Permalink
Browse files

Merge pull request #383 from developingchris/alias_help_option_to_help

alias --help to help on subcommands
  • Loading branch information...
2 parents 3e6197f + 1e8dab9 commit 0631d7d4c7f1731ea6e30f2a16e74ccf73870bf4 @sferik sferik committed Dec 14, 2013
Showing with 14 additions and 0 deletions.
  1. +1 −0 lib/thor.rb
  2. +13 −0 spec/subcommand_spec.rb
View
@@ -229,6 +229,7 @@ def subcommand(subcommand, subcommand_class)
define_method(subcommand) do |*args|
args, opts = Thor::Arguments.split(args)
+ args.unshift("help") if opts.include? "--help" or opts.include? "-h"
invoke subcommand_class, args, opts, :invoked_via_subcommand => true, :class_options => options
end
end
View
@@ -25,6 +25,19 @@
output = capture(:stdout) { TestSubcommands::Parent.start(%w[sub print_opt --opt output]) }
expect(output).to eq('output')
end
+
+ it "accepts the help switch and calls the help command on the subcommand" do
+ output = capture(:stdout) { TestSubcommands::Parent.start(%w[sub print_opt --help])}
+ sub_help = capture(:stdout) { TestSubcommands::Parent.start(%w[sub help print_opt])}
+ expect(output).to eq(sub_help)
+ end
+
+ it "accepts the help short switch and calls the help command on the subcommand" do
+ output = capture(:stdout) { TestSubcommands::Parent.start(%w[sub print_opt -h])}
+ sub_help = capture(:stdout) { TestSubcommands::Parent.start(%w[sub help print_opt])}
+ expect(output).to eq(sub_help)
+ end
+
end
end

0 comments on commit 0631d7d

Please sign in to comment.