@@ -17,9 +17,34 @@ cli.help((sections) => {
1717// Simplify the version output compared to the default
1818cli . globalCommand . outputVersion = ( ) => console . info ( manifest . version ) ;
1919
20+ function normalizeOptions (
21+ options : Record < string , any > ,
22+ { array } : { array ?: string [ ] } = { } ,
23+ ) {
24+ // Do not allow positional arguments in options
25+ options [ "--" ] = undefined ;
26+
27+ for ( const key in options ) {
28+ if ( options [ key ] == null ) continue ;
29+
30+ // If the flag is expected to be an array, ensure it's an array.
31+ if ( array ?. includes ( key ) ) {
32+ const v = options [ key ] ;
33+ options [ key ] = Array . isArray ( v ) ? v : [ v ] ;
34+ continue ;
35+ }
36+
37+ // If a flag is passed multiple times (becoming an array), only take the last value.
38+ if ( Array . isArray ( options [ key ] ) ) {
39+ options [ key ] = options [ key ] . at ( - 1 ) ;
40+ }
41+ }
42+ }
43+
2044cli
2145 . command ( "init" , "Initialize a new changesets setup" )
2246 . action ( async ( options ) => {
47+ normalizeOptions ( options ) ;
2348 const { init } = await import ( "./commands/init/index.ts" ) ;
2449 await init ( options ) ;
2550 } ) ;
3863 )
3964 . option ( "-m, --message <text>" , "Directly provide a message to the changeset" )
4065 . action ( async ( options ) => {
66+ normalizeOptions ( options ) ;
4167 const { add } = await import ( "./commands/add/index.ts" ) ;
4268 await add ( options ) ;
4369 } ) ;
5379 "Template for snapshot prerelease" ,
5480 )
5581 . action ( async ( options ) => {
56- if ( options . ignore ) {
57- options . ignore = Array . isArray ( options . ignore )
58- ? options . ignore
59- : [ options . ignore ] ;
60- }
61-
82+ normalizeOptions ( options , { array : [ "ignore" ] } ) ;
6283 const { version } = await import ( "./commands/version/index.ts" ) ;
6384 await version ( options ) ;
6485 } ) ;
7192 . option ( "--tag <name>" , "Publish with the given npm dist-tag" )
7293 . option ( "--git-tag" , "Create a git tag for the release" )
7394 . action ( async ( options ) => {
95+ normalizeOptions ( options ) ;
7496 const { publish } = await import ( "./commands/publish/index.ts" ) ;
7597 await publish ( options ) ;
7698 } ) ;
82104 . option ( "-v, --verbose" , "Show more information about the changesets" )
83105 . option ( "-o, --output <file>" , "Output the status as JSON to a file" )
84106 . action ( async ( options ) => {
107+ normalizeOptions ( options ) ;
85108 const { status } = await import ( "./commands/status/index.ts" ) ;
86109 await status ( options ) ;
87110 } ) ;
88111
89112cli
90113 . command ( "tag" , "Create git tags for the current version of all packages" )
91114 . action ( async ( options ) => {
115+ normalizeOptions ( options ) ;
92116 const { tag } = await import ( "./commands/tag/index.ts" ) ;
93117 await tag ( options ) ;
94118 } ) ;
95119
96120cli
97121 . command ( "pre enter <tag>" , "Enter prerelease mode with the given tag" )
98122 . action ( async ( tag : string , options ) => {
123+ normalizeOptions ( options ) ;
99124 const { pre } = await import ( "./commands/pre/index.ts" ) ;
100125 await pre ( { ...options , command : "enter" , tag } ) ;
101126 } ) ;
102127
103128cli . command ( "pre exit" , "Exit prerelease mode" ) . action ( async ( options ) => {
129+ normalizeOptions ( options ) ;
104130 const { pre } = await import ( "./commands/pre/index.ts" ) ;
105131 await pre ( { ...options , command : "exit" } ) ;
106132} ) ;
0 commit comments