Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

alias --help to help on subcommands #383

Merged
merged 3 commits into from
Dec 14, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/thor.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ def subcommand(subcommand, subcommand_class)


define_method(subcommand) do |*args| define_method(subcommand) do |*args|
args, opts = Thor::Arguments.split(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 invoke subcommand_class, args, opts, :invoked_via_subcommand => true, :class_options => options
end end
end end
Expand Down
13 changes: 13 additions & 0 deletions spec/subcommand_spec.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -25,6 +25,19 @@
output = capture(:stdout) { TestSubcommands::Parent.start(%w[sub print_opt --opt output]) } output = capture(:stdout) { TestSubcommands::Parent.start(%w[sub print_opt --opt output]) }
expect(output).to eq("output") expect(output).to eq("output")
end 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


end end