mirror of
https://github.com/ArchiveBox/ArchiveBox.git
synced 2025-05-19 01:15:11 -04:00
better stdin handling
This commit is contained in:
parent
ad3898add6
commit
f60b5ed867
1 changed files with 9 additions and 12 deletions
|
@ -61,21 +61,18 @@ def reject_stdin(caller: str, stdin: Optional[IO]=sys.stdin) -> None:
|
||||||
if stdin and not stdin.isatty():
|
if stdin and not stdin.isatty():
|
||||||
stdin_raw_text = stdin.read().strip()
|
stdin_raw_text = stdin.read().strip()
|
||||||
if stdin_raw_text:
|
if stdin_raw_text:
|
||||||
print(
|
stderr(f'[X] The "{caller}" command does not accept stdin.', color='red')
|
||||||
'{red}[X] The "{}" command does not accept stdin.{reset}\n'.format(
|
stderr(f' Run archivebox "{caller} --help" to see usage and examples.')
|
||||||
caller,
|
stderr()
|
||||||
**ANSI,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
print(' Run archivebox "{} --help" to see usage and examples.'.format(
|
|
||||||
caller,
|
|
||||||
))
|
|
||||||
print()
|
|
||||||
raise SystemExit(1)
|
raise SystemExit(1)
|
||||||
|
|
||||||
def accept_stdin(stdin: Optional[IO]=sys.stdin) -> Optional[str]:
|
def accept_stdin(stdin: Optional[IO]=sys.stdin) -> Optional[str]:
|
||||||
if stdin and not stdin.isatty():
|
"""accept any standard input and return it as a string or None"""
|
||||||
return stdin.read()
|
if not stdin:
|
||||||
|
return None
|
||||||
|
elif stdin and not stdin.isatty():
|
||||||
|
stdin_str = stdin.read().strip()
|
||||||
|
return stdin_str or None
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue