Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/258.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix built-in help command requiring quotes for nested subcommands
10 changes: 8 additions & 2 deletions src/cleo/commands/help_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ class HelpCommand(Command):
"command_name",
required=False,
description="The command name",
default="help",
default=["help"],
is_list=True,
)
]

Expand All @@ -43,7 +44,12 @@ def handle(self) -> int:

if self._command is None:
assert self._application is not None
self._command = self._application.find(self.argument("command_name"))
command_name = self.argument("command_name")
if isinstance(command_name, list):
command_name = " ".join(command_name)
if not command_name:
command_name = "help"
self._command = self._application.find(command_name)

self.line("")
TextDescriptor().describe(self._io, self._command)
Expand Down
4 changes: 2 additions & 2 deletions tests/fixtures/application_run5.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ Description:
Displays help for a command.

Usage:
help [options] [--] [<command_name>]
help [options] [--] [<command_name>...]

Arguments:
command_name The command name [default: "help"]
command_name The command name [default: ["help"]]

Options:
-h, --help Display help for the given command. When no command is given display help for the list command.
Expand Down
24 changes: 24 additions & 0 deletions tests/test_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,30 @@ def test_run_with_help(tester: ApplicationTester) -> None:
).read_text(encoding="utf-8")


def test_run_help_with_nested_subcommand() -> None:
app = Application()
app.add(FooSubNamespaced1Command())

tester1 = ApplicationTester(app)
exit1 = tester1.execute("help foo bar baz")
output1 = tester1.io.fetch_output()

tester2 = ApplicationTester(app)
exit2 = tester2.execute('help "foo bar baz"')
output2 = tester2.io.fetch_output()

tester3 = ApplicationTester(app)
exit3 = tester3.execute("--help foo bar baz")
output3 = tester3.io.fetch_output()

assert exit1 == 0
assert exit2 == 0
assert exit3 == 0
assert "The foo bar baz command" in output1
assert output1 == output2
assert output1 == output3


def test_run_with_input() -> None:
app = Application()
command = Foo3Command()
Expand Down