fix(bindings/cli): Skip empty stdin in non tty environments (#6714)

This commit is contained in:
realtimetodie 2023-01-05 06:15:36 +01:00 committed by GitHub
parent 918a01bf5c
commit 0076418819
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,6 +1,6 @@
use std::{
fs::{self, File},
io::{self, BufRead, Write},
io::{self, Read, Write},
path::{Path, PathBuf},
sync::Arc,
};
@ -245,14 +245,14 @@ fn collect_stdin_input() -> Option<String> {
return None;
}
Some(
io::stdin()
.lock()
.lines()
.map(|line| line.expect("Not able to read stdin"))
.collect::<Vec<String>>()
.join("\n"),
)
let mut buffer = String::new();
let result = io::stdin().lock().read_to_string(&mut buffer);
if result.is_ok() && !buffer.is_empty() {
Some(buffer)
} else {
None
}
}
struct InputContext {