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 @@
Fixed the built-in `help` command failing to resolve namespaced sub-commands passed as separate tokens.
8 changes: 6 additions & 2 deletions src/cleo/commands/help_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ class HelpCommand(Command):
Argument(
"command_name",
required=False,
is_list=True,
description="The command name",
default="help",
default=["help"],
)
]

Expand All @@ -43,7 +44,10 @@ 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)
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
9 changes: 9 additions & 0 deletions tests/test_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,15 @@ def test_run_with_help(tester: ApplicationTester) -> None:
).read_text(encoding="utf-8")


def test_run_help_command_with_namespaced_command(app: Application) -> None:
app.catch_exceptions(False)
app.add(FooSubNamespaced1Command())
tester = ApplicationTester(app)

assert tester.execute("help foo bar baz", decorated=False) == 0
assert "The foo bar baz command" in tester.io.fetch_output()


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