@@ -4,15 +4,15 @@ import Command, {
44 GlobalCommand ,
55 CommandConfig ,
66 HelpCallback ,
7- CommandExample
7+ CommandExample ,
88} from './Command'
99import { OptionConfig } from './Option'
1010import {
1111 getMriOptions ,
1212 setDotProp ,
1313 setByType ,
1414 getFileName ,
15- camelcaseOptionName
15+ camelcaseOptionName ,
1616} from './utils'
1717import { processArgs } from './node'
1818
@@ -43,8 +43,8 @@ class CAC extends EventEmitter {
4343 */
4444 options : ParsedArgv [ 'options' ]
4545
46- showHelpOnExit : boolean
47- showVersionOnExit : boolean
46+ showHelpOnExit ? : boolean
47+ showVersionOnExit ? : boolean
4848
4949 /**
5050 * @param name The program name to display in help and version message
@@ -53,6 +53,9 @@ class CAC extends EventEmitter {
5353 super ( )
5454 this . name = name
5555 this . commands = [ ]
56+ this . rawArgs = [ ]
57+ this . args = [ ]
58+ this . options = { }
5659 this . globalCommand = new GlobalCommand ( this )
5760 this . globalCommand . usage ( '<command> [options]' )
5861 }
@@ -155,7 +158,7 @@ class CAC extends EventEmitter {
155158 }
156159 return this
157160 }
158-
161+
159162 unsetMatchedCommand ( ) {
160163 this . matchedCommand = undefined
161164 this . matchedCommandName = undefined
@@ -168,7 +171,7 @@ class CAC extends EventEmitter {
168171 argv = processArgs ,
169172 {
170173 /** Whether to run the action for matched command */
171- run = true
174+ run = true ,
172175 } = { }
173176 ) : ParsedArgv {
174177 this . rawArgs = argv
@@ -187,7 +190,7 @@ class CAC extends EventEmitter {
187190 shouldParse = false
188191 const parsedInfo = {
189192 ...parsed ,
190- args : parsed . args . slice ( 1 )
193+ args : parsed . args . slice ( 1 ) ,
191194 }
192195 this . setParsedInfo ( parsedInfo , command , commandName )
193196 this . emit ( `command:${ commandName } ` , command )
@@ -243,7 +246,7 @@ class CAC extends EventEmitter {
243246 // All added options
244247 const cliOptions = [
245248 ...this . globalCommand . options ,
246- ...( command ? command . options : [ ] )
249+ ...( command ? command . options : [ ] ) ,
247250 ]
248251 const mriOptions = getMriOptions ( cliOptions )
249252
@@ -260,17 +263,16 @@ class CAC extends EventEmitter {
260263 ( res , name ) => {
261264 return {
262265 ...res ,
263- [ camelcaseOptionName ( name ) ] : parsed [ name ]
266+ [ camelcaseOptionName ( name ) ] : parsed [ name ] ,
264267 }
265268 } ,
266269 { _ : [ ] }
267270 )
268271
269272 const args = parsed . _
270- delete parsed . _
271273
272274 const options : { [ k : string ] : any } = {
273- '--' : argsAfterDoubleDashes
275+ '--' : argsAfterDoubleDashes ,
274276 }
275277
276278 // Set option default value
@@ -300,16 +302,18 @@ class CAC extends EventEmitter {
300302 }
301303 }
302304
303- // Set dot nested option values
305+ // Set option values (support dot- nested property name)
304306 for ( const key of Object . keys ( parsed ) ) {
305- const keys = key . split ( '.' )
306- setDotProp ( options , keys , parsed [ key ] )
307- setByType ( options , transforms )
307+ if ( key !== '_' ) {
308+ const keys = key . split ( '.' )
309+ setDotProp ( options , keys , parsed [ key ] )
310+ setByType ( options , transforms )
311+ }
308312 }
309313
310314 return {
311315 args,
312- options
316+ options,
313317 }
314318 }
315319
0 commit comments