Skip to content

Commit 7c81f81

Browse files
fix(cli): parse multiple config args to last item of array (#164)
Closes #146
1 parent 9a5371c commit 7c81f81

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

packages/cli/src/lib/yargs-cli.spec.ts

+16
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,22 @@ describe('yargsCli', () => {
2020
expect(parsedArgv.verbose).toBe(false);
2121
});
2222

23+
it('multiple config args should be parsed to last item from array', async () => {
24+
const args: string[] = ['--config=./config.a.ts', '--config=./config.b.ts'];
25+
const parsedArgv = await yargsCli(args, {
26+
options,
27+
}).parseAsync();
28+
expect(parsedArgv.config).toBe('./config.b.ts');
29+
});
30+
31+
it('single config arg should be parsed as a single string', async () => {
32+
const args: string[] = ['--config=./config.a.ts'];
33+
const parsedArgv = await yargsCli(args, {
34+
options,
35+
}).parseAsync();
36+
expect(parsedArgv.config).toBe('./config.a.ts');
37+
});
38+
2339
it('global options should parse correctly', async () => {
2440
const args: string[] = objectToCliArgs({
2541
verbose: true,

packages/cli/src/lib/yargs-cli.ts

+6
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ export function yargsCli(
4949
'strip-dashed': true,
5050
} satisfies Partial<ParserConfigurationOptions>)
5151
.array('persist.format')
52+
.coerce('config', (config: string | string[]) => {
53+
if (Array.isArray(config)) {
54+
return config[config.length - 1];
55+
}
56+
return config;
57+
})
5258
.options(options);
5359
//.demandCommand(...demandCommand);
5460

0 commit comments

Comments
 (0)