File tree Expand file tree Collapse file tree 2 files changed +53
-0
lines changed Expand file tree Collapse file tree 2 files changed +53
-0
lines changed Original file line number Diff line number Diff line change @@ -263,6 +263,7 @@ export class CommandInstance {
263
263
if ( isCommandBuilderCallback ( builder ) ) {
264
264
// A function can be provided, which builds
265
265
// up a yargs chain and possibly returns it.
266
+ yargs . getInternalMethods ( ) . getUsageInstance ( ) . freeze ( ) ;
266
267
const builderOutput = builder (
267
268
yargs . getInternalMethods ( ) . reset ( aliases ) ,
268
269
helpOrVersionSet
@@ -284,6 +285,7 @@ export class CommandInstance {
284
285
} else if ( isCommandBuilderOptionDefinitions ( builder ) ) {
285
286
// as a short hand, an object can instead be provided, specifying
286
287
// the options that a command takes.
288
+ yargs . getInternalMethods ( ) . getUsageInstance ( ) . freeze ( ) ;
287
289
innerYargs = yargs . getInternalMethods ( ) . reset ( aliases ) ;
288
290
Object . keys ( commandHandler . builder ) . forEach ( key => {
289
291
innerYargs . option ( key , builder [ key ] ) ;
Original file line number Diff line number Diff line change @@ -3991,6 +3991,57 @@ describe('usage tests', () => {
3991
3991
' --arg2 arg2 desc [string]' ,
3992
3992
] ) ;
3993
3993
} ) ;
3994
+
3995
+ // See: https://github.com/yargs/yargs/issues/2291
3996
+ it ( 'should display help output for nested default command on failure' , ( ) => {
3997
+ const r = checkUsage ( ( ) =>
3998
+ yargs ( )
3999
+ . command (
4000
+ 'root' ,
4001
+ 'root command' ,
4002
+ y => {
4003
+ y . command ( {
4004
+ command : 'nested' ,
4005
+ desc : 'nested command' ,
4006
+ builder : y => {
4007
+ y . command ( {
4008
+ command : 'deep-a' ,
4009
+ aliases : [ '$0' ] ,
4010
+ desc : 'deeply nested default' ,
4011
+ builder : noop ,
4012
+ handler : noop ,
4013
+ } ) . command ( {
4014
+ command : 'deep-b' ,
4015
+ desc : 'a deeply nested command' ,
4016
+ builder : noop ,
4017
+ handler : noop ,
4018
+ } ) ;
4019
+ } ,
4020
+ handler : noop ,
4021
+ } ) ;
4022
+ } ,
4023
+ ( ) => { }
4024
+ )
4025
+ . strict ( )
4026
+ . demandCommand ( )
4027
+ . parse ( [ 'root' , 'nested' , 'bloop' ] )
4028
+ ) ;
4029
+ r . errors [ 0 ]
4030
+ . split ( '\n' )
4031
+ . should . deep . equal ( [
4032
+ 'usage root nested' ,
4033
+ '' ,
4034
+ 'nested command' ,
4035
+ '' ,
4036
+ 'Commands:' ,
4037
+ ' usage root nested deep-a deeply nested default [default]' ,
4038
+ ' usage root nested deep-b a deeply nested command' ,
4039
+ '' ,
4040
+ 'Options:' ,
4041
+ ' --help Show help [boolean]' ,
4042
+ ' --version Show version number [boolean]' ,
4043
+ ] ) ;
4044
+ } ) ;
3994
4045
} ) ;
3995
4046
3996
4047
describe ( 'positional' , ( ) => {
You can’t perform that action at this time.
0 commit comments