Skip to content
Myr

app.rs

This file

Path

src/app.rs

546 lines · 22.8 KiB · Rust

Last changed by

Do not allow list-details in combination with -1sharkdpbefore adoption0335cc3

History of this file

Take it

1use clap::{crate_version, App, AppSettings, Arg};23pub fn build_app() -> App<'static, 'static> {4    let mut app = App::new("fd")5        .version(crate_version!())6        .usage("fd [FLAGS/OPTIONS] [<pattern>] [<path>...]")7        .setting(AppSettings::ColoredHelp)8        .setting(AppSettings::DeriveDisplayOrder)9        .after_help(10            "Note: `fd -h` prints a short and concise overview while `fd --help` gives all \11                 details.",12        )13        .arg(14            Arg::with_name("hidden")15                .long("hidden")16                .short("H")17                .overrides_with("hidden")18                .help("Search hidden files and directories")19                .long_help(20                    "Include hidden directories and files in the search results (default: \21                         hidden files and directories are skipped). Files and directories are \22                         considered to be hidden if their name starts with a `.` sign (dot).",23                ),24        )25        .arg(26            Arg::with_name("no-ignore")27                .long("no-ignore")28                .short("I")29                .overrides_with("no-ignore")30                .help("Do not respect .(git|fd)ignore files")31                .long_help(32                    "Show search results from files and directories that would otherwise be \33                         ignored by '.gitignore', '.ignore' or '.fdignore' files.",34                ),35        )36        .arg(37            Arg::with_name("no-ignore-vcs")38                .long("no-ignore-vcs")39                .overrides_with("no-ignore-vcs")40                .hidden_short_help(true)41                .long_help(42                    "Show search results from files and directories that would otherwise be \43                         ignored by '.gitignore' files.",44                ),45        )46        .arg(47            Arg::with_name("rg-alias-hidden-ignore")48                .short("u")49                .long("unrestricted")50                .multiple(true)51                .hidden_short_help(true)52                .long_help(53                    "Alias for '--no-ignore'. Can be repeated. '-uu' is an alias for \54                         '--no-ignore --hidden'.",55                ),56        )57        .arg(58            Arg::with_name("case-sensitive")59                .long("case-sensitive")60                .short("s")61                .overrides_with_all(&["ignore-case", "case-sensitive"])62                .help("Case-sensitive search (default: smart case)")63                .long_help(64                    "Perform a case-sensitive search. By default, fd uses case-insensitive \65                         searches, unless the pattern contains an uppercase character (smart \66                         case).",67                ),68        )69        .arg(70            Arg::with_name("ignore-case")71                .long("ignore-case")72                .short("i")73                .overrides_with_all(&["case-sensitive", "ignore-case"])74                .help("Case-insensitive search (default: smart case)")75                .long_help(76                    "Perform a case-insensitive search. By default, fd uses case-insensitive \77                         searches, unless the pattern contains an uppercase character (smart \78                         case).",79                ),80        )81        .arg(82            Arg::with_name("glob")83                .long("glob")84                .short("g")85                .conflicts_with("fixed-strings")86                .overrides_with("glob")87                .help("Glob-based search (default: regular expression)")88                .long_help("Perform a glob-based search instead of a regular expression search."),89        )90        .arg(91            Arg::with_name("regex")92                .long("regex")93                .overrides_with_all(&["glob", "regex"])94                .hidden_short_help(true)95                .long_help(96                    "Perform a regular-expression based search (default). This can be used to \97                         override --glob.",98                ),99        )100        .arg(101            Arg::with_name("fixed-strings")102                .long("fixed-strings")103                .short("F")104                .alias("literal")105                .overrides_with("fixed-strings")106                .hidden_short_help(true)107                .long_help(108                    "Treat the pattern as a literal string instead of a regular expression.",109                ),110        )111        .arg(112            Arg::with_name("absolute-path")113                .long("absolute-path")114                .short("a")115                .overrides_with("absolute-path")116                .help("Show absolute instead of relative paths")117                .long_help(118                    "Shows the full path starting from the root as opposed to relative paths.",119                ),120        )121        .arg(122            Arg::with_name("list-details")123                .long("list-details")124                .short("l")125                .conflicts_with("absolute-path")126                .help("Use a long listing format with file metadata")127                .long_help(128                    "Use a detailed listing format like 'ls -l'. This is basically an alias \129                         for '--exec-batch ls -l' with some additional 'ls' options. This can be \130                         used to see more metadata, to show symlink targets and to achieve a \131                         deterministic sort order.",132                ),133        )134        .arg(135            Arg::with_name("follow")136                .long("follow")137                .short("L")138                .alias("dereference")139                .overrides_with("follow")140                .help("Follow symbolic links")141                .long_help(142                    "By default, fd does not descend into symlinked directories. Using this \143                         flag, symbolic links are also traversed.",144                ),145        )146        .arg(147            Arg::with_name("full-path")148                .long("full-path")149                .short("p")150                .overrides_with("full-path")151                .help("Search full path (default: file-/dirname only)")152                .long_help(153                    "By default, the search pattern is only matched against the filename (or \154                         directory name). Using this flag, the pattern is matched against the \155                         full path.",156                ),157        )158        .arg(159            Arg::with_name("null_separator")160                .long("print0")161                .short("0")162                .overrides_with("print0")163                .conflicts_with("list-details")164                .help("Separate results by the null character")165                .long_help(166                    "Separate search results by the null character (instead of newlines). \167                         Useful for piping results to 'xargs'.",168                ),169        )170        .arg(171            Arg::with_name("max-depth")172                .long("max-depth")173                .short("d")174                .takes_value(true)175                .value_name("depth")176                .help("Set maximum search depth (default: none)")177                .long_help(178                    "Limit the directory traversal to a given depth. By default, there is no \179                         limit on the search depth.",180                ),181        )182        // support --maxdepth as well, for compatibility with rg183        .arg(184            Arg::with_name("rg-depth")185                .long("maxdepth")186                .hidden(true)187                .takes_value(true)188        )189        .arg(190            Arg::with_name("min-depth")191                .long("min-depth")192                .takes_value(true)193                .value_name("depth")194                .hidden_short_help(true)195                .long_help(196                    "Only show search results starting at the given depth. \197                     See also: '--max-depth' and '--exact-depth'",198                ),199        )200        .arg(201            Arg::with_name("exact-depth")202                .long("exact-depth")203                .takes_value(true)204                .value_name("depth")205                .hidden_short_help(true)206                .conflicts_with_all(&["max-depth", "min-depth"])207                .long_help(208                    "Only show search results at the exact given depth. This is an alias for \209                     '--min-depth <depth> --max-depth <depth>'.",210                ),211        )212        .arg(213            Arg::with_name("file-type")214                .long("type")215                .short("t")216                .multiple(true)217                .number_of_values(1)218                .takes_value(true)219                .value_name("filetype")220                .possible_values(&[221                    "f",222                    "file",223                    "d",224                    "directory",225                    "l",226                    "symlink",227                    "x",228                    "executable",229                    "e",230                    "empty",231                    "s",232                    "socket",233                    "p",234                    "pipe",235                ])236                .hide_possible_values(true)237                .help(238                    "Filter by type: file (f), directory (d), symlink (l),\nexecutable (x), \239                         empty (e), socket (s), pipe (p)",240                )241                .long_help(242                    "Filter the search by type (multiple allowable filetypes can be specified):\n  \243                       'f' or 'file':         regular files\n  \244                       'd' or 'directory':    directories\n  \245                       'l' or 'symlink':      symbolic links\n  \246                       'x' or 'executable':   executables\n  \247                       'e' or 'empty':        empty files or directories\n  \248                       's' or 'socket':       socket\n  \249                       'p' or 'pipe':         named pipe (FIFO)",250                ),251        )252        .arg(253            Arg::with_name("extension")254                .long("extension")255                .short("e")256                .multiple(true)257                .number_of_values(1)258                .takes_value(true)259                .value_name("ext")260                .help("Filter by file extension")261                .long_help(262                    "(Additionally) filter search results by their file extension. Multiple \263                         allowable file extensions can be specified.",264                ),265        )266        .arg(267            Arg::with_name("exec")268                .long("exec")269                .short("x")270                .min_values(1)271                .allow_hyphen_values(true)272                .value_terminator(";")273                .value_name("cmd")274                .conflicts_with("list-details")275                .help("Execute a command for each search result")276                .long_help(277                    "Execute a command for each search result.\n\278                     All arguments following --exec are taken to be arguments to the command until the \279                     argument ';' is encountered.\n\280                     Each occurrence of the following placeholders is substituted by a path derived from the \281                     current search result before the command is executed:\n  \282                       '{}':   path\n  \283                       '{/}':  basename\n  \284                       '{//}': parent directory\n  \285                       '{.}':  path without file extension\n  \286                       '{/.}': basename without file extension",287                ),288        )289        .arg(290            Arg::with_name("exec-batch")291                .long("exec-batch")292                .short("X")293                .min_values(1)294                .allow_hyphen_values(true)295                .value_terminator(";")296                .value_name("cmd")297                .conflicts_with_all(&["exec", "list-details"])298                .help("Execute a command with all search results at once")299                .long_help(300                    "Execute a command with all search results at once.\n\301                     All arguments following --exec-batch are taken to be arguments to the command until the \302                     argument ';' is encountered.\n\303                     A single occurrence of the following placeholders is authorized and substituted by the paths derived from the \304                     search results before the command is executed:\n  \305                       '{}':   path\n  \306                       '{/}':  basename\n  \307                       '{//}': parent directory\n  \308                       '{.}':  path without file extension\n  \309                       '{/.}': basename without file extension",310                ),311        )312        .arg(313            Arg::with_name("exclude")314                .long("exclude")315                .short("E")316                .takes_value(true)317                .value_name("pattern")318                .number_of_values(1)319                .multiple(true)320                .help("Exclude entries that match the given glob pattern")321                .long_help(322                    "Exclude files/directories that match the given glob pattern. This \323                         overrides any other ignore logic. Multiple exclude patterns can be \324                         specified.",325                ),326        )327        .arg(328            Arg::with_name("ignore-file")329                .long("ignore-file")330                .takes_value(true)331                .value_name("path")332                .number_of_values(1)333                .multiple(true)334                .hidden_short_help(true)335                .long_help(336                    "Add a custom ignore-file in '.gitignore' format. These files have a low \337                         precedence.",338                ),339        )340        .arg(341            Arg::with_name("color")342                .long("color")343                .short("c")344                .takes_value(true)345                .value_name("when")346                .possible_values(&["never", "auto", "always"])347                .hide_possible_values(true)348                .help("When to use colors: never, *auto*, always")349                .long_help(350                    "Declare when to use color for the pattern match output:\n  \351                       'auto':      show colors if the output goes to an interactive console (default)\n  \352                       'never':     do not use colorized output\n  \353                       'always':    always use colorized output",354                ),355        )356        .arg(357            Arg::with_name("threads")358                .long("threads")359                .short("j")360                .takes_value(true)361                .value_name("num")362                .hidden_short_help(true)363                .long_help(364                    "Set number of threads to use for searching & executing (default: number \365                         of available CPU cores)",366                ),367        )368        .arg(369            Arg::with_name("size")370                .long("size")371                .short("S")372                .takes_value(true)373                .number_of_values(1)374                .allow_hyphen_values(true)375                .multiple(true)376                .help("Limit results based on the size of files.")377                .long_help(378                    "Limit results based on the size of files using the format <+-><NUM><UNIT>.\n   \379                        '+': file size must be greater than or equal to this\n   \380                        '-': file size must be less than or equal to this\n   \381                        'NUM':  The numeric size (e.g. 500)\n   \382                        'UNIT': The units for NUM. They are not case-sensitive.\n\383                     Allowed unit values:\n   \384                         'b':  bytes\n   \385                         'k':  kilobytes\n   \386                         'm':  megabytes\n   \387                         'g':  gigabytes\n   \388                         't':  terabytes\n   \389                         'ki': kibibytes\n   \390                         'mi': mebibytes\n   \391                         'gi': gibibytes\n   \392                         'ti': tebibytes",393                ),394        )395        .arg(396            Arg::with_name("max-buffer-time")397                .long("max-buffer-time")398                .takes_value(true)399                .hidden(true)400                .long_help(401                    "Amount of time in milliseconds to buffer, before streaming the search \402                         results to the console.",403                ),404        )405        .arg(406            Arg::with_name("changed-within")407                .long("changed-within")408                .alias("change-newer-than")409                .takes_value(true)410                .value_name("date|dur")411                .number_of_values(1)412                .help("Filter by file modification time (newer than)")413                .long_help(414                    "Filter results based on the file modification time. The argument can be provided \415                     as a specific point in time (YYYY-MM-DD HH:MM:SS) or as a duration (10h, 1d, 35min). \416                     '--change-newer-than' can be used as an alias.\n\417                     Examples:\n    \418                         --changed-within 2weeks\n    \419                         --change-newer-than '2018-10-27 10:00:00'",420                ),421        )422        .arg(423            Arg::with_name("changed-before")424                .long("changed-before")425                .alias("change-older-than")426                .takes_value(true)427                .value_name("date|dur")428                .number_of_values(1)429                .help("Filter by file modification time (older than)")430                .long_help(431                    "Filter results based on the file modification time. The argument can be provided \432                     as a specific point in time (YYYY-MM-DD HH:MM:SS) or as a duration (10h, 1d, 35min). \433                     '--change-older-than' can be used as an alias.\n\434                     Examples:\n    \435                         --changed-before '2018-10-27 10:00:00'\n    \436                         --change-older-than 2weeks",437                ),438        )439        .arg(440            Arg::with_name("max-results")441                .long("max-results")442                .takes_value(true)443                .value_name("count")444                // We currently do not support --max-results in combination with445                // program execution because the results that come up in a --max-results446                // search are non-deterministic. Users might think that they can run the447                // same search with `--exec rm` attached and get a reliable removal of448                // the files they saw in the previous search.449                .conflicts_with_all(&["exec", "exec-batch", "list-details"])450                .hidden_short_help(true)451                .long_help("Limit the number of search results to 'count' and quit immediately."),452        )453        .arg(454            Arg::with_name("max-one-result")455                .short("1")456                .hidden_short_help(true)457                .overrides_with("max-results")458                .conflicts_with_all(&["exec", "exec-batch", "list-details"])459                .long_help("Limit the search to a single result and quit immediately. \460                                This is an alias for '--max-results=1'.")461        )462        .arg(463            Arg::with_name("show-errors")464                .long("show-errors")465                .hidden_short_help(true)466                .overrides_with("show-errors")467                .long_help(468                    "Enable the display of filesystem errors for situations such as \469                         insufficient permissions or dead symlinks.",470                ),471        )472        .arg(473            Arg::with_name("base-directory")474                .long("base-directory")475                .takes_value(true)476                .value_name("path")477                .number_of_values(1)478                .hidden_short_help(true)479                .long_help(480                    "Change the current working directory of fd to the provided path. The \481                         means that search results will be shown with respect to the given base \482                         path. Note that relative paths which are passed to fd via the positional \483                         <path> argument or the '--search-path' option will also be resolved \484                         relative to this directory.",485                ),486        )487        .arg(488            Arg::with_name("pattern").help(489                "the search pattern - a regular expression unless '--glob' is used (optional)",490            ),491        )492        .arg(493            Arg::with_name("path-separator")494                .takes_value(true)495                .value_name("separator")496                .long("path-separator")497                .hidden_short_help(true)498                .long_help(499                    "Set the path separator to use when printing file paths. The default is \500                         the OS-specific separator ('/' on Unix, '\\' on Windows).",501                ),502        )503        .arg(504            Arg::with_name("path")505                .multiple(true)506                .help("the root directory for the filesystem search (optional)")507                .long_help(508                    "The directory where the filesystem search is rooted (optional). If \509                         omitted, search the current working directory.",510                ),511        )512        .arg(513            Arg::with_name("search-path")514                .long("search-path")515                .takes_value(true)516                .conflicts_with("path")517                .multiple(true)518                .hidden_short_help(true)519                .number_of_values(1)520                .long_help(521                    "Provide paths to search as an alternative to the positional <path> \522                         argument. Changes the usage to `fd [FLAGS/OPTIONS] --search-path <path> \523                         --search-path <path2> [<pattern>]`",524                ),525        );526527    // Make `--one-file-system` available only on Unix and Windows platforms, as per the528    // restrictions on the corresponding option in the `ignore` crate.529    // Provide aliases `mount` and `xdev` for people coming from `find`.530    if cfg!(any(unix, windows)) {531        app = app.arg(532            Arg::with_name("one-file-system")533                .long("one-file-system")534                .aliases(&["mount", "xdev"])535                .hidden_short_help(true)536                .long_help(537                    "By default, fd will traverse the file system tree as far as other options \538                     dictate. With this flag, fd ensures that it does not descend into a \539                     different file system than the one it started in. Comparable to the -mount \540                     or -xdev filters of find(1).",541                ),542        );543    }544545    app546}