feat: add color option to CLI and configuration file

The option is used to force enable/disable color output and is passed to the reporter which should respect it
This commit is contained in:
Joakim Carlstein 2023-12-20 09:06:13 +01:00 committed by Joakim Carlstein
parent 7bae76f496
commit f9a16d87a1
14 changed files with 112 additions and 11 deletions

View file

@ -10,7 +10,12 @@ import { version } from '../get-package-info.js';
const lazyDefaultReporter = async () => import('../reporters/default.js');
export default async function listCommand({ directory, reporter: reporterConfig, storage: storageConfig }: Config) {
export default async function listCommand({
directory,
reporter: reporterConfig,
storage: storageConfig,
color,
}: Config) {
if (!directory) {
throw MissingOptionError.fromOption('directory');
}
@ -31,7 +36,7 @@ export default async function listCommand({ directory, reporter: reporterConfig,
);
}
await reporter.onInit?.({ command: 'list', version, cwd, dry: false, directory });
await reporter.onInit?.({ command: 'list', version, cwd, dry: false, directory, color });
const [storage, storageError] = await exec(async () => storagePlugin.initializeStorage());

View file

@ -19,7 +19,7 @@ import { getDuration } from '../get-duration.js';
const lazyDefaultReporter = async () => import('../reporters/default.js');
export default async function newCommand(
{ directory, template, reporter: reporterConfig, plugins = [], extension }: Config,
{ directory, template, reporter: reporterConfig, plugins = [], extension, color }: Config,
name: string,
) {
if (!directory) {
@ -45,7 +45,7 @@ export default async function newCommand(
);
}
await reporter.onInit?.({ command: 'new', version, cwd, dry: false, directory });
await reporter.onInit?.({ command: 'new', version, cwd, dry: false, directory, color });
const start = process.hrtime();

View file

@ -22,7 +22,7 @@ type ExtraFlags = {
const lazyDefaultReporter = async () => import('../reporters/default.js');
export default async function removeCommand(
{ directory, reporter: reporterConfig, storage: storageConfig, force }: Config & ExtraFlags,
{ directory, reporter: reporterConfig, storage: storageConfig, color, force = false }: Config & ExtraFlags,
name: string,
) {
if (!directory) {
@ -57,7 +57,7 @@ export default async function removeCommand(
return 1;
}
await reporter.onInit?.({ command: 'remove', version, cwd, dry: false, directory });
await reporter.onInit?.({ command: 'remove', version, cwd, dry: false, directory, color });
const [migrationFile, fileError] = await exec(async () => getMigration(cwd, directory, name, !force));

View file

@ -33,6 +33,7 @@ describe('up', () => {
command: 'up',
cwd: '/emigrate',
dry: false,
color: undefined,
version,
directory: 'migrations',
},
@ -111,6 +112,7 @@ describe('up', () => {
cwd: '/emigrate',
version,
dry: false,
color: undefined,
directory: 'migrations',
},
]);
@ -152,6 +154,7 @@ describe('up', () => {
cwd: '/emigrate',
version,
dry: true,
color: undefined,
directory: 'migrations',
},
]);
@ -193,6 +196,7 @@ describe('up', () => {
cwd: '/emigrate',
version,
dry: false,
color: undefined,
directory: 'migrations',
},
]);
@ -219,6 +223,7 @@ describe('up', () => {
cwd: '/emigrate',
version,
dry: false,
color: undefined,
directory: 'migrations',
},
]);
@ -265,6 +270,7 @@ describe('up', () => {
cwd: '/emigrate',
version,
dry: false,
color: undefined,
directory: 'migrations',
},
]);
@ -312,6 +318,7 @@ describe('up', () => {
cwd: '/emigrate',
version,
dry: false,
color: undefined,
directory: 'migrations',
},
]);

View file

@ -25,6 +25,7 @@ export default async function upCommand({
storage: storageConfig,
reporter: reporterConfig,
directory,
color,
dry = false,
plugins = [],
cwd = process.cwd(),
@ -49,7 +50,7 @@ export default async function upCommand({
);
}
await reporter.onInit?.({ command: 'up', version, cwd, dry, directory });
await reporter.onInit?.({ command: 'up', version, cwd, dry, directory, color });
const [storage, storageError] = await exec(async () => storagePlugin.initializeStorage());