Skip to content

Commit

Permalink
fix(cli): parse multiple config args to last item of array (#164)
Browse files Browse the repository at this point in the history
Closes #146
  • Loading branch information
MishaSeredenkoPushBased authored Oct 27, 2023
1 parent 9a5371c commit 7c81f81
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
16 changes: 16 additions & 0 deletions packages/cli/src/lib/yargs-cli.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,22 @@ describe('yargsCli', () => {
expect(parsedArgv.verbose).toBe(false);
});

it('multiple config args should be parsed to last item from array', async () => {
const args: string[] = ['--config=./config.a.ts', '--config=./config.b.ts'];
const parsedArgv = await yargsCli(args, {
options,
}).parseAsync();
expect(parsedArgv.config).toBe('./config.b.ts');
});

it('single config arg should be parsed as a single string', async () => {
const args: string[] = ['--config=./config.a.ts'];
const parsedArgv = await yargsCli(args, {
options,
}).parseAsync();
expect(parsedArgv.config).toBe('./config.a.ts');
});

it('global options should parse correctly', async () => {
const args: string[] = objectToCliArgs({
verbose: true,
Expand Down
6 changes: 6 additions & 0 deletions packages/cli/src/lib/yargs-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ export function yargsCli(
'strip-dashed': true,
} satisfies Partial<ParserConfigurationOptions>)
.array('persist.format')
.coerce('config', (config: string | string[]) => {
if (Array.isArray(config)) {
return config[config.length - 1];
}
return config;
})
.options(options);
//.demandCommand(...demandCommand);

Expand Down

0 comments on commit 7c81f81

Please sign in to comment.