Tell the user they passed stdin to a command that doesn't accept it
(caller: str, stdin: Optional[IO]=sys.stdin)
| 95 | |
| 96 | |
| 97 | def reject_stdin(caller: str, stdin: Optional[IO]=sys.stdin) -> None: |
| 98 | """Tell the user they passed stdin to a command that doesn't accept it""" |
| 99 | |
| 100 | if not stdin: |
| 101 | return None |
| 102 | |
| 103 | if IN_DOCKER: |
| 104 | # when TTY is disabled in docker we cant tell if stdin is being piped in or not |
| 105 | # if we try to read stdin when its not piped we will hang indefinitely waiting for it |
| 106 | return None |
| 107 | |
| 108 | if not stdin.isatty(): |
| 109 | # stderr('READING STDIN TO REJECT...') |
| 110 | stdin_raw_text = stdin.read() |
| 111 | if stdin_raw_text.strip(): |
| 112 | # stderr('GOT STDIN!', len(stdin_str)) |
| 113 | stderr(f'[!] The "{caller}" command does not accept stdin (ignoring).', color='red') |
| 114 | stderr(f' Run archivebox "{caller} --help" to see usage and examples.') |
| 115 | stderr() |
| 116 | # raise SystemExit(1) |
| 117 | return None |
| 118 | |
| 119 | |
| 120 | def accept_stdin(stdin: Optional[IO]=sys.stdin) -> Optional[str]: |