Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Make subcommand help more consistent #387

Merged
merged 1 commit into from

3 participants

@developingchris

When a command is being asked for help upon and is in the subcommands
list the subcommand's class is invoked for help instead.

A hash of the subcommand classes was added to facilitate this.

Fixes issue #375

@developingchris developingchris Make subcommand help more consistent
When a command is being asked for help upon and is in the subcommands
list the subcommand's class is invoked for help instead.

A hash of the subcommand classes was added to facilitate this.
e917677
@coveralls

Coverage Status

Coverage increased (+0.02%) when pulling e917677 on developingchris:unify_help into 3dd0e8f on erikhuda:master.

@sferik sferik merged commit 54a0e17 into erikhuda:master
@sferik
Owner

Thanks!

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

    Make subcommand help more consistent

    developingchris authored
    When a command is being asked for help upon and is in the subcommands
    list the subcommand's class is invoked for help instead.
    
    A hash of the subcommand classes was added to facilitate this.
This page is out of date. Refresh to see the latest.
Showing with 19 additions and 1 deletion.
  1. +14 −1 lib/thor.rb
  2. +5 −0 spec/subcommand_spec.rb
View
15 lib/thor.rb
@@ -223,9 +223,14 @@ def subcommands
end
alias_method :subtasks, :subcommands
+ def subcommand_classes
+ @subcommand_classes ||= {}
+ end
+
def subcommand(subcommand, subcommand_class)
subcommands << subcommand.to_s
subcommand_class.subcommand_help subcommand
+ subcommand_classes[subcommand.to_s] = subcommand_class
define_method(subcommand) do |*args|
args, opts = Thor::Arguments.split(args)
@@ -472,6 +477,14 @@ def help(command = nil, subcommand = true); super; end
desc 'help [COMMAND]', 'Describe available commands or one specific command'
def help(command = nil, subcommand = false)
- command ? self.class.command_help(shell, command) : self.class.help(shell, subcommand)
+ if command
+ if self.class.subcommands.include? command
+ self.class.subcommand_classes[command].help(shell, true)
+ else
+ self.class.command_help(shell, command)
+ end
+ else
+ self.class.help(shell, subcommand)
+ end
end
end
View
5 spec/subcommand_spec.rb
@@ -38,6 +38,11 @@
expect(output).to eq(sub_help)
end
+ it "the help command on the subcommand and after it should result in the same output" do
+ output = capture(:stdout) { TestSubcommands::Parent.start(%w[sub help])}
+ sub_help = capture(:stdout) { TestSubcommands::Parent.start(%w[help sub])}
+ expect(output).to eq(sub_help)
+ end
end
end
Something went wrong with that request. Please try again.