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

feat: set --no-interaction when stdin is not a tty #245

Merged
merged 1 commit into from
Sep 2, 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
6 changes: 5 additions & 1 deletion cleo/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,11 @@ def _configure_io(self, io: IO) -> None:
elif io.input.has_parameter_option("--no-ansi", True):
io.decorated(False)

if io.input.has_parameter_option(["--no-interaction", "-n"], True):
if io.input.has_parameter_option(["--no-interaction", "-n"], True) or (
io.input._interactive is None
and io.input.stream
and not io.input.stream.isatty()
):
io.interactive(False)

shell_verbosity = int(os.getenv("SHELL_VERBOSITY", 0))
Expand Down
8 changes: 4 additions & 4 deletions cleo/io/inputs/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def __init__(self, definition: Definition | None = None) -> None:
self._stream: TextIO = None # type: ignore[assignment]
self._options: dict[str, Any] = {}
self._arguments: dict[str, Any] = {}
self._interactive = True
self._interactive: bool | None = None

if definition is None:
self._definition = Definition()
Expand Down Expand Up @@ -56,7 +56,7 @@ def read(self, length: int, default: str = "") -> str:
"""
Reads the given amount of characters from the input stream.
"""
if not self._interactive:
if not self.is_interactive():
return default

return self._stream.read(length)
Expand All @@ -65,7 +65,7 @@ def read_line(self, length: int = -1, default: str = "") -> str:
"""
Reads a line from the input stream.
"""
if not self._interactive:
if not self.is_interactive():
return default

return self._stream.readline(length)
Expand All @@ -83,7 +83,7 @@ def is_closed(self) -> bool:
return self._stream.closed

def is_interactive(self) -> bool:
return self._interactive
return True if self._interactive is None else self._interactive

def interactive(self, interactive: bool = True) -> None:
self._interactive = interactive
Expand Down
2 changes: 1 addition & 1 deletion cleo/testers/application_tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def execute(
self,
args: str = "",
inputs: str | None = None,
interactive: bool | None = None,
interactive: bool = True,
verbosity: Verbosity | None = None,
decorated: bool = False,
supports_utf8: bool = True,
Expand Down