Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"