Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

alias --help to help on subcommands #383

Merged
merged 3 commits into from

4 participants

@developingchris

When the --help option is present it will change the args array to
include the help command.

This fixes issue #376 for the 1.0 milestone

@developingchris developingchris alias --help to help on subcommands
When the --help option is present it will change the args array to
include the help command.
b23e2cf
@coveralls

Coverage Status

Coverage decreased (-0.08%) when pulling b23e2cf on developingchris:alias_help_option_to_help into aaeccb6 on erikhuda:master.

lib/thor.rb
@@ -353,6 +354,7 @@ def dispatch(meth, given_args, given_opts, config) #:nodoc:
command = Thor::DynamicCommand.new(meth)
end
+
@sferik Owner
sferik added a note

Please remove this stray whitespace.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@sferik
Owner

Does this also work for the -h short alias? If so, there should be a test for it. If not, it should. :wink:

developingchris added some commits
@developingchris developingchris 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.
7959d9a
@developingchris developingchris remove stray whitespace 1e8dab9
@developingchris

test and implementation added for the short alias of help.

@sferik sferik merged commit 0631d7d into erikhuda:master
@schneems

:heart: awesome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 7, 2013
  1. @developingchris

    alias --help to help on subcommands

    developingchris authored
    When the --help option is present it will change the args array to
    include the help command.
Commits on Dec 14, 2013
  1. @developingchris

    revising branch to also inlude the short option

    developingchris authored
    Now the -h and --help enact the same functionality as if help was called
    on the subcommand.
  2. @developingchris
This page is out of date. Refresh to see the latest.
Showing with 14 additions and 0 deletions.
  1. +1 −0  lib/thor.rb
  2. +13 −0 spec/subcommand_spec.rb
View
1  lib/thor.rb
@@ -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
13 spec/subcommand_spec.rb
@@ -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
Something went wrong with that request. Please try again.