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