@@ -123,4 +123,41 @@ describe('help command processed on correct command', () => {
123
123
program . parse ( 'node test.js help' . split ( ' ' ) ) ;
124
124
} ) . toThrow ( 'program' ) ;
125
125
} ) ;
126
+
127
+ test ( 'when no long help flag then "help sub" works' , ( ) => {
128
+ const program = new commander . Command ( ) ;
129
+ program . exitOverride ( ) ;
130
+ program . helpOption ( '-H' ) ;
131
+ const sub = program . command ( 'sub' ) ;
132
+ // Patch help for easy way to check called.
133
+ sub . help = ( ) => { throw new Error ( 'sub help' ) ; } ;
134
+ expect ( ( ) => {
135
+ program . parse ( [ 'help' , 'sub' ] , { from : 'user' } ) ;
136
+ } ) . toThrow ( 'sub help' ) ;
137
+ } ) ;
138
+
139
+ test ( 'when no help options in sub then "help sub" works' , ( ) => {
140
+ const program = new commander . Command ( ) ;
141
+ program . exitOverride ( ) ;
142
+ const sub = program . command ( 'sub' )
143
+ . helpOption ( false ) ;
144
+ // Patch help for easy way to check called.
145
+ sub . help = ( ) => { throw new Error ( 'sub help' ) ; } ;
146
+ expect ( ( ) => {
147
+ program . parse ( [ 'help' , 'sub' ] , { from : 'user' } ) ;
148
+ } ) . toThrow ( 'sub help' ) ;
149
+ } ) ;
150
+
151
+ test ( 'when different help options in sub then "help sub" works' , ( ) => {
152
+ const program = new commander . Command ( ) ;
153
+ program . exitOverride ( ) ;
154
+ const sub = program . command ( 'sub' ) ;
155
+ program . helpOption ( '-h, --help' ) ;
156
+ sub . helpOption ( '-a, --assist' ) ;
157
+ // Patch help for easy way to check called.
158
+ sub . help = ( ) => { throw new Error ( 'sub help' ) ; } ;
159
+ expect ( ( ) => {
160
+ program . parse ( [ 'help' , 'sub' ] , { from : 'user' } ) ;
161
+ } ) . toThrow ( 'sub help' ) ;
162
+ } ) ;
126
163
} ) ;
0 commit comments