Skip to content
Myr

cli.rs

This file

Path

src/cli.rs

861 lines · 30.2 KiB · Rust

Last changed by

Merge pull request #1283 from tmccombs/new-rust-versionTavian Barnesbefore adoptione4bca10

History of this file

Take it

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 1–21why, one step back
1use std::path::{Path, PathBuf};
2use std::time::Duration;34use anyhow::anyhow;5use clap::{6 error::ErrorKind, value_parser, Arg, ArgAction, ArgGroup, ArgMatches, Command, Parser,7 ValueEnum,8};9#[cfg(feature = "completions")]10use clap_complete::Shell;11use normpath::PathExt;1213use crate::error::print_error;14use crate::exec::CommandSet;15use crate::filesystem;16#[cfg(unix)]17use crate::filter::OwnerFilter;18use crate::filter::SizeFilter;1920#[derive(Parser)]21#[command(

Change clap CLI binary name to 'fd'David Peterbefore adoptionac35b11

line 22why, one step back
22 name = "fd",

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

line 23why, one step back
23 version,

Add simple 'about' textDavid Peterbefore adoption7f5bc98

line 24why, one step back
24 about = "A program to find entries in your filesystem",

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

line 25why, one step back
25 after_long_help = "Bugs can be reported on GitHub: https://github.com/sharkdp/fd/issues",

Set max. term width to make help texts easier to readDavid Peterbefore adoption70c4865

line 26why, one step back
26 max_term_width = 98,

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 27–31why, one step back
27 args_override_self = true,
28 group(ArgGroup::new("execs").args(&["exec", "exec_batch", "list_details"]).conflicts_with_all(&[29 "max_results", "has_results", "count"])),30)]31pub struct Opts {

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 32–35why, one step back
32 /// Include hidden directories and files in the search results (default:
33 /// hidden files and directories are skipped). Files and directories are34 /// considered to be hidden if their name starts with a `.` sign (dot).35 /// The flag can be overridden with --no-hidden.

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 36–38why, one step back
36 #[arg(
37 long,38 short = 'H',

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 39–40why, one step back
39 help = "Search hidden files and directories",
40 long_help

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 41–43why, one step back
41 )]
42 pub hidden: bool,43

Merge pull request #1170 from tmccombs/clap-improvements-2Thayne McCombsbefore adoption85e3ada

lines 44–47why, one step back
44 /// Overrides --hidden
45 #[arg(long, overrides_with = "hidden", hide = true, action = ArgAction::SetTrue)]46 no_hidden: (),47

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 48–50why, one step back
48 /// Show search results from files and directories that would otherwise be
49 /// ignored by '.gitignore', '.ignore', '.fdignore', or the global ignore file.50 /// The flag can be overridden with --ignore.

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 51–53why, one step back
51 #[arg(
52 long,53 short = 'I',

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 54–55why, one step back
54 help = "Do not respect .(git|fd)ignore files",
55 long_help

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 56–58why, one step back
56 )]
57 pub no_ignore: bool,58

Merge pull request #1170 from tmccombs/clap-improvements-2Thayne McCombsbefore adoption85e3ada

lines 59–62why, one step back
59 /// Overrides --no-ignore
60 #[arg(long, overrides_with = "no_ignore", hide = true, action = ArgAction::SetTrue)]61 ignore: (),62

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 63–64why, one step back
63 ///Show search results from files and directories that would otherwise be
64 /// ignored by '.gitignore' files. The flag can be overridden with --ignore-vcs.

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 65–67why, one step back
65 #[arg(
66 long,67 hide_short_help = true,

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 68–69why, one step back
68 help = "Do not respect .gitignore files",
69 long_help

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 70–72why, one step back
70 )]
71 pub no_ignore_vcs: bool,72

Merge pull request #1170 from tmccombs/clap-improvements-2Thayne McCombsbefore adoption85e3ada

lines 73–76why, one step back
73 /// Overrides --no-ignore-vcs
74 #[arg(long, overrides_with = "no_ignore_vcs", hide = true, action = ArgAction::SetTrue)]75 ignore_vcs: (),76

Merge pull request #1216 from vegerot/pr1216David Peterbefore adoptionaf9daff

lines 77–98why, one step back
77 /// Do not require a git repository to respect gitignores.
78 /// By default, fd will only respect global gitignore rules, .gitignore rules,79 /// and local exclude rules if fd detects that you are searching inside a80 /// git repository. This flag allows you to relax this restriction such that81 /// fd will respect all git related ignore rules regardless of whether you're82 /// searching in a git repository or not.83 ///84 ///85 /// This flag can be disabled with --require-git.86 #[arg(87 long,88 overrides_with = "require_git",89 hide_short_help = true,90 // same description as ripgrep's flag: ripgrep/crates/core/app.rs91 long_help92 )]93 pub no_require_git: bool,9495 /// Overrides --no-require-git96 #[arg(long, overrides_with = "no_require_git", hide = true, action = ArgAction::SetTrue)]97 require_git: (),98

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 99–100why, one step back
99 /// Show search results from files and directories that would otherwise be
100 /// ignored by '.gitignore', '.ignore', or '.fdignore' files in parent directories.

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 101–103why, one step back
101 #[arg(
102 long,103 hide_short_help = true,

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 104–105why, one step back
104 help = "Do not respect .(git|fd)ignore files in parent directories",
105 long_help

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 106–112why, one step back
106 )]
107 pub no_ignore_parent: bool,108109 /// Do not respect the global ignore file110 #[arg(long, hide = true)]111 pub no_global_ignore_file: bool,112

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 113–114why, one step back
113 /// Perform an unrestricted search, including ignored and hidden files. This is
114 /// an alias for '--no-ignore --hidden'.

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

line 115why, one step back
115 #[arg(long = "unrestricted", short = 'u', overrides_with_all(&["ignore", "no_hidden"]), action(ArgAction::Count), hide_short_help = true,

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 116–117why, one step back
116 help = "Unrestricted search, alias for '--no-ignore --hidden'",
117 long_help,

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 118–131why, one step back
118 )]
119 rg_alias_hidden_ignore: u8,120121 /// Case-sensitive search (default: smart case)122 #[arg(123 long,124 short = 's',125 overrides_with("ignore_case"),126 long_help = "Perform a case-sensitive search. By default, fd uses case-insensitive \127 searches, unless the pattern contains an uppercase character (smart \128 case)."129 )]130 pub case_sensitive: bool,131

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 132–134why, one step back
132 /// Perform a case-insensitive search. By default, fd uses case-insensitive
133 /// searches, unless the pattern contains an uppercase character (smart134 /// case).

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 135–138why, one step back
135 #[arg(
136 long,137 short = 'i',138 overrides_with("case_sensitive"),

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 139–140why, one step back
139 help = "Case-insensitive search (default: smart case)",
140 long_help

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 141–143why, one step back
141 )]
142 pub ignore_case: bool,143

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

line 144why, one step back
144 /// Perform a glob-based search instead of a regular expression search.

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 145–148why, one step back
145 #[arg(
146 long,147 short = 'g',148 conflicts_with("fixed_strings"),

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 149–150why, one step back
149 help = "Glob-based search (default: regular expression)",
150 long_help

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 151–153why, one step back
151 )]
152 pub glob: bool,153

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 154–155why, one step back
154 /// Perform a regular-expression based search (default). This can be used to
155 /// override --glob.

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 156–159why, one step back
156 #[arg(
157 long,158 overrides_with("glob"),159 hide_short_help = true,

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 160–161why, one step back
160 help = "Regular-expression based search (default)",
161 long_help

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 162–164why, one step back
162 )]
163 pub regex: bool,164

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 165–167why, one step back
165 /// Treat the pattern as a literal string instead of a regular expression. Note
166 /// that this also performs substring comparison. If you want to match on an167 /// exact filename, consider using '--glob'.

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 168–172why, one step back
168 #[arg(
169 long,170 short = 'F',171 alias = "literal",172 hide_short_help = true,

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 173–174why, one step back
173 help = "Treat pattern as literal string stead of regex",
174 long_help

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 175–177why, one step back
175 )]
176 pub fixed_strings: bool,177

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 178–180why, one step back
178 /// Add additional required search patterns, all of which must be matched. Multiple
179 /// additional patterns can be specified. The patterns are regular180 /// expressions, unless '--glob' or '--fixed-strings' is used.

Merge pull request #1139 from Uthar/masterDavid Peterbefore adoptionc9d3968

lines 181–183why, one step back
181 #[arg(
182 long = "and",183 value_name = "pattern",

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 184–185why, one step back
184 help = "Additional search patterns that need to be matched",
185 long_help,

Merge pull request #1139 from Uthar/masterDavid Peterbefore adoptionc9d3968

lines 186–190why, one step back
186 hide_short_help = true,
187 allow_hyphen_values = true188 )]189 pub exprs: Option<Vec<String>>,190

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 191–192why, one step back
191 /// Shows the full path starting from the root as opposed to relative paths.
192 /// The flag can be overridden with --relative-path.

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 193–195why, one step back
193 #[arg(
194 long,195 short = 'a',

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 196–197why, one step back
196 help = "Show absolute instead of relative paths",
197 long_help

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 198–200why, one step back
198 )]
199 pub absolute_path: bool,200

Merge pull request #1170 from tmccombs/clap-improvements-2Thayne McCombsbefore adoption85e3ada

lines 201–204why, one step back
201 /// Overrides --absolute-path
202 #[arg(long, overrides_with = "absolute_path", hide = true, action = ArgAction::SetTrue)]203 relative_path: (),204

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 205–208why, one step back
205 /// Use a detailed listing format like 'ls -l'. This is basically an alias
206 /// for '--exec-batch ls -l' with some additional 'ls' options. This can be207 /// used to see more metadata, to show symlink targets and to achieve a208 /// deterministic sort order.

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 209–212why, one step back
209 #[arg(
210 long,211 short = 'l',212 conflicts_with("absolute_path"),

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 213–214why, one step back
213 help = "Use a long listing format with file metadata",
214 long_help

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 215–228why, one step back
215 )]
216 pub list_details: bool,217218 /// Follow symbolic links219 #[arg(220 long,221 short = 'L',222 alias = "dereference",223 long_help = "By default, fd does not descend into symlinked directories. Using this \224 flag, symbolic links are also traversed. \225 Flag can be overriden with --no-follow."226 )]227 pub follow: bool,228

Merge pull request #1170 from tmccombs/clap-improvements-2Thayne McCombsbefore adoption85e3ada

lines 229–232why, one step back
229 /// Overrides --follow
230 #[arg(long, overrides_with = "follow", hide = true, action = ArgAction::SetTrue)]231 no_follow: (),232

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 233–234why, one step back
233 /// By default, the search pattern is only matched against the filename (or directory name). Using this flag, the pattern is matched against the full (absolute) path. Example:
234 /// fd --glob -p '**/.git/config'

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 235–237why, one step back
235 #[arg(
236 long,237 short = 'p',

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 238–240why, one step back
238 help = "Search full abs. path (default: filename only)",
239 long_help,240 verbatim_doc_comment

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 241–243why, one step back
241 )]
242 pub full_path: bool,243

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 244–245why, one step back
244 /// Separate search results by the null character (instead of newlines).
245 /// Useful for piping results to 'xargs'.

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 246–250why, one step back
246 #[arg(
247 long = "print0",248 short = '0',249 conflicts_with("list_details"),250 hide_short_help = true,

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 251–252why, one step back
251 help = "Separate search results by the null character",
252 long_help

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 253–255why, one step back
253 )]
254 pub null_separator: bool,255

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 256–257why, one step back
256 /// Limit the directory traversal to a given depth. By default, there is no
257 /// limit on the search depth.

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 258–262why, one step back
258 #[arg(
259 long,260 short = 'd',261 value_name = "depth",262 alias("maxdepth"),

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 263–264why, one step back
263 help = "Set maximum search depth (default: none)",
264 long_help

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 265–268why, one step back
265 )]
266 max_depth: Option<usize>,267268 /// Only show search results starting at the given depth.

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

line 269why, one step back
269 /// See also: '--max-depth' and '--exact-depth'

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 270–273why, one step back
270 #[arg(
271 long,272 value_name = "depth",273 hide_short_help = true,

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 274–275why, one step back
274 help = "Only show search results starting at the given depth.",
275 long_help

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 276–278why, one step back
276 )]
277 min_depth: Option<usize>,278

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 279–280why, one step back
279 /// Only show search results at the exact given depth. This is an alias for
280 /// '--min-depth <depth> --max-depth <depth>'.

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

line 281why, one step back
281 #[arg(long, value_name = "depth", hide_short_help = true, conflicts_with_all(&["max_depth", "min_depth"]),

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 282–283why, one step back
282 help = "Only show search results at the exact given depth",
283 long_help,

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 284–286why, one step back
284 )]
285 exact_depth: Option<usize>,286

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 287–293why, one step back
287 /// Exclude files/directories that match the given glob pattern. This
288 /// overrides any other ignore logic. Multiple exclude patterns can be289 /// specified.290 ///291 /// Examples:292 /// {n} --exclude '*.pyc'293 /// {n} --exclude node_modules

Reorder command line optionsDavid Peterbefore adoption12165c7

lines 294–297why, one step back
294 #[arg(
295 long,296 short = 'E',297 value_name = "pattern",

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 298–299why, one step back
298 help = "Exclude entries that match the given glob pattern",
299 long_help

Reorder command line optionsDavid Peterbefore adoption12165c7

lines 300–302why, one step back
300 )]
301 pub exclude: Vec<String>,302

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 303–305why, one step back
303 /// Do not traverse into directories that match the search criteria. If
304 /// you want to exclude specific directories, use the '--exclude=…' option.305 #[arg(long, hide_short_help = true, conflicts_with_all(&["size", "exact_depth"]),

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

line 306why, one step back
306 long_help,

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 307–309why, one step back
307 )]
308 pub prune: bool,309

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 310–341why, one step back
310 /// Filter the search by type:
311 /// {n} 'f' or 'file': regular files312 /// {n} 'd' or 'directory': directories313 /// {n} 'l' or 'symlink': symbolic links314 /// {n} 's' or 'socket': socket315 /// {n} 'p' or 'pipe': named pipe (FIFO)316 /// {n}{n} 'x' or 'executable': executables317 /// {n} 'e' or 'empty': empty files or directories318 ///319 /// This option can be specified more than once to include multiple file types.320 /// Searching for '--type file --type symlink' will show both regular files as321 /// well as symlinks. Note that the 'executable' and 'empty' filters work differently:322 /// '--type executable' implies '--type file' by default. And '--type empty' searches323 /// for empty files and directories, unless either '--type file' or '--type directory'324 /// is specified in addition.325 ///326 /// Examples:327 /// {n} - Only search for files:328 /// {n} fd --type file …329 /// {n} fd -tf …330 /// {n} - Find both files and symlinks331 /// {n} fd --type file --type symlink …332 /// {n} fd -tf -tl …333 /// {n} - Find executable files:334 /// {n} fd --type executable335 /// {n} fd -tx336 /// {n} - Find empty files:337 /// {n} fd --type empty --type file338 /// {n} fd -te -tf339 /// {n} - Find empty directories:340 /// {n} fd --type empty --type directory341 /// {n} fd -te -td

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 342–347why, one step back
342 #[arg(
343 long = "type",344 short = 't',345 value_name = "filetype",346 hide_possible_values = true,347 value_enum,

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 348–350why, one step back
348 help = "Filter by type: file (f), directory (d), symlink (l), \
349 executable (x), empty (e), socket (s), pipe (p)",350 long_help

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 351–353why, one step back
351 )]
352 pub filetype: Option<Vec<FileType>>,353

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 354–358why, one step back
354 /// (Additionally) filter search results by their file extension. Multiple
355 /// allowable file extensions can be specified.356 ///357 /// If you want to search for files without extension,358 /// you can use the regex '^[^.]+$' as a normal search pattern.

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 359–362why, one step back
359 #[arg(
360 long = "extension",361 short = 'e',362 value_name = "ext",

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 363–364why, one step back
363 help = "Filter by file extension",
364 long_help

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 365–367why, one step back
365 )]
366 pub extensions: Option<Vec<String>>,367

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 368–384why, one step back
368 /// Limit results based on the size of files using the format <+-><NUM><UNIT>.
369 /// '+': file size must be greater than or equal to this370 /// '-': file size must be less than or equal to this371 ///372 /// If neither '+' nor '-' is specified, file size must be exactly equal to this.373 /// 'NUM': The numeric size (e.g. 500)374 /// 'UNIT': The units for NUM. They are not case-sensitive.375 /// Allowed unit values:376 /// 'b': bytes377 /// 'k': kilobytes (base ten, 10^3 = 1000 bytes)378 /// 'm': megabytes379 /// 'g': gigabytes380 /// 't': terabytes381 /// 'ki': kibibytes (base two, 2^10 = 1024 bytes)382 /// 'mi': mebibytes383 /// 'gi': gibibytes384 /// 'ti': tebibytes

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

line 385why, one step back
385 #[arg(long, short = 'S', value_parser = SizeFilter::from_string, allow_hyphen_values = true, verbatim_doc_comment, value_name = "size",

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 386–388why, one step back
386 help = "Limit results based on the size of files",
387 long_help,388 verbatim_doc_comment,

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 389–391why, one step back
389 )]
390 pub size: Vec<SizeFilter>,391

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 392–402why, one step back
392 /// Filter results based on the file modification time. Files with modification times
393 /// greater than the argument are returned. The argument can be provided394 /// as a specific point in time (YYYY-MM-DD HH:MM:SS) or as a duration (10h, 1d, 35min).395 /// If the time is not specified, it defaults to 00:00:00.396 /// '--change-newer-than', '--newer', or '--changed-after' can be used as aliases.397 ///398 /// Examples:399 /// {n} --changed-within 2weeks400 /// {n} --change-newer-than '2018-10-27 10:00:00'401 /// {n} --newer 2018-10-27402 /// {n} --changed-after 1day

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 403–406why, one step back
403 #[arg(
404 long,405 alias("change-newer-than"),406 alias("newer"),

Merge pull request #1176 from tmccombs/changed-afterDavid Peterbefore adoption8dda499

line 407why, one step back
407 alias("changed-after"),

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

line 408why, one step back
408 value_name = "date|dur",

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 409–410why, one step back
409 help = "Filter by file modification time (newer than)",
410 long_help

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 411–413why, one step back
411 )]
412 pub changed_within: Option<String>,413

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 414–422why, one step back
414 /// Filter results based on the file modification time. Files with modification times
415 /// less than the argument are returned. The argument can be provided416 /// as a specific point in time (YYYY-MM-DD HH:MM:SS) or as a duration (10h, 1d, 35min).417 /// '--change-older-than' or '--older' can be used as aliases.418 ///419 /// Examples:420 /// {n} --changed-before '2018-10-27 10:00:00'421 /// {n} --change-older-than 2weeks422 /// {n} --older 2018-10-27

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 423–427why, one step back
423 #[arg(
424 long,425 alias("change-older-than"),426 alias("older"),427 value_name = "date|dur",

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 428–429why, one step back
428 help = "Filter by file modification time (older than)",
429 long_help

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 430–432why, one step back
430 )]
431 pub changed_before: Option<String>,432

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 433–440why, one step back
433 /// Filter files by their user and/or group.
434 /// Format: [(user|uid)][:(group|gid)]. Either side is optional.435 /// Precede either side with a '!' to exclude files instead.436 ///437 /// Examples:438 /// {n} --owner john439 /// {n} --owner :students440 /// {n} --owner '!john:students'

Reorder command line optionsDavid Peterbefore adoption12165c7

lines 441–442why, one step back
441 #[cfg(unix)]
442 #[arg(long, short = 'o', value_parser = OwnerFilter::from_string, value_name = "user:group",

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 443–444why, one step back
443 help = "Filter by owning user and/or group",
444 long_help,

Reorder command line optionsDavid Peterbefore adoption12165c7

lines 445–450why, one step back
445 )]
446 pub owner: Option<OwnerFilter>,447448 #[command(flatten)]449 pub exec: Exec,450

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 451–456why, one step back
451 /// Maximum number of arguments to pass to the command given with -X.
452 /// If the number of results is greater than the given size,453 /// the command given with -X is run again with remaining arguments.454 /// A batch size of zero means there is no limit (default), but note455 /// that batching might still happen due to OS restrictions on the456 /// maximum length of command lines.

Reorder command line optionsDavid Peterbefore adoption12165c7

lines 457–463why, one step back
457 #[arg(
458 long,459 value_name = "size",460 hide_short_help = true,461 requires("exec_batch"),462 value_parser = value_parser!(usize),463 default_value_t,

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 464–465why, one step back
464 help = "Max number of arguments to run as a batch size with -X",
465 long_help,

Reorder command line optionsDavid Peterbefore adoption12165c7

lines 466–468why, one step back
466 )]
467 pub batch_size: usize,468

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

line 469why, one step back
469 /// Add a custom ignore-file in '.gitignore' format. These files have a low precedence.

Reorder command line optionsDavid Peterbefore adoption12165c7

lines 470–473why, one step back
470 #[arg(
471 long,472 value_name = "path",473 hide_short_help = true,

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 474–475why, one step back
474 help = "Add a custom ignore-file in '.gitignore' format",
475 long_help

Reorder command line optionsDavid Peterbefore adoption12165c7

lines 476–478why, one step back
476 )]
477 pub ignore_file: Vec<PathBuf>,478

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

line 479why, one step back
479 /// Declare when to use color for the pattern match output

Reorder command line optionsDavid Peterbefore adoption12165c7

lines 480–485why, one step back
480 #[arg(
481 long,482 short = 'c',483 value_enum,484 default_value_t = ColorWhen::Auto,485 value_name = "when",

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 486–487why, one step back
486 help = "When to use colors",
487 long_help,

Reorder command line optionsDavid Peterbefore adoption12165c7

lines 488–492why, one step back
488 )]
489 pub color: ColorWhen,490491 /// Set number of threads to use for searching & executing (default: number492 /// of available CPU cores)

Merge pull request #1162 from sharkdp/fix-threads-optionDavid Peterbefore adoption0a7b51a

line 493why, one step back
493 #[arg(long, short = 'j', value_name = "num", hide_short_help = true, value_parser = clap::value_parser!(u32).range(1..))]

Reorder command line optionsDavid Peterbefore adoption12165c7

lines 494–502why, one step back
494 pub threads: Option<u32>,
495496 /// Milliseconds to buffer before streaming search results to console497 ///498 /// Amount of time in milliseconds to buffer, before streaming the search499 /// results to the console.500 #[arg(long, hide = true, value_parser = parse_millis)]501 pub max_buffer_time: Option<Duration>,502

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

line 503why, one step back
503 ///Limit the number of search results to 'count' and quit immediately.

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 504–507why, one step back
504 #[arg(
505 long,506 value_name = "count",507 hide_short_help = true,

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 508–509why, one step back
508 help = "Limit the number of search results",
509 long_help

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 510–512why, one step back
510 )]
511 max_results: Option<usize>,512

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 513–514why, one step back
513 /// Limit the search to a single result and quit immediately.
514 /// This is an alias for '--max-results=1'.

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 515–518why, one step back
515 #[arg(
516 short = '1',517 hide_short_help = true,518 overrides_with("max_results"),

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 519–520why, one step back
519 help = "Limit search to a single result",
520 long_help

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 521–523why, one step back
521 )]
522 max_one_result: bool,523

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 524–527why, one step back
524 /// When the flag is present, the program does not print anything and will
525 /// return with an exit code of 0 if there is at least one match. Otherwise, the526 /// exit code will be 1.527 /// '--has-results' can be used as an alias.

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 528–533why, one step back
528 #[arg(
529 long,530 short = 'q',531 alias = "has-results",532 hide_short_help = true,533 conflicts_with("max_results"),

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 534–535why, one step back
534 help = "Print nothing, exit code 0 if match found, 1 otherwise",
535 long_help

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 536–538why, one step back
536 )]
537 pub quiet: bool,538

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 539–540why, one step back
539 /// Enable the display of filesystem errors for situations such as
540 /// insufficient permissions or dead symlinks.

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 541–543why, one step back
541 #[arg(
542 long,543 hide_short_help = true,

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 544–545why, one step back
544 help = "Show filesystem errors",
545 long_help

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 546–548why, one step back
546 )]
547 pub show_errors: bool,548

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 549–553why, one step back
549 /// Change the current working directory of fd to the provided path. This
550 /// means that search results will be shown with respect to the given base551 /// path. Note that relative paths which are passed to fd via the positional552 /// <path> argument or the '--search-path' option will also be resolved553 /// relative to this directory.

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 554–557why, one step back
554 #[arg(
555 long,556 value_name = "path",557 hide_short_help = true,

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 558–559why, one step back
558 help = "Change current working directory",
559 long_help

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 560–562why, one step back
560 )]
561 pub base_directory: Option<PathBuf>,562

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 563–566why, one step back
563 /// the search pattern which is either a regular expression (default) or a glob
564 /// pattern (if --glob is used). If no pattern has been specified, every entry565 /// is considered a match. If your pattern starts with a dash (-), make sure to566 /// pass '--' first, or it will be considered as a flag (fd -- '-foo').

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 567–570why, one step back
567 #[arg(
568 default_value = "",569 hide_default_value = true,570 value_name = "pattern",

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 571–572why, one step back
571 help = "the search pattern (a regular expression, unless '--glob' is used; optional)",
572 long_help

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 573–575why, one step back
573 )]
574 pub pattern: String,575

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 576–577why, one step back
576 /// Set the path separator to use when printing file paths. The default is
577 /// the OS-specific separator ('/' on Unix, '\' on Windows).

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 578–581why, one step back
578 #[arg(
579 long,580 value_name = "separator",581 hide_short_help = true,

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 582–583why, one step back
582 help = "Set path separator when printing file paths",
583 long_help

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 584–586why, one step back
584 )]
585 pub path_separator: Option<String>,586

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 587–588why, one step back
587 /// The directory where the filesystem search is rooted (optional). If
588 /// omitted, search the current working directory.

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 589–590why, one step back
589 #[arg(action = ArgAction::Append,
590 value_name = "path",

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 591–592why, one step back
591 help = "the root directories for the filesystem search (optional)",
592 long_help,

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 593–595why, one step back
593 )]
594 path: Vec<PathBuf>,595

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 596–598why, one step back
596 /// Provide paths to search as an alternative to the positional <path>
597 /// argument. Changes the usage to `fd [OPTIONS] --search-path <path>598 /// --search-path <path2> [<pattern>]`

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 599–603why, one step back
599 #[arg(
600 long,601 conflicts_with("path"),602 value_name = "search-path",603 hide_short_help = true,

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 604–605why, one step back
604 help = "Provides paths to search as an alternative to the positional <path> argument",
605 long_help

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 606–612why, one step back
606 )]
607 search_path: Vec<PathBuf>,608609 /// By default, relative paths are prefixed with './' when -x/--exec,610 /// -X/--exec-batch, or -0/--print0 are given, to reduce the risk of a611 /// path starting with '-' being treated as a command line option. Use612 /// this flag to disable this behaviour.

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

line 613why, one step back
613 #[arg(long, conflicts_with_all(&["path", "search_path"]), hide_short_help = true, long_help)]

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 614–615why, one step back
614 pub strip_cwd_prefix: bool,
615

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 616–619why, one step back
616 /// By default, fd will traverse the file system tree as far as other options
617 /// dictate. With this flag, fd ensures that it does not descend into a618 /// different file system than the one it started in. Comparable to the -mount619 /// or -xdev filters of find(1).

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

line 620why, one step back
620 #[cfg(any(unix, windows))]

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

line 621why, one step back
621 #[arg(long, aliases(&["mount", "xdev"]), hide_short_help = true, long_help)]

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 622–697why, one step back
622 pub one_file_system: bool,
623624 #[cfg(feature = "completions")]625 #[arg(long, hide = true, exclusive = true)]626 gen_completions: Option<Option<Shell>>,627}628629impl Opts {630 pub fn search_paths(&self) -> anyhow::Result<Vec<PathBuf>> {631 // would it make sense to concatenate these?632 let paths = if !self.path.is_empty() {633 &self.path634 } else if !self.search_path.is_empty() {635 &self.search_path636 } else {637 let current_directory = Path::new(".");638 ensure_current_directory_exists(current_directory)?;639 return Ok(vec![self.normalize_path(current_directory)]);640 };641 Ok(paths642 .iter()643 .filter_map(|path| {644 if filesystem::is_existing_directory(path) {645 Some(self.normalize_path(path))646 } else {647 print_error(format!(648 "Search path '{}' is not a directory.",649 path.to_string_lossy()650 ));651 None652 }653 })654 .collect())655 }656657 fn normalize_path(&self, path: &Path) -> PathBuf {658 if self.absolute_path {659 filesystem::absolute_path(path.normalize().unwrap().as_path()).unwrap()660 } else {661 path.to_path_buf()662 }663 }664665 pub fn no_search_paths(&self) -> bool {666 self.path.is_empty() && self.search_path.is_empty()667 }668669 #[inline]670 pub fn rg_alias_ignore(&self) -> bool {671 self.rg_alias_hidden_ignore > 0672 }673674 pub fn max_depth(&self) -> Option<usize> {675 self.max_depth.or(self.exact_depth)676 }677678 pub fn min_depth(&self) -> Option<usize> {679 self.min_depth.or(self.exact_depth)680 }681682 pub fn threads(&self) -> usize {683 // This will panic if the number of threads passed in is more than usize::MAX in an environment684 // where usize is less than 32 bits (for example 16-bit architectures). It's pretty685 // unlikely fd will be running in such an environment, and even more unlikely someone would686 // be trying to use that many threads on such an environment, so I think panicing is an687 // appropriate way to handle that.688 std::cmp::max(689 self.threads690 .map_or_else(num_cpus::get, |n| n.try_into().expect("too many threads")),691 1,692 )693 }694695 pub fn max_results(&self) -> Option<usize> {696 self.max_results697 .filter(|&m| m > 0)

Merge pull request #1283 from tmccombs/new-rust-versionTavian Barnesbefore adoptione4bca10

line 698why, one step back
698 .or_else(|| self.max_one_result.then_some(1))

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 699–705why, one step back
699 }
700701 #[cfg(feature = "completions")]702 pub fn gen_completions(&self) -> anyhow::Result<Option<Shell>> {703 self.gen_completions704 .map(|maybe_shell| match maybe_shell {705 Some(sh) => Ok(sh),

Merge pull request #1170 from tmccombs/clap-improvements-2Thayne McCombsbefore adoption85e3ada

lines 706–708why, one step back
706 None => {
707 Shell::from_env().ok_or_else(|| anyhow!("Unable to get shell from environment"))708 }

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 709–721why, one step back
709 })
710 .transpose()711 }712}713714#[derive(Copy, Clone, PartialEq, Eq, ValueEnum)]715pub enum FileType {716 #[value(alias = "f")]717 File,718 #[value(alias = "d")]719 Directory,720 #[value(alias = "l")]721 Symlink,

Merge pull request #1169 from Ptipiak/mention-executable-detectionDavid Peterbefore adoption38cdeb0

line 722why, one step back
722 /// A file which is executable by the current effective user

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 723–762why, one step back
723 #[value(alias = "x")]
724 Executable,725 #[value(alias = "e")]726 Empty,727 #[value(alias = "s")]728 Socket,729 #[value(alias = "p")]730 Pipe,731}732733#[derive(Copy, Clone, PartialEq, Eq, Debug, ValueEnum)]734pub enum ColorWhen {735 /// show colors if the output goes to an interactive console (default)736 Auto,737 /// always use colorized output738 Always,739 /// do not use colorized output740 Never,741}742743impl ColorWhen {744 pub fn as_str(&self) -> &'static str {745 use ColorWhen::*;746 match *self {747 Auto => "auto",748 Never => "never",749 Always => "always",750 }751 }752}753754// there isn't a derive api for getting grouped values yet,755// so we have to use hand-rolled parsing for exec and exec-batch756pub struct Exec {757 pub command: Option<CommandSet>,758}759760impl clap::FromArgMatches for Exec {761 fn from_arg_matches(matches: &ArgMatches) -> clap::error::Result<Self> {762 let command = matches

Merge pull request #1244 from tmccombs/grouped-occurrencesDavid Peterbefore adoption73a693e

line 763why, one step back
763 .get_occurrences::<String>("exec")

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 764–766why, one step back
764 .map(CommandSet::new)
765 .or_else(|| {766 matches

Merge pull request #1244 from tmccombs/grouped-occurrencesDavid Peterbefore adoption73a693e

line 767why, one step back
767 .get_occurrences::<String>("exec_batch")

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 768–822why, one step back
768 .map(CommandSet::new_batch)
769 })770 .transpose()771 .map_err(|e| clap::Error::raw(ErrorKind::InvalidValue, e))?;772 Ok(Exec { command })773 }774775 fn update_from_arg_matches(&mut self, matches: &ArgMatches) -> clap::error::Result<()> {776 *self = Self::from_arg_matches(matches)?;777 Ok(())778 }779}780781impl clap::Args for Exec {782 fn augment_args(cmd: Command) -> Command {783 cmd.arg(Arg::new("exec")784 .action(ArgAction::Append)785 .long("exec")786 .short('x')787 .num_args(1..)788 .allow_hyphen_values(true)789 .value_terminator(";")790 .value_name("cmd")791 .conflicts_with("list_details")792 .help("Execute a command for each search result")793 .long_help(794 "Execute a command for each search result in parallel (use --threads=1 for sequential command execution). \795 All positional arguments following --exec are considered to be arguments to the command - not to fd. \796 It is therefore recommended to place the '-x'/'--exec' option last.\n\797 The following placeholders are substituted before the command is executed:\n \798 '{}': path (of the current search result)\n \799 '{/}': basename\n \800 '{//}': parent directory\n \801 '{.}': path without file extension\n \802 '{/.}': basename without file extension\n\n\803 If no placeholder is present, an implicit \"{}\" at the end is assumed.\n\n\804 Examples:\n\n \805 - find all *.zip files and unzip them:\n\n \806 fd -e zip -x unzip\n\n \807 - find *.h and *.cpp files and run \"clang-format -i ..\" for each of them:\n\n \808 fd -e h -e cpp -x clang-format -i\n\n \809 - Convert all *.jpg files to *.png files:\n\n \810 fd -e jpg -x convert {} {.}.png\811 ",812 ),813 )814 .arg(815 Arg::new("exec_batch")816 .action(ArgAction::Append)817 .long("exec-batch")818 .short('X')819 .num_args(1..)820 .allow_hyphen_values(true)821 .value_terminator(";")822 .value_name("cmd")

Merge pull request #1168 from tmccombs/clippy-fixes-2Thayne McCombsbefore adoption9e88f91

line 823why, one step back
823 .conflicts_with_all(["exec", "list_details"])

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 824–861why, one step back
824 .help("Execute a command with all search results at once")
825 .long_help(826 "Execute the given command once, with all search results as arguments.\n\827 One of the following placeholders is substituted before the command is executed:\n \828 '{}': path (of all search results)\n \829 '{/}': basename\n \830 '{//}': parent directory\n \831 '{.}': path without file extension\n \832 '{/.}': basename without file extension\n\n\833 If no placeholder is present, an implicit \"{}\" at the end is assumed.\n\n\834 Examples:\n\n \835 - Find all test_*.py files and open them in your favorite editor:\n\n \836 fd -g 'test_*.py' -X vim\n\n \837 - Find all *.rs files and count the lines with \"wc -l ...\":\n\n \838 fd -e rs -X wc -l\839 "840 ),841 )842 }843844 fn augment_args_for_update(cmd: Command) -> Command {845 Self::augment_args(cmd)846 }847}848849fn parse_millis(arg: &str) -> Result<Duration, std::num::ParseIntError> {850 Ok(Duration::from_millis(arg.parse()?))851}852853fn ensure_current_directory_exists(current_directory: &Path) -> anyhow::Result<()> {854 if filesystem::is_existing_directory(current_directory) {855 Ok(())856 } else {857 Err(anyhow!(858 "Could not retrieve current directory (has it been deleted?)."859 ))860 }861}