From 4d0c7571609b60568e8c33681ec189c2fd9da517 Mon Sep 17 00:00:00 2001 From: Sai Asish Y Date: Tue, 12 May 2026 21:58:05 -0700 Subject: [PATCH] fix: resolve namespaced sub-commands in help command --- news/258.bugfix.md | 1 + src/cleo/commands/help_command.py | 8 ++++++-- tests/fixtures/application_run5.txt | 4 ++-- tests/test_application.py | 9 +++++++++ 4 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 news/258.bugfix.md diff --git a/news/258.bugfix.md b/news/258.bugfix.md new file mode 100644 index 00000000..32a6049b --- /dev/null +++ b/news/258.bugfix.md @@ -0,0 +1 @@ +Fixed the built-in `help` command failing to resolve namespaced sub-commands passed as separate tokens. diff --git a/src/cleo/commands/help_command.py b/src/cleo/commands/help_command.py index a52713eb..9d8ae6c0 100644 --- a/src/cleo/commands/help_command.py +++ b/src/cleo/commands/help_command.py @@ -15,8 +15,9 @@ class HelpCommand(Command): Argument( "command_name", required=False, + is_list=True, description="The command name", - default="help", + default=["help"], ) ] @@ -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) diff --git a/tests/fixtures/application_run5.txt b/tests/fixtures/application_run5.txt index a322d59f..22244549 100644 --- a/tests/fixtures/application_run5.txt +++ b/tests/fixtures/application_run5.txt @@ -3,10 +3,10 @@ Description: Displays help for a command. Usage: - help [options] [--] [] + help [options] [--] [...] 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. diff --git a/tests/test_application.py b/tests/test_application.py index f08286a4..80142de6 100644 --- a/tests/test_application.py +++ b/tests/test_application.py @@ -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()