Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't clear interactive state on namespace commands #234

Merged
merged 1 commit into from Aug 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions cleo/application.py
Expand Up @@ -417,8 +417,10 @@ def _run(self, io: IO) -> int:
del argv[index + 1 : index + 1 + (len(name.split(" ")) - 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
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/foo3_command.py
Expand Up @@ -12,6 +12,6 @@ class Foo3Command(Command):
aliases = ["foo3"]

def handle(self) -> int:
question = self.ask("echo:")
question = self.ask("echo:", default="default input")
self.line(question)
return 0
2 changes: 1 addition & 1 deletion tests/fixtures/foo_sub_namespaced3_command.py
Expand Up @@ -12,6 +12,6 @@ class FooSubNamespaced3Command(Command):
aliases = ["foobar"]

def handle(self) -> int:
question = self.ask("")
question = self.ask("", default="default input")
self.line(question)
return 0
12 changes: 12 additions & 0 deletions tests/test_application.py
Expand Up @@ -376,3 +376,15 @@ def test_run_namespaced_with_input() -> None:

assert status_code == 0
assert tester.io.fetch_output() == "Hello world!\n"


@pytest.mark.parametrize("cmd", (Foo3Command(), FooSubNamespaced3Command()))
def test_run_with_input_and_non_interactive(cmd: Command) -> None:
app = Application()
app.add(cmd)

tester = ApplicationTester(app)
status_code = tester.execute(f"--no-interaction {cmd.name}", inputs="Hello world!")

assert status_code == 0
assert tester.io.fetch_output() == "default input\n"