Skip to content

Commit 252a7c2

Browse files
Shows root command help considering if it implements #call
1 parent 1cef94f commit 252a7c2

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

lib/dry/cli/banner.rb

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,19 @@ def self.command_name(name)
3737
# @since 0.1.0
3838
# @api private
3939
def self.command_name_and_arguments(command, name)
40-
usage = "\nUsage:\n #{name}#{arguments(command)}"
40+
usage = "\nUsage:\n"
4141

42-
return usage + " | #{name} SUBCOMMAND" if command.subcommands.any?
42+
callable_root_command = false
43+
if command.new.respond_to?(:call)
44+
callable_root_command = true
45+
usage += " #{name}#{arguments(command)}"
46+
end
47+
48+
if command.subcommands.any?
49+
usage += " "
50+
usage += "|" if callable_root_command
51+
usage += " #{name} SUBCOMMAND"
52+
end
4353

4454
usage
4555
end

spec/support/shared_examples/inherited_commands.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,27 @@
2727
expect(error).to eq(expected)
2828
end
2929

30+
it "shows root command help considering if it implements #call" do
31+
output = capture_output { cli.call(arguments: %w[namespace --help]) }
32+
expected = <<~DESC
33+
Command:
34+
#{cmd} namespace
35+
36+
Usage:
37+
#{cmd} namespace SUBCOMMAND
38+
39+
Description:
40+
This is a namespace
41+
42+
Subcommands:
43+
sub-command # I'm a concrete command
44+
45+
Options:
46+
--help, -h # Print this help
47+
DESC
48+
expect(output).to eq(expected)
49+
end
50+
3051
it "shows run's help" do
3152
output = capture_output { cli.call(arguments: %w[i run --help]) }
3253
expected = <<~DESC

0 commit comments

Comments
 (0)