Skip to content

Commit 7959d9a

Browse files
revising branch to also inlude the short option
Now the -h and --help enact the same functionality as if help was called on the subcommand.
1 parent b23e2cf commit 7959d9a

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

lib/thor.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ def subcommand(subcommand, subcommand_class)
229229

230230
define_method(subcommand) do |*args|
231231
args, opts = Thor::Arguments.split(args)
232-
args.unshift("help") if opts.include? "--help"
232+
args.unshift("help") if opts.include? "--help" or opts.include? "-h"
233233
invoke subcommand_class, args, opts, :invoked_via_subcommand => true, :class_options => options
234234
end
235235
end

spec/subcommand_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@
3232
expect(output).to eq(sub_help)
3333
end
3434

35+
it "accepts the help short switch and calls the help command on the subcommand" do
36+
output = capture(:stdout) { TestSubcommands::Parent.start(%w[sub print_opt -h])}
37+
sub_help = capture(:stdout) { TestSubcommands::Parent.start(%w[sub help print_opt])}
38+
expect(output).to eq(sub_help)
39+
end
40+
3541
end
3642

3743
end

0 commit comments

Comments
 (0)