From d323b0b51dc3462fe6a05315d24e2ae37d3d023c Mon Sep 17 00:00:00 2001 From: Fedor Kuznetsov Date: Thu, 5 Jan 2023 03:55:41 +0500 Subject: [PATCH] Fix #258 --- src/cleo/application.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/cleo/application.py b/src/cleo/application.py index 33749998..287870ee 100644 --- a/src/cleo/application.py +++ b/src/cleo/application.py @@ -428,6 +428,32 @@ def _run(self, io: IO) -> int: io.input.set_stream(stream) io.input.interactive(interactive) + if name == "help" and isinstance(io.input, ArgvInput): + # If the command is `help` we suppose + # that all without `-` is a command (possible namespaced) + argv = io.input._tokens[:] + + if io.input.script_name is not None: + argv.insert(0, io.input.script_name) + else: + # Needs because `ApplicationTester` doesn't add script name + argv.insert(0, self.name) + + # filter all words after `help` without `-` + start = argv.index(name) + words = list(filter(lambda arg: "-" not in arg, argv[start + 1 :])) + + if words: + index = argv.index(words[0]) + argv[index] = " ".join(argv[index:]) + del argv[index + 1 :] + + stream = io.input.stream + interactive = io.input.is_interactive() + io.set_input(ArgvInput(argv)) + io.input.set_stream(stream) + io.input.interactive(interactive) + exit_code = self._run_command(command, io) self._running_command = None