1
0
Fork 0
mirror of synced 2024-06-14 08:25:21 +12:00

better stdin handling

This commit is contained in:
Nick Sweeting 2019-05-01 02:28:12 -04:00
parent ad3898add6
commit f60b5ed867

View file

@ -61,21 +61,18 @@ def reject_stdin(caller: str, stdin: Optional[IO]=sys.stdin) -> None:
if stdin and not stdin.isatty():
stdin_raw_text = stdin.read().strip()
if stdin_raw_text:
print(
'{red}[X] The "{}" command does not accept stdin.{reset}\n'.format(
caller,
**ANSI,
)
)
print(' Run archivebox "{} --help" to see usage and examples.'.format(
caller,
))
print()
stderr(f'[X] The "{caller}" command does not accept stdin.', color='red')
stderr(f' Run archivebox "{caller} --help" to see usage and examples.')
stderr()
raise SystemExit(1)
def accept_stdin(stdin: Optional[IO]=sys.stdin) -> Optional[str]:
if stdin and not stdin.isatty():
return stdin.read()
"""accept any standard input and return it as a string or None"""
if not stdin:
return None
elif stdin and not stdin.isatty():
stdin_str = stdin.read().strip()
return stdin_str or None
return None