File tree Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -220,9 +220,14 @@ def subcommands
220
220
end
221
221
alias_method :subtasks , :subcommands
222
222
223
+ def subcommand_classes
224
+ @subcommand_classes ||= { }
225
+ end
226
+
223
227
def subcommand ( subcommand , subcommand_class )
224
228
subcommands << subcommand . to_s
225
229
subcommand_class . subcommand_help subcommand
230
+ subcommand_classes [ subcommand . to_s ] = subcommand_class
226
231
227
232
define_method ( subcommand ) do |*args |
228
233
args , opts = Thor ::Arguments . split ( args )
@@ -466,6 +471,14 @@ def help(command = nil, subcommand = true); super; end
466
471
467
472
desc 'help [COMMAND]' , 'Describe available commands or one specific command'
468
473
def help ( command = nil , subcommand = false )
469
- command ? self . class . command_help ( shell , command ) : self . class . help ( shell , subcommand )
474
+ if command
475
+ if self . class . subcommands . include? command
476
+ self . class . subcommand_classes [ command ] . help ( shell , true )
477
+ else
478
+ self . class . command_help ( shell , command )
479
+ end
480
+ else
481
+ self . class . help ( shell , subcommand )
482
+ end
470
483
end
471
484
end
Original file line number Diff line number Diff line change 38
38
expect ( output ) . to eq ( sub_help )
39
39
end
40
40
41
+ it "the help command on the subcommand and after it should result in the same output" do
42
+ output = capture ( :stdout ) { TestSubcommands ::Parent . start ( %w[ sub help ] ) }
43
+ sub_help = capture ( :stdout ) { TestSubcommands ::Parent . start ( %w[ help sub ] ) }
44
+ expect ( output ) . to eq ( sub_help )
45
+ end
41
46
end
42
47
43
48
end
You can’t perform that action at this time.
0 commit comments