diff --git a/examples/dd_test.rs b/examples/dd_test.rs index 2415836..e68ebcd 100644 --- a/examples/dd_test.rs +++ b/examples/dd_test.rs @@ -15,10 +15,10 @@ //! [INFO ] Total bandwidth: 1.11 GiB/s //! ``` use byte_unit::Byte; +use clap::Parser; use cmd_lib::*; use rayon::prelude::*; use std::time::Instant; -use clap::Parser; const DATA_SIZE: u64 = 10 * 1024 * 1024 * 1024; // 10GB data diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 0000000..e69de29 diff --git a/src/child.rs b/src/child.rs index 6e4f73d..07c7f54 100644 --- a/src/child.rs +++ b/src/child.rs @@ -354,14 +354,10 @@ impl StderrThread { .lines() .map_while(Result::ok) .for_each(|line| { - if !capture { - info!("{line}"); - } else { - if !output.is_empty() { - output.push('\n'); - } - output.push_str(&line); + if !output.is_empty() { + output.push('\n'); } + output.push_str(&line); }); return output; } diff --git a/src/process.rs b/src/process.rs index 11d84ee..d21ad3b 100644 --- a/src/process.rs +++ b/src/process.rs @@ -11,6 +11,7 @@ use std::ffi::{OsStr, OsString}; use std::fmt; use std::fs::{File, OpenOptions}; use std::io::{Error, ErrorKind, Result}; +use std::mem::take; use std::path::{Path, PathBuf}; use std::process::Command; use std::sync::Mutex; @@ -160,7 +161,7 @@ impl GroupCmds { #[doc(hidden)] #[derive(Default)] pub struct Cmds { - cmds: Vec>, + cmds: Vec, full_cmds: String, ignore_error: bool, file: String, @@ -188,7 +189,7 @@ impl Cmds { ); } } - self.cmds.push(Some(cmd)); + self.cmds.push(cmd); self } @@ -204,8 +205,7 @@ impl Cmds { let mut children: Vec = Vec::new(); let len = self.cmds.len(); let mut prev_pipe_in = None; - for (i, cmd_opt) in self.cmds.iter_mut().enumerate() { - let mut cmd = cmd_opt.take().unwrap(); + for (i, mut cmd) in take(&mut self.cmds).into_iter().enumerate() { if i != len - 1 { // not the last, update redirects let (pipe_reader, pipe_writer) =