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/320.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improved the error message for invalid subcommands in a command namespace.
2 changes: 2 additions & 0 deletions src/cleo/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,8 @@ def _get_command_name(self, io: IO) -> str | None:
if self.has(candidate):
return candidate

return candidates[-1]

return io.input.first_argument

def extract_namespace(self, name: str, limit: int | None = None) -> str:
Expand Down
12 changes: 12 additions & 0 deletions tests/test_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,18 @@ def test_set_catch_exceptions(app: Application, environ: dict[str, str]) -> None
tester.execute("foo", decorated=False)


def test_invalid_subcommand_uses_full_command_name(app: Application) -> None:
app.auto_exits(False)
app.catch_exceptions(True)
app.add(FooCommand())

tester = ApplicationTester(app)
tester.execute("foo baz", decorated=False)

assert tester.status_code == 1
assert 'The command "foo baz" does not exist.' in tester.io.fetch_error()


def test_auto_exit(app: Application) -> None:
app.auto_exits(False)
assert not app.is_auto_exit_enabled()
Expand Down