@@ -186,24 +186,17 @@ module.exports = function command (yargs, usage, validation, globalMiddleware) {
186186 // a function can be provided, which builds
187187 // up a yargs chain and possibly returns it.
188188 innerYargs = commandHandler . builder ( yargs . reset ( parsed . aliases ) )
189- // if the builder function did not yet parse argv with reset yargs
190- // and did not explicitly set a usage() string, then apply the
191- // original command string as usage() for consistent behavior with
192- // options object below.
193- if ( yargs . parsed === false ) {
194- if ( shouldUpdateUsage ( yargs ) ) {
195- yargs . getUsageInstance ( ) . usage (
196- usageFromParentCommandsCommandHandler ( parentCommands , commandHandler ) ,
197- commandHandler . description
198- )
199- }
200- innerArgv = innerYargs ? innerYargs . _parseArgs ( null , null , true , commandIndex ) : yargs . _parseArgs ( null , null , true , commandIndex )
201- } else {
202- innerArgv = yargs . parsed . argv
189+ if ( ! innerYargs || ( typeof innerYargs . _parseArgs !== 'function' ) ) {
190+ innerYargs = yargs
203191 }
204-
205- if ( innerYargs && yargs . parsed === false ) aliases = innerYargs . parsed . aliases
206- else aliases = yargs . parsed . aliases
192+ if ( shouldUpdateUsage ( innerYargs ) ) {
193+ innerYargs . getUsageInstance ( ) . usage (
194+ usageFromParentCommandsCommandHandler ( parentCommands , commandHandler ) ,
195+ commandHandler . description
196+ )
197+ }
198+ innerArgv = innerYargs . _parseArgs ( null , null , true , commandIndex )
199+ aliases = innerYargs . parsed . aliases
207200 } else if ( typeof commandHandler . builder === 'object' ) {
208201 // as a short hand, an object can instead be provided, specifying
209202 // the options that a command takes.
@@ -419,18 +412,19 @@ module.exports = function command (yargs, usage, validation, globalMiddleware) {
419412 // the state of commands such that
420413 // we can apply .parse() multiple times
421414 // with the same yargs instance.
422- let frozen
415+ let frozens = [ ]
423416 self . freeze = ( ) => {
424- frozen = { }
417+ let frozen = { }
418+ frozens . push ( frozen )
425419 frozen . handlers = handlers
426420 frozen . aliasMap = aliasMap
427421 frozen . defaultCommand = defaultCommand
428422 }
429423 self . unfreeze = ( ) => {
424+ let frozen = frozens . pop ( )
430425 handlers = frozen . handlers
431426 aliasMap = frozen . aliasMap
432427 defaultCommand = frozen . defaultCommand
433- frozen = undefined
434428 }
435429
436430 return self
0 commit comments