Skip to content

Commit 1cef94f

Browse files
Shows subcommands when root command doesn't implement #call
1 parent 8b8567f commit 1cef94f

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

lib/dry/cli.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ def perform_registry(arguments)
111111
return usage(result) unless result.found?
112112

113113
command, args = parse(result.command, result.arguments, result.names)
114+
return usage(result) unless command.respond_to?(:call)
114115

115116
result.before_callbacks.run(command, args)
116117
command.call(**args)

spec/support/shared_examples/inherited_commands.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@
1818
expect(error).to eq(expected)
1919
end
2020

21+
it "shows subcommands when root command doesn't implement #call" do
22+
error = capture_error { cli.call(arguments: %w[namespace]) }
23+
expected = <<~DESC
24+
Commands:
25+
#{cmd} namespace sub-command # I'm a concrete command
26+
DESC
27+
expect(error).to eq(expected)
28+
end
29+
2130
it "shows run's help" do
2231
output = capture_output { cli.call(arguments: %w[i run --help]) }
2332
expected = <<~DESC

0 commit comments

Comments
 (0)