This commit is contained in:
Jonah Caplan 2021-10-16 00:02:37 -04:00
parent a4a4709320
commit 91860bf682
5 changed files with 28 additions and 21 deletions

View file

@ -2,11 +2,11 @@ use std::path::PathBuf;
use std::sync::mpsc::Receiver; use std::sync::mpsc::Receiver;
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
use crate::config::Config;
use crate::error::print_error; use crate::error::print_error;
use crate::exit_codes::{merge_exitcodes, ExitCode}; use crate::exit_codes::{merge_exitcodes, ExitCode};
use crate::walk::WorkerResult;
use crate::filesystem::strip_current_dir; use crate::filesystem::strip_current_dir;
use crate::config::Config; use crate::walk::WorkerResult;
use super::CommandTemplate; use super::CommandTemplate;
@ -60,21 +60,23 @@ pub fn batch(
buffer_output: bool, buffer_output: bool,
config: &Arc<Config>, config: &Arc<Config>,
) -> ExitCode { ) -> ExitCode {
let paths = rx.iter().filter_map(|value| match value { let paths = rx
WorkerResult::Entry(val) => Some(val), .iter()
WorkerResult::Error(err) => { .filter_map(|value| match value {
if show_filesystem_errors { WorkerResult::Entry(val) => Some(val),
print_error(err.to_string()); WorkerResult::Error(err) => {
if show_filesystem_errors {
print_error(err.to_string());
}
None
} }
None })
} .map(|m| {
}) if config.no_strip {
.map(|m| { m
if config.no_strip { } else {
m strip_current_dir(&m).to_path_buf()
} else { }
strip_current_dir(&m).to_path_buf() });
}
});
cmd.generate_and_execute_batch(paths, buffer_output) cmd.generate_and_execute_batch(paths, buffer_output)
} }

View file

@ -144,7 +144,6 @@ impl CommandTemplate {
out_perm: Arc<Mutex<()>>, out_perm: Arc<Mutex<()>>,
buffer_output: bool, buffer_output: bool,
) -> ExitCode { ) -> ExitCode {
let mut cmd = Command::new(self.args[0].generate(&input, self.path_separator.as_deref())); let mut cmd = Command::new(self.args[0].generate(&input, self.path_separator.as_deref()));
for arg in &self.args[1..] { for arg in &self.args[1..] {
cmd.arg(arg.generate(&input, self.path_separator.as_deref())); cmd.arg(arg.generate(&input, self.path_separator.as_deref()));

View file

@ -376,7 +376,7 @@ fn construct_config(matches: clap::ArgMatches, pattern_regex: &str) -> Result<Co
} }
}), }),
no_strip: matches.is_present("path") || matches.is_present("search-path"), no_strip: matches.is_present("path") || matches.is_present("search-path"),
}) })
} }
fn extract_command( fn extract_command(

View file

@ -179,7 +179,13 @@ fn spawn_receiver(
// This will be set to `Some` if the `--exec` argument was supplied. // This will be set to `Some` if the `--exec` argument was supplied.
if let Some(ref cmd) = config.command { if let Some(ref cmd) = config.command {
if cmd.in_batch_mode() { if cmd.in_batch_mode() {
exec::batch(rx, cmd, show_filesystem_errors, enable_output_buffering, &config) exec::batch(
rx,
cmd,
show_filesystem_errors,
enable_output_buffering,
&config,
)
} else { } else {
let shared_rx = Arc::new(Mutex::new(rx)); let shared_rx = Arc::new(Mutex::new(rx));

View file

@ -1944,6 +1944,6 @@ fn test_no_strip() {
te.assert_output( te.assert_output(
&["c.foo", "./", "-X", "echo"], &["c.foo", "./", "-X", "echo"],
"./one/two/C.Foo2 ./one/two/c.foo" "./one/two/C.Foo2 ./one/two/c.foo",
) )
} }