Add warnings to commands that expect stdin
Signed-off-by: Evan Lloyd New-Schmidt <evan@new-schmidt.com>
This commit is contained in:
parent
e61f12d014
commit
3d908a2866
1 changed files with 11 additions and 1 deletions
12
src/main.rs
12
src/main.rs
|
@ -2,7 +2,7 @@ use std::{
|
|||
collections::HashSet,
|
||||
env,
|
||||
fs::File,
|
||||
io::{stderr, stdin, stdout, BufReader, Read, Write},
|
||||
io::{stderr, stdin, stdout, BufReader, IsTerminal, Read, Write},
|
||||
num::NonZeroUsize,
|
||||
path::PathBuf,
|
||||
process,
|
||||
|
@ -97,6 +97,8 @@ fn main() -> anyhow::Result<()> {
|
|||
.exit()
|
||||
}
|
||||
|
||||
warn_if_stdin_is_tty();
|
||||
|
||||
let pid = process::id();
|
||||
let span = info_span!("", pid);
|
||||
let _handle = span.enter();
|
||||
|
@ -174,6 +176,8 @@ fn main() -> anyhow::Result<()> {
|
|||
Cmd::Simplify { lang } => {
|
||||
use om_wikiparser::html;
|
||||
|
||||
warn_if_stdin_is_tty();
|
||||
|
||||
let mut input = String::new();
|
||||
stdin().read_to_string(&mut input)?;
|
||||
|
||||
|
@ -261,6 +265,12 @@ fn get_thread_count(requested: Option<isize>) -> anyhow::Result<NonZeroUsize> {
|
|||
Ok(procs)
|
||||
}
|
||||
|
||||
fn warn_if_stdin_is_tty() {
|
||||
if stdin().is_terminal() {
|
||||
warn!("Expecting input on stdin but it is a TTY");
|
||||
}
|
||||
}
|
||||
|
||||
/// Get the version returned by `git describe`, e.g.:
|
||||
/// - `v2.0` if a git tag
|
||||
/// - the commit hash `034ac04` if not a tag
|
||||
|
|
Loading…
Add table
Reference in a new issue