Skip to content
Myr

mod.rs

This file

Path

src/exec/mod.rs

526 lines · 17.8 KiB · Rust

Last changed by

Error out if no args provided to --exec or --exec-batchThayne McCombsbefore adoptionc577b08

History of this file

Take it

The walk stopped after 200 commits: lines older than 9412648 point at it.

Add link to troubleshooting sectionsharkdpbefore adoption9412648

lines 1–5why, one step back
1mod command;
2mod input;3mod job;4mod token;5

use custom --path-separator in arguments to --execAllen Wildbefore adoption8a532e5

lines 6–8why, one step back
6use std::borrow::Cow;
7use std::ffi::{OsStr, OsString};8use std::path::{Component, Path, PathBuf, Prefix};

Add link to troubleshooting sectionsharkdpbefore adoption9412648

lines 9–11why, one step back
9use std::process::{Command, Stdio};
10use std::sync::{Arc, Mutex};11

Error out if no args provided to --exec or --exec-batchThayne McCombsbefore adoptionc577b08

line 12why, one step back
12use anyhow::{bail, Result};

Remove `lazy_static` from dependenciesShun Sakaibefore adoption0484486

line 13why, one step back
13use once_cell::sync::Lazy;

Add link to troubleshooting sectionsharkdpbefore adoption9412648

lines 14–17why, one step back
14use regex::Regex;
1516use crate::exit_codes::ExitCode;17

Group together output from multi exec commandsThayne McCombsbefore adoption9fb0c5d

line 18why, one step back
18use self::command::{execute_commands, handle_cmd_error};

Add link to troubleshooting sectionsharkdpbefore adoption9412648

lines 19–32why, one step back
19use self::input::{basename, dirname, remove_extension};
20pub use self::job::{batch, job};21use self::token::Token;2223/// Execution mode of the command24#[derive(Debug, Clone, Copy, PartialEq)]25pub enum ExecutionMode {26 /// Command is executed for each search result27 OneByOne,28 /// Command is run for a batch of results at once29 Batch,30}3132#[derive(Debug, Clone, PartialEq)]

Support multiple `--exec` instancesThayne McCombsbefore adoption0aee9b0

line 33why, one step back
33pub struct CommandSet {

Add link to troubleshooting sectionsharkdpbefore adoption9412648

line 34why, one step back
34 mode: ExecutionMode,

use custom --path-separator in arguments to --execAllen Wildbefore adoption8a532e5

line 35why, one step back
35 path_separator: Option<String>,

Support multiple `--exec` instancesThayne McCombsbefore adoption0aee9b0

line 36why, one step back
36 commands: Vec<CommandTemplate>,

Add link to troubleshooting sectionsharkdpbefore adoption9412648

lines 37–38why, one step back
37}
38

Support multiple `--exec` instancesThayne McCombsbefore adoption0aee9b0

line 39why, one step back
39impl CommandSet {

Error out if no args provided to --exec or --exec-batchThayne McCombsbefore adoptionc577b08

line 40why, one step back
40 pub fn new<I, S>(input: I, path_separator: Option<String>) -> Result<CommandSet>

Add link to troubleshooting sectionsharkdpbefore adoption9412648

line 41why, one step back
41 where

Support multiple `--exec` instancesThayne McCombsbefore adoption0aee9b0

line 42why, one step back
42 I: IntoIterator<Item = Vec<S>>,

Add link to troubleshooting sectionsharkdpbefore adoption9412648

lines 43–44why, one step back
43 S: AsRef<str>,
44 {

Error out if no args provided to --exec or --exec-batchThayne McCombsbefore adoptionc577b08

line 45why, one step back
45 Ok(CommandSet {

Support multiple `--exec` instancesThayne McCombsbefore adoption0aee9b0

lines 46–47why, one step back
46 mode: ExecutionMode::OneByOne,
47 path_separator,

Error out if no args provided to --exec or --exec-batchThayne McCombsbefore adoptionc577b08

lines 48–52why, one step back
48 commands: input
49 .into_iter()50 .map(CommandTemplate::new)51 .collect::<Result<_>>()?,52 })

Add link to troubleshooting sectionsharkdpbefore adoption9412648

lines 53–54why, one step back
53 }
54

Support multiple `--exec` instancesThayne McCombsbefore adoption0aee9b0

line 55why, one step back
55 pub fn new_batch<I, S>(input: I, path_separator: Option<String>) -> Result<CommandSet>

Add link to troubleshooting sectionsharkdpbefore adoption9412648

line 56why, one step back
56 where

Support multiple `--exec` instancesThayne McCombsbefore adoption0aee9b0

line 57why, one step back
57 I: IntoIterator<Item = Vec<S>>,

Add link to troubleshooting sectionsharkdpbefore adoption9412648

lines 58–59why, one step back
58 S: AsRef<str>,
59 {

Support multiple `--exec` instancesThayne McCombsbefore adoption0aee9b0

lines 60–65why, one step back
60 Ok(CommandSet {
61 mode: ExecutionMode::Batch,62 path_separator,63 commands: input64 .into_iter()65 .map(|args| {

Error out if no args provided to --exec or --exec-batchThayne McCombsbefore adoptionc577b08

line 66why, one step back
66 let cmd = CommandTemplate::new(args)?;

Support multiple `--exec` instancesThayne McCombsbefore adoption0aee9b0

line 67why, one step back
67 if cmd.number_of_tokens() > 1 {

Error out if no args provided to --exec or --exec-batchThayne McCombsbefore adoptionc577b08

line 68why, one step back
68 bail!("Only one placeholder allowed for batch commands");

Support multiple `--exec` instancesThayne McCombsbefore adoption0aee9b0

lines 69–70why, one step back
69 }
70 if cmd.args[0].has_tokens() {

Error out if no args provided to --exec or --exec-batchThayne McCombsbefore adoptionc577b08

line 71why, one step back
71 bail!("First argument of exec-batch is expected to be a fixed executable");

Support multiple `--exec` instancesThayne McCombsbefore adoption0aee9b0

lines 72–82why, one step back
72 }
73 Ok(cmd)74 })75 .collect::<Result<Vec<_>>>()?,76 })77 }7879 pub fn in_batch_mode(&self) -> bool {80 self.mode == ExecutionMode::Batch81 }82

Error out if no args provided to --exec or --exec-batchThayne McCombsbefore adoptionc577b08

line 83why, one step back
83 pub fn execute(&self, input: &Path, out_perm: Arc<Mutex<()>>, buffer_output: bool) -> ExitCode {

Support multiple `--exec` instancesThayne McCombsbefore adoption0aee9b0

line 84why, one step back
84 let path_separator = self.path_separator.as_deref();

Group together output from multi exec commandsThayne McCombsbefore adoption9fb0c5d

lines 85–88why, one step back
85 let commands = self
86 .commands87 .iter()88 .map(|c| c.generate(input, path_separator));

Error out if no args provided to --exec or --exec-batchThayne McCombsbefore adoptionc577b08

line 89why, one step back
89 execute_commands(commands, &out_perm, buffer_output)

Support multiple `--exec` instancesThayne McCombsbefore adoption0aee9b0

lines 90–91why, one step back
90 }
91

Group together output from multi exec commandsThayne McCombsbefore adoption9fb0c5d

line 92why, one step back
92 pub fn execute_batch<I>(&self, paths: I) -> ExitCode

Support multiple `--exec` instancesThayne McCombsbefore adoption0aee9b0

lines 93–99why, one step back
93 where
94 I: Iterator<Item = PathBuf>,95 {96 let path_separator = self.path_separator.as_deref();97 let mut paths = paths.collect::<Vec<_>>();98 paths.sort();99 for cmd in &self.commands {

Group together output from multi exec commandsThayne McCombsbefore adoption9fb0c5d

line 100why, one step back
100 let exit = cmd.generate_and_execute_batch(&paths, path_separator);

Support multiple `--exec` instancesThayne McCombsbefore adoption0aee9b0

lines 101–103why, one step back
101 if exit != ExitCode::Success {
102 return exit;103 }

Add link to troubleshooting sectionsharkdpbefore adoption9412648

line 104why, one step back
104 }

Support multiple `--exec` instancesThayne McCombsbefore adoption0aee9b0

line 105why, one step back
105 ExitCode::Success

Add link to troubleshooting sectionsharkdpbefore adoption9412648

line 106why, one step back
106 }

Support multiple `--exec` instancesThayne McCombsbefore adoption0aee9b0

line 107why, one step back
107}

Add link to troubleshooting sectionsharkdpbefore adoption9412648

line 108why, one step back
108

Support multiple `--exec` instancesThayne McCombsbefore adoption0aee9b0

lines 109–118why, one step back
109/// Represents a template that is utilized to generate command strings.
110///111/// The template is meant to be coupled with an input in order to generate a command. The112/// `generate_and_execute()` method will be used to generate a command and execute it.113#[derive(Debug, Clone, PartialEq)]114struct CommandTemplate {115 args: Vec<ArgumentTemplate>,116}117118impl CommandTemplate {

Error out if no args provided to --exec or --exec-batchThayne McCombsbefore adoptionc577b08

line 119why, one step back
119 fn new<I, S>(input: I) -> Result<CommandTemplate>

Add link to troubleshooting sectionsharkdpbefore adoption9412648

lines 120–123why, one step back
120 where
121 I: IntoIterator<Item = S>,122 S: AsRef<str>,123 {

Remove `lazy_static` from dependenciesShun Sakaibefore adoption0484486

lines 124–125why, one step back
124 static PLACEHOLDER_PATTERN: Lazy<Regex> =
125 Lazy::new(|| Regex::new(r"\{(/?\.?|//)\}").unwrap());

Add link to troubleshooting sectionsharkdpbefore adoption9412648

lines 126–169why, one step back
126
127 let mut args = Vec::new();128 let mut has_placeholder = false;129130 for arg in input {131 let arg = arg.as_ref();132133 let mut tokens = Vec::new();134 let mut start = 0;135136 for placeholder in PLACEHOLDER_PATTERN.find_iter(arg) {137 // Leading text before the placeholder.138 if placeholder.start() > start {139 tokens.push(Token::Text(arg[start..placeholder.start()].to_owned()));140 }141142 start = placeholder.end();143144 match placeholder.as_str() {145 "{}" => tokens.push(Token::Placeholder),146 "{.}" => tokens.push(Token::NoExt),147 "{/}" => tokens.push(Token::Basename),148 "{//}" => tokens.push(Token::Parent),149 "{/.}" => tokens.push(Token::BasenameNoExt),150 _ => unreachable!("Unhandled placeholder"),151 }152153 has_placeholder = true;154 }155156 // Without a placeholder, the argument is just fixed text.157 if tokens.is_empty() {158 args.push(ArgumentTemplate::Text(arg.to_owned()));159 continue;160 }161162 if start < arg.len() {163 // Trailing text after last placeholder.164 tokens.push(Token::Text(arg[start..].to_owned()));165 }166167 args.push(ArgumentTemplate::Tokens(tokens));168 }169

Error out if no args provided to --exec or --exec-batchThayne McCombsbefore adoptionc577b08

lines 170–178why, one step back
170 // We need to check that we have at least one argument, because if not
171 // it will try to execute each file and directory it finds.172 //173 // Sadly, clap can't currently handle this for us, see174 // https://github.com/clap-rs/clap/issues/3542175 if args.is_empty() {176 bail!("No executable provided for --exec or --exec-batch");177 }178

Add link to troubleshooting sectionsharkdpbefore adoption9412648

lines 179–183why, one step back
179 // If a placeholder token was not supplied, append one at the end of the command.
180 if !has_placeholder {181 args.push(ArgumentTemplate::Tokens(vec![Token::Placeholder]));182 }183

Error out if no args provided to --exec or --exec-batchThayne McCombsbefore adoptionc577b08

line 184why, one step back
184 Ok(CommandTemplate { args })

Add link to troubleshooting sectionsharkdpbefore adoption9412648

lines 185–193why, one step back
185 }
186187 fn number_of_tokens(&self) -> usize {188 self.args.iter().filter(|arg| arg.has_tokens()).count()189 }190191 /// Generates and executes a command.192 ///193 /// Using the internal `args` field, and a supplied `input` variable, a `Command` will be

Group together output from multi exec commandsThayne McCombsbefore adoption9fb0c5d

lines 194–195why, one step back
194 /// build.
195 fn generate(&self, input: &Path, path_separator: Option<&str>) -> Command {

Support multiple `--exec` instancesThayne McCombsbefore adoption0aee9b0

line 196why, one step back
196 let mut cmd = Command::new(self.args[0].generate(&input, path_separator));

Add link to troubleshooting sectionsharkdpbefore adoption9412648

line 197why, one step back
197 for arg in &self.args[1..] {

Support multiple `--exec` instancesThayne McCombsbefore adoption0aee9b0

line 198why, one step back
198 cmd.arg(arg.generate(&input, path_separator));

Add link to troubleshooting sectionsharkdpbefore adoption9412648

line 199why, one step back
199 }

Group together output from multi exec commandsThayne McCombsbefore adoption9fb0c5d

line 200why, one step back
200 cmd

Add link to troubleshooting sectionsharkdpbefore adoption9412648

lines 201–202why, one step back
201 }
202

Support multiple `--exec` instancesThayne McCombsbefore adoption0aee9b0

lines 203–204why, one step back
203 fn generate_and_execute_batch(
204 &self,

Fix clippy lintsThayne McCombsbefore adoptionf27332e

line 205why, one step back
205 paths: &[PathBuf],

Support multiple `--exec` instancesThayne McCombsbefore adoption0aee9b0

lines 206–207why, one step back
206 path_separator: Option<&str>,
207 ) -> ExitCode {

use custom --path-separator in arguments to --execAllen Wildbefore adoption8a532e5

line 208why, one step back
208 let mut cmd = Command::new(self.args[0].generate("", None));

Add link to troubleshooting sectionsharkdpbefore adoption9412648

lines 209–216why, one step back
209 cmd.stdin(Stdio::inherit());
210 cmd.stdout(Stdio::inherit());211 cmd.stderr(Stdio::inherit());212213 let mut has_path = false;214215 for arg in &self.args[1..] {216 if arg.has_tokens() {

Support multiple `--exec` instancesThayne McCombsbefore adoption0aee9b0

lines 217–218why, one step back
217 for path in paths {
218 cmd.arg(arg.generate(path, path_separator));

Add link to troubleshooting sectionsharkdpbefore adoption9412648

lines 219–221why, one step back
219 has_path = true;
220 }221 } else {

use custom --path-separator in arguments to --execAllen Wildbefore adoption8a532e5

line 222why, one step back
222 cmd.arg(arg.generate("", None));

Add link to troubleshooting sectionsharkdpbefore adoption9412648

lines 223–226why, one step back
223 }
224 }225226 if has_path {

Group together output from multi exec commandsThayne McCombsbefore adoption9fb0c5d

lines 227–230why, one step back
227 match cmd.spawn().and_then(|mut c| c.wait()) {
228 Ok(_) => ExitCode::Success,229 Err(e) => handle_cmd_error(&cmd, e),230 }

Add link to troubleshooting sectionsharkdpbefore adoption9412648

lines 231–248why, one step back
231 } else {
232 ExitCode::Success233 }234 }235}236237/// Represents a template for a single command argument.238///239/// The argument is either a collection of `Token`s including at least one placeholder variant, or240/// a fixed text.241#[derive(Clone, Debug, PartialEq)]242enum ArgumentTemplate {243 Tokens(Vec<Token>),244 Text(String),245}246247impl ArgumentTemplate {248 pub fn has_tokens(&self) -> bool {

Fix clippy warningsDavid Peterbefore adoption2a2126c

line 249why, one step back
249 matches!(self, ArgumentTemplate::Tokens(_))

Add link to troubleshooting sectionsharkdpbefore adoption9412648

lines 250–251why, one step back
250 }
251

use custom --path-separator in arguments to --execAllen Wildbefore adoption8a532e5

lines 252–255why, one step back
252 /// Generate an argument from this template. If path_separator is Some, then it will replace
253 /// the path separator in all placeholder tokens. Text arguments and tokens are not affected by254 /// path separator substitution.255 pub fn generate(&self, path: impl AsRef<Path>, path_separator: Option<&str>) -> OsString {

Add link to troubleshooting sectionsharkdpbefore adoption9412648

line 256why, one step back
256 use self::Token::*;

use custom --path-separator in arguments to --execAllen Wildbefore adoption8a532e5

line 257why, one step back
257 let path = path.as_ref();

Add link to troubleshooting sectionsharkdpbefore adoption9412648

lines 258–263why, one step back
258
259 match *self {260 ArgumentTemplate::Tokens(ref tokens) => {261 let mut s = OsString::new();262 for token in tokens {263 match *token {

use custom --path-separator in arguments to --execAllen Wildbefore adoption8a532e5

lines 264–275why, one step back
264 Basename => s.push(Self::replace_separator(basename(path), path_separator)),
265 BasenameNoExt => s.push(Self::replace_separator(266 &remove_extension(basename(path).as_ref()),267 path_separator,268 )),269 NoExt => s.push(Self::replace_separator(270 &remove_extension(path),271 path_separator,272 )),273 Parent => s.push(Self::replace_separator(&dirname(path), path_separator)),274 Placeholder => {275 s.push(Self::replace_separator(path.as_ref(), path_separator))

Add link to troubleshooting sectionsharkdpbefore adoption9412648

lines 276–284why, one step back
276 }
277 Text(ref string) => s.push(string),278 }279 }280 s281 }282 ArgumentTemplate::Text(ref text) => OsString::from(text),283 }284 }

use custom --path-separator in arguments to --execAllen Wildbefore adoption8a532e5

lines 285–339why, one step back
285
286 /// Replace the path separator in the input with the custom separator string. If path_separator287 /// is None, simply return a borrowed Cow<OsStr> of the input. Otherwise, the input is288 /// interpreted as a Path and its components are iterated through and re-joined into a new289 /// OsString.290 fn replace_separator<'a>(path: &'a OsStr, path_separator: Option<&str>) -> Cow<'a, OsStr> {291 // fast-path - no replacement necessary292 if path_separator.is_none() {293 return Cow::Borrowed(path);294 }295296 let path_separator = path_separator.unwrap();297 let mut out = OsString::with_capacity(path.len());298 let mut components = Path::new(path).components().peekable();299300 while let Some(comp) = components.next() {301 match comp {302 // Absolute paths on Windows are tricky. A Prefix component is usually a drive303 // letter or UNC path, and is usually followed by RootDir. There are also304 // "verbatim" prefixes beginning with "\\?\" that skip normalization. We choose to305 // ignore verbatim path prefixes here because they're very rare, might be306 // impossible to reach here, and there's no good way to deal with them. If users307 // are doing something advanced involving verbatim windows paths, they can do their308 // own output filtering with a tool like sed.309 Component::Prefix(prefix) => {310 if let Prefix::UNC(server, share) = prefix.kind() {311 // Prefix::UNC is a parsed version of '\\server\share'312 out.push(path_separator);313 out.push(path_separator);314 out.push(server);315 out.push(path_separator);316 out.push(share);317 } else {318 // All other Windows prefix types are rendered as-is. This results in e.g. "C:" for319 // drive letters. DeviceNS and Verbatim* prefixes won't have backslashes converted,320 // but they're not returned by directories fd can search anyway so we don't worry321 // about them.322 out.push(comp.as_os_str());323 }324 }325326 // Root directory is always replaced with the custom separator.327 Component::RootDir => out.push(path_separator),328329 // Everything else is joined normally, with a trailing separator if we're not last330 _ => {331 out.push(comp.as_os_str());332 if components.peek().is_some() {333 out.push(path_separator);334 }335 }336 }337 }338 Cow::Owned(out)339 }

Add link to troubleshooting sectionsharkdpbefore adoption9412648

lines 340–348why, one step back
340}
341342#[cfg(test)]343mod tests {344 use super::*;345346 #[test]347 fn tokens_with_placeholder() {348 assert_eq!(

Error out if no args provided to --exec or --exec-batchThayne McCombsbefore adoptionc577b08

line 349why, one step back
349 CommandSet::new(vec![vec![&"echo", &"${SHELL}:"]], None).unwrap(),

Support multiple `--exec` instancesThayne McCombsbefore adoption0aee9b0

lines 350–357why, one step back
350 CommandSet {
351 commands: vec![CommandTemplate {352 args: vec![353 ArgumentTemplate::Text("echo".into()),354 ArgumentTemplate::Text("${SHELL}:".into()),355 ArgumentTemplate::Tokens(vec![Token::Placeholder]),356 ]357 }],

Add link to troubleshooting sectionsharkdpbefore adoption9412648

line 358why, one step back
358 mode: ExecutionMode::OneByOne,

use custom --path-separator in arguments to --execAllen Wildbefore adoption8a532e5

line 359why, one step back
359 path_separator: None,

Add link to troubleshooting sectionsharkdpbefore adoption9412648

lines 360–366why, one step back
360 }
361 );362 }363364 #[test]365 fn tokens_with_no_extension() {366 assert_eq!(

Error out if no args provided to --exec or --exec-batchThayne McCombsbefore adoptionc577b08

line 367why, one step back
367 CommandSet::new(vec![vec!["echo", "{.}"]], None).unwrap(),

Support multiple `--exec` instancesThayne McCombsbefore adoption0aee9b0

lines 368–374why, one step back
368 CommandSet {
369 commands: vec![CommandTemplate {370 args: vec![371 ArgumentTemplate::Text("echo".into()),372 ArgumentTemplate::Tokens(vec![Token::NoExt]),373 ],374 }],

Add link to troubleshooting sectionsharkdpbefore adoption9412648

line 375why, one step back
375 mode: ExecutionMode::OneByOne,

use custom --path-separator in arguments to --execAllen Wildbefore adoption8a532e5

line 376why, one step back
376 path_separator: None,

Add link to troubleshooting sectionsharkdpbefore adoption9412648

lines 377–383why, one step back
377 }
378 );379 }380381 #[test]382 fn tokens_with_basename() {383 assert_eq!(

Error out if no args provided to --exec or --exec-batchThayne McCombsbefore adoptionc577b08

line 384why, one step back
384 CommandSet::new(vec![vec!["echo", "{/}"]], None).unwrap(),

Support multiple `--exec` instancesThayne McCombsbefore adoption0aee9b0

lines 385–391why, one step back
385 CommandSet {
386 commands: vec![CommandTemplate {387 args: vec![388 ArgumentTemplate::Text("echo".into()),389 ArgumentTemplate::Tokens(vec![Token::Basename]),390 ],391 }],

Add link to troubleshooting sectionsharkdpbefore adoption9412648

line 392why, one step back
392 mode: ExecutionMode::OneByOne,

use custom --path-separator in arguments to --execAllen Wildbefore adoption8a532e5

line 393why, one step back
393 path_separator: None,

Add link to troubleshooting sectionsharkdpbefore adoption9412648

lines 394–400why, one step back
394 }
395 );396 }397398 #[test]399 fn tokens_with_parent() {400 assert_eq!(

Error out if no args provided to --exec or --exec-batchThayne McCombsbefore adoptionc577b08

line 401why, one step back
401 CommandSet::new(vec![vec!["echo", "{//}"]], None).unwrap(),

Support multiple `--exec` instancesThayne McCombsbefore adoption0aee9b0

lines 402–408why, one step back
402 CommandSet {
403 commands: vec![CommandTemplate {404 args: vec![405 ArgumentTemplate::Text("echo".into()),406 ArgumentTemplate::Tokens(vec![Token::Parent]),407 ],408 }],

Add link to troubleshooting sectionsharkdpbefore adoption9412648

line 409why, one step back
409 mode: ExecutionMode::OneByOne,

use custom --path-separator in arguments to --execAllen Wildbefore adoption8a532e5

line 410why, one step back
410 path_separator: None,

Add link to troubleshooting sectionsharkdpbefore adoption9412648

lines 411–417why, one step back
411 }
412 );413 }414415 #[test]416 fn tokens_with_basename_no_extension() {417 assert_eq!(

Error out if no args provided to --exec or --exec-batchThayne McCombsbefore adoptionc577b08

line 418why, one step back
418 CommandSet::new(vec![vec!["echo", "{/.}"]], None).unwrap(),

Support multiple `--exec` instancesThayne McCombsbefore adoption0aee9b0

lines 419–425why, one step back
419 CommandSet {
420 commands: vec![CommandTemplate {421 args: vec![422 ArgumentTemplate::Text("echo".into()),423 ArgumentTemplate::Tokens(vec![Token::BasenameNoExt]),424 ],425 }],

Add link to troubleshooting sectionsharkdpbefore adoption9412648

line 426why, one step back
426 mode: ExecutionMode::OneByOne,

use custom --path-separator in arguments to --execAllen Wildbefore adoption8a532e5

line 427why, one step back
427 path_separator: None,

Add link to troubleshooting sectionsharkdpbefore adoption9412648

lines 428–434why, one step back
428 }
429 );430 }431432 #[test]433 fn tokens_multiple() {434 assert_eq!(

Error out if no args provided to --exec or --exec-batchThayne McCombsbefore adoptionc577b08

line 435why, one step back
435 CommandSet::new(vec![vec!["cp", "{}", "{/.}.ext"]], None).unwrap(),

Support multiple `--exec` instancesThayne McCombsbefore adoption0aee9b0

lines 436–446why, one step back
436 CommandSet {
437 commands: vec![CommandTemplate {438 args: vec![439 ArgumentTemplate::Text("cp".into()),440 ArgumentTemplate::Tokens(vec![Token::Placeholder]),441 ArgumentTemplate::Tokens(vec![442 Token::BasenameNoExt,443 Token::Text(".ext".into())444 ]),445 ],446 }],

Add link to troubleshooting sectionsharkdpbefore adoption9412648

line 447why, one step back
447 mode: ExecutionMode::OneByOne,

use custom --path-separator in arguments to --execAllen Wildbefore adoption8a532e5

line 448why, one step back
448 path_separator: None,

Add link to troubleshooting sectionsharkdpbefore adoption9412648

lines 449–455why, one step back
449 }
450 );451 }452453 #[test]454 fn tokens_single_batch() {455 assert_eq!(

Support multiple `--exec` instancesThayne McCombsbefore adoption0aee9b0

lines 456–458why, one step back
456 CommandSet::new_batch(vec![vec!["echo", "{.}"]], None).unwrap(),
457 CommandSet {458 commands: vec![CommandTemplate {

Fix clippy lintsThayne McCombsbefore adoptionf27332e

lines 459–462why, one step back
459 args: vec![
460 ArgumentTemplate::Text("echo".into()),461 ArgumentTemplate::Tokens(vec![Token::NoExt]),462 ],

Support multiple `--exec` instancesThayne McCombsbefore adoption0aee9b0

line 463why, one step back
463 }],

Add link to troubleshooting sectionsharkdpbefore adoption9412648

line 464why, one step back
464 mode: ExecutionMode::Batch,

use custom --path-separator in arguments to --execAllen Wildbefore adoption8a532e5

line 465why, one step back
465 path_separator: None,

Add link to troubleshooting sectionsharkdpbefore adoption9412648

lines 466–471why, one step back
466 }
467 );468 }469470 #[test]471 fn tokens_multiple_batch() {

Support multiple `--exec` instancesThayne McCombsbefore adoption0aee9b0

line 472why, one step back
472 assert!(CommandSet::new_batch(vec![vec!["echo", "{.}", "{}"]], None).is_err());

Error out if no args provided to --exec or --exec-batchThayne McCombsbefore adoptionc577b08

lines 473–482why, one step back
473 }
474475 #[test]476 fn template_no_args() {477 assert!(CommandTemplate::new::<Vec<_>, &'static str>(vec![]).is_err());478 }479480 #[test]481 fn command_set_no_args() {482 assert!(CommandSet::new(vec![vec!["echo"], vec![]], None).is_err());

use custom --path-separator in arguments to --execAllen Wildbefore adoption8a532e5

lines 483–516why, one step back
483 }
484485 #[test]486 fn generate_custom_path_separator() {487 let arg = ArgumentTemplate::Tokens(vec![Token::Placeholder]);488 macro_rules! check {489 ($input:expr, $expected:expr) => {490 assert_eq!(arg.generate($input, Some("#")), OsString::from($expected));491 };492 }493494 check!("foo", "foo");495 check!("foo/bar", "foo#bar");496 check!("/foo/bar/baz", "#foo#bar#baz");497 }498499 #[cfg(windows)]500 #[test]501 fn generate_custom_path_separator_windows() {502 let arg = ArgumentTemplate::Tokens(vec![Token::Placeholder]);503 macro_rules! check {504 ($input:expr, $expected:expr) => {505 assert_eq!(arg.generate($input, Some("#")), OsString::from($expected));506 };507 }508509 // path starting with a drive letter510 check!(r"C:\foo\bar", "C:#foo#bar");511 // UNC path512 check!(r"\\server\share\path", "##server#share#path");513 // Drive Relative path - no separator after the colon omits the RootDir path component.514 // This is uncommon, but valid515 check!(r"C:foo\bar", "C:foo#bar");516

fix spellinga1346054before adoption5b4869a

line 517why, one step back
517 // forward slashes should get normalized and interpreted as separators

use custom --path-separator in arguments to --execAllen Wildbefore adoption8a532e5

lines 518–520why, one step back
518 check!("C:/foo/bar", "C:#foo#bar");
519 check!("C:foo/bar", "C:foo#bar");520

fix spellinga1346054before adoption5b4869a

line 521why, one step back
521 // Rust does not interpret "//server/share" as a UNC path, but rather as a normal

use custom --path-separator in arguments to --execAllen Wildbefore adoption8a532e5

lines 522–524why, one step back
522 // absolute path that begins with RootDir, and the two slashes get combined together as
523 // a single path separator during normalization.524 //check!("//server/share/path", "##server#share#path");

Add link to troubleshooting sectionsharkdpbefore adoption9412648

lines 525–526why, one step back
525 }
526}