MCPcopy
hub / github.com/ArchiveBox/ArchiveBox / reject_stdin

Function reject_stdin

archivebox/logging_util.py:97–117  ·  view source on GitHub ↗

Tell the user they passed stdin to a command that doesn't accept it

(caller: str, stdin: Optional[IO]=sys.stdin)

Source from the content-addressed store, hash-verified

95
96
97def 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
120def accept_stdin(stdin: Optional[IO]=sys.stdin) -> Optional[str]:

Callers 9

mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85

Calls 1

stderrFunction · 0.85

Tested by

no test coverage detected