File tree 2 files changed +22
-0
lines changed
2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,22 @@ describe('yargsCli', () => {
20
20
expect ( parsedArgv . verbose ) . toBe ( false ) ;
21
21
} ) ;
22
22
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
+
23
39
it ( 'global options should parse correctly' , async ( ) => {
24
40
const args : string [ ] = objectToCliArgs ( {
25
41
verbose : true ,
Original file line number Diff line number Diff line change @@ -49,6 +49,12 @@ export function yargsCli(
49
49
'strip-dashed' : true ,
50
50
} satisfies Partial < ParserConfigurationOptions > )
51
51
. 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
+ } )
52
58
. options ( options ) ;
53
59
//.demandCommand(...demandCommand);
54
60
You can’t perform that action at this time.
0 commit comments