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

Possible fix for the subcommand help messages using the klass name instead of command name #330

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/thor.rb
Expand Up @@ -454,7 +454,11 @@ def find_command_possibilities(meth)

def subcommand_help(cmd)
desc "help [COMMAND]", "Describe subcommands or one specific subcommand"
class_eval <<-RUBY
class_eval <<-RUBY
@subcommand_name = "#{cmd.to_s}"
def self.subcommand_name()
@subcommand_name
end
def help(command = nil, subcommand = true); super; end
RUBY
end
Expand Down
3 changes: 2 additions & 1 deletion lib/thor/command.rb
Expand Up @@ -45,7 +45,8 @@ def formatted_usage(klass, namespace = true, subcommand = false)
namespace = klass.namespace
formatted = "#{namespace.gsub(/^(default)/,'')}:"
end
formatted = "#{klass.namespace.split(':').last} " if subcommand

formatted = (klass.respond_to? :subcommand_name) ? "#{klass.subcommand_name} " : "#{klass.namespace.split(':').last} " if subcommand

formatted ||= ""

Expand Down
2 changes: 1 addition & 1 deletion spec/base_spec.rb
Expand Up @@ -192,7 +192,7 @@ def hello
it "returns tracked subclasses, grouped by the files they come from" do
thorfile = File.join(File.dirname(__FILE__), "fixtures", "script.thor")
expect(Thor::Base.subclass_files[File.expand_path(thorfile)]).to eq([
MyScript, MyScript::AnotherScript, MyChildScript, Barn,
MyScript, MyScript::AnotherScript, MyChildScript, BarnCli,
PackageNameScript, Scripts::MyScript, Scripts::MyDefaults,
Scripts::ChildDefault, Scripts::Arities
])
Expand Down
4 changes: 2 additions & 2 deletions spec/fixtures/script.thor
Expand Up @@ -145,7 +145,7 @@ class MyChildScript < MyScript
remove_command :boom, :undefine => true
end

class Barn < Thor
class BarnCli < Thor
desc "open [ITEM]", "open the barn door"
def open(item = nil)
if item == "shotgun"
Expand Down Expand Up @@ -192,7 +192,7 @@ module Scripts
end

desc "barn", "commands to manage the barn"
subcommand "barn", Barn
subcommand "barn", BarnCli
end

class ChildDefault < Thor
Expand Down
2 changes: 1 addition & 1 deletion spec/register_spec.rb
Expand Up @@ -157,7 +157,7 @@ def say
begin
$thor_runner = false
help_output = capture(:stdout) { BoringVendorProvidedCLI.start(%w[exciting]) }
expect(help_output).to include('thor exciting_plugin_c_l_i fireworks')
expect(help_output).to include('thor exciting fireworks')
ensure
$thor_runner = true
end
Expand Down
2 changes: 1 addition & 1 deletion spec/subcommand_spec.rb
Expand Up @@ -6,7 +6,7 @@

it "maps a given subcommand to another Thor subclass" do
barn_help = capture(:stdout) { Scripts::MyDefaults.start(%w[barn]) }
expect(barn_help).to include("barn help [COMMAND] # Describe subcommands or one specific subcommand")
expect(barn_help).to include("thor barn help [COMMAND] # Describe subcommands or one specific subcommand")
end

it "passes commands to subcommand classes" do
Expand Down