diff options
author | Thomas Voss <mail@thomasvoss.com> | 2023-08-06 17:22:53 +0200 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2023-08-06 17:22:53 +0200 |
commit | ce5c445fd431f108e73bbe62b0ee73b8418d85c1 (patch) | |
tree | 13f86aba90bd346e4ead017830299bba1d7b2853 /src | |
parent | 439e8b14a2a56397a69afae219a0d7465431249a (diff) |
Make the -e flag work as intended
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/src/main.rs b/src/main.rs index bc00355..23a0bf6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,12 +5,14 @@ use std::{ ffi::OsString, fs, hash::{Hash, Hasher}, - io::{self, BufRead, BufReader, BufWriter, Write}, + io::{self, BufRead, BufReader, BufWriter, Read, Write}, iter, path::{Component, Path, PathBuf}, process::{self, Command, Stdio}, }; +use itertools::Itertools; + use { cerm::{err, warn}, tempfile::tempdir, @@ -48,14 +50,22 @@ fn work() -> Result<(), io::Error> { let (cmd, args) = rest.split_first().unwrap_or_else(|| usage(None)); // Collect sources from standard input - let srcs: Vec<_> = io::stdin() - .lines() - .map(|x| match x { - Err(e) => { err!("{e}"); }, - Ok(l) if l.is_empty() => usage(None), - Ok(l) => l, + let srcs = io::stdin() + .bytes() + .map(|x| { + x.unwrap_or_else(|e| { + err!("{e}"); + }) }) - .collect(); + .group_by(|b| *b == (b'\0' + b'\n' * !flags.nul as u8)); + let srcs = srcs + .into_iter() + .filter(|(x, _)| !x) + .map(|(_, x)| String::from_utf8(x.collect_vec())) + .collect::<Result<Vec<_>, _>>() + .unwrap_or_else(|e| { + err!("{e}"); + }); // Spawn the child process let mut child = Command::new(cmd) |