aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2023-08-06 17:22:53 +0200
committerThomas Voss <mail@thomasvoss.com> 2023-08-06 17:22:53 +0200
commitce5c445fd431f108e73bbe62b0ee73b8418d85c1 (patch)
tree13f86aba90bd346e4ead017830299bba1d7b2853
parent439e8b14a2a56397a69afae219a0d7465431249a (diff)
Make the -e flag work as intended
-rw-r--r--Cargo.lock16
-rw-r--r--Cargo.toml1
-rw-r--r--src/main.rs26
3 files changed, 35 insertions, 8 deletions
diff --git a/Cargo.lock b/Cargo.lock
index ed60ec2..5fc2540 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -33,6 +33,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
+name = "either"
+version = "1.9.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07"
+
+[[package]]
name = "errno"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -60,6 +66,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6999dc1837253364c2ebb0704ba97994bd874e8f195d665c50b7548f6ea92764"
[[package]]
+name = "itertools"
+version = "0.11.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b1c173a5686ce8bfa551b3563d0c2170bf24ca44da99c7ca4bfdab5418c3fe57"
+dependencies = [
+ "either",
+]
+
+[[package]]
name = "lexopt"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -82,6 +97,7 @@ name = "mmv"
version = "0.1.0"
dependencies = [
"cerm",
+ "itertools",
"lexopt",
"tempfile",
]
diff --git a/Cargo.toml b/Cargo.toml
index fac1bb2..262e69a 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -11,5 +11,6 @@ authors = [
[dependencies]
cerm = "1.0.0"
+itertools = "0.11.0"
lexopt = "0.1.0"
tempfile = "3.7.0"
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)