Skip to content

Commit

Permalink
fix: don't clear interactive state on namespace commands (#234)
Browse files Browse the repository at this point in the history
  • Loading branch information
branchvincent committed Aug 25, 2022
1 parent 1f7e94a commit 2891bb0
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
2 changes: 2 additions & 0 deletions cleo/application.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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"

0 comments on commit 2891bb0

Please sign in to comment.