app.rs
This file
Path
src/app.rs
212 lines · 8.2 KiB · Rust
Last changed by
Add support for exclude-patternssharkdpbefore adoption5ad69fb
History of this fileTake it
Relicense under MIT/Apache-2.0Antti Keränenbefore adoption701b8f2
lines 1–8why, one step back1// Copyright (c) 2017 fd developers2// Licensed under the Apache License, Version 2.03// <LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0>4// or the MIT license <LICENSE-MIT or http://opensource.org/licenses/MIT>,5// at your option. All files in the project carrying such6// notice may not be copied, modified, or distributed except7// according to those terms.8app: refactor to ripgrep style for long_helpAlejandro Baezbefore adoptiona84536a
lines 9–10why, one step back9use std::collections::HashMap;10Use clap to generate shell completionsFlorian Hofmairbefore adoption396b9ba
lines 11–12why, one step back11use clap::{App, AppSettings, Arg};12app: refactor to ripgrep style for long_helpAlejandro Baezbefore adoptiona84536a
lines 13–29why, one step back13struct Help {14 short: &'static str,15 long: &'static str,16}1718macro_rules! doc {19 ($map:expr, $name:expr, $short:expr) => {20 doc!($map, $name, $short, $short)21 };22 ($map:expr, $name:expr, $short:expr, $long:expr) => {23 $map.insert($name, Help {24 short: $short,25 long: concat!($long, "\n ")26 });27 };28}29Use clap to generate shell completionsFlorian Hofmairbefore adoption396b9ba
line 30why, one step back30pub fn build_app() -> App<'static, 'static> {app: refactor to ripgrep style for long_helpAlejandro Baezbefore adoptiona84536a
lines 31–37why, one step back31 let helps = usage();32 let arg = |name| {33 Arg::with_name(name).help(helps[name].short).long_help(34 helps[name].long,35 )36 };37Use clap to generate shell completionsFlorian Hofmairbefore adoption396b9ba
line 38why, one step back38 App::new("fd")Code style udpatessharkdpbefore adoption34e4620
lines 39–42why, one step back39 .version(crate_version!())40 .usage("fd [FLAGS/OPTIONS] [<pattern>] [<path>]")41 .setting(AppSettings::ColoredHelp)42 .setting(AppSettings::DeriveDisplayOrder)app: refactor to ripgrep style for long_helpAlejandro Baezbefore adoptiona84536a
lines 43–44why, one step back43 .arg(arg("hidden").long("hidden").short("H"))44 .arg(arg("no-ignore").long("no-ignore").short("I"))Format the source code using `rustfmt`Antti Keränenbefore adoption049b9ec
lines 45–62why, one step back45 .arg(46 arg("rg-alias-hidden-ignore")47 .short("u")48 .multiple(true)49 .hidden(true),50 )51 .arg(52 arg("case-sensitive")53 .long("case-sensitive")54 .short("s")55 .overrides_with("ignore-case"),56 )57 .arg(58 arg("ignore-case")59 .long("ignore-case")60 .short("i")61 .overrides_with("case-sensitive"),62 )app: refactor to ripgrep style for long_helpAlejandro Baezbefore adoptiona84536a
lines 63–67why, one step back63 .arg(arg("absolute-path").long("absolute-path").short("a"))64 .arg(arg("follow").long("follow").short("L").alias("dereference"))65 .arg(arg("full-path").long("full-path").short("p"))66 .arg(arg("null_separator").long("print0").short("0"))67 .arg(arg("depth").long("max-depth").short("d").takes_value(true))Code style udpatessharkdpbefore adoption34e4620
line 68why, one step back68 .arg(app: refactor to ripgrep style for long_helpAlejandro Baezbefore adoptiona84536a
line 69why, one step back69 arg("file-type")Use clap to generate shell completionsFlorian Hofmairbefore adoption396b9ba
lines 70–72why, one step back70 .long("type")71 .short("t")72 .takes_value(true)Update help textsharkdpbefore adoption0aae4a3
line 73why, one step back73 .value_name("filetype")Switch symlink arg from 's' to 'l' (#83)Jean-Christophe Petkovichbefore adoptionaffe419
line 74why, one step back74 .possible_values(&["f", "file", "d", "directory", "l", "symlink"])app: refactor to ripgrep style for long_helpAlejandro Baezbefore adoptiona84536a
line 75why, one step back75 .hide_possible_values(true),Code style udpatessharkdpbefore adoption34e4620
lines 76–77why, one step back76 )77 .arg(app: refactor to ripgrep style for long_helpAlejandro Baezbefore adoptiona84536a
line 78why, one step back78 arg("extension")Use clap to generate shell completionsFlorian Hofmairbefore adoption396b9ba
lines 79–81why, one step back79 .long("extension")80 .short("e")81 .takes_value(true)app: refactor to ripgrep style for long_helpAlejandro Baezbefore adoptiona84536a
line 82why, one step back82 .value_name("ext"),Code style udpatessharkdpbefore adoption34e4620
lines 83–84why, one step back83 )84 .arg(Add support for exclude-patternssharkdpbefore adoption5ad69fb
lines 85–100why, one step back85 arg("exec")86 .long("exec")87 .short("x")88 .takes_value(true)89 .value_name("cmd"),90 )91 .arg(92 arg("exclude")93 .long("exclude")94 .short("E")95 .takes_value(true)96 .value_name("pattern")97 .number_of_values(1)98 .multiple(true),99 )100 .arg(app: refactor to ripgrep style for long_helpAlejandro Baezbefore adoptiona84536a
line 101why, one step back101 arg("color")Use clap to generate shell completionsFlorian Hofmairbefore adoption396b9ba
lines 102–104why, one step back102 .long("color")103 .short("c")104 .takes_value(true)Update help textsharkdpbefore adoption0aae4a3
line 105why, one step back105 .value_name("when")Use clap to generate shell completionsFlorian Hofmairbefore adoption396b9ba
line 106why, one step back106 .possible_values(&["never", "auto", "always"])app: refactor to ripgrep style for long_helpAlejandro Baezbefore adoptiona84536a
line 107why, one step back107 .hide_possible_values(true),Code style udpatessharkdpbefore adoption34e4620
lines 108–109why, one step back108 )109 .arg(app: refactor to ripgrep style for long_helpAlejandro Baezbefore adoptiona84536a
line 110why, one step back110 arg("threads")Use clap to generate shell completionsFlorian Hofmairbefore adoption396b9ba
lines 111–113why, one step back111 .long("threads")112 .short("j")113 .takes_value(true)app: refactor to ripgrep style for long_helpAlejandro Baezbefore adoptiona84536a
line 114why, one step back114 .value_name("num"),Code style udpatessharkdpbefore adoption34e4620
lines 115–116why, one step back115 )116 .arg(app: refactor to ripgrep style for long_helpAlejandro Baezbefore adoptiona84536a
line 117why, one step back117 arg("max-buffer-time")Use clap to generate shell completionsFlorian Hofmairbefore adoption396b9ba
lines 118–119why, one step back118 .long("max-buffer-time")119 .takes_value(true)app: refactor to ripgrep style for long_helpAlejandro Baezbefore adoptiona84536a
line 120why, one step back120 .hidden(true),Code style udpatessharkdpbefore adoption34e4620
line 121why, one step back121 )app: refactor to ripgrep style for long_helpAlejandro Baezbefore adoptiona84536a
lines 122–130why, one step back122 .arg(arg("pattern"))123 .arg(arg("path"))124}125126#[cfg_attr(rustfmt, rustfmt_skip)]127fn usage() -> HashMap<&'static str, Help> {128 let mut h = HashMap::new();129 doc!(h, "hidden"130 , "Search hidden files and directories"Update long help textsharkdpbefore adoptiond8da6ec
lines 131–132why, one step back131 , "Include hidden directories and files in the search results (default: hidden files \132 and directories are skipped).");app: refactor to ripgrep style for long_helpAlejandro Baezbefore adoptiona84536a
lines 133–134why, one step back133 doc!(h, "no-ignore"134 , "Do not respect .(git)ignore files"Update long help textsharkdpbefore adoptiond8da6ec
line 135why, one step back135 , "Show search results from files and directories that would otherwise be ignored by \app: refactor to ripgrep style for long_helpAlejandro Baezbefore adoptiona84536a
lines 136–138why, one step back136 '.*ignore' files.");137 doc!(h, "case-sensitive"138 , "Case-sensitive search (default: smart case)"Update long help textsharkdpbefore adoptiond8da6ec
line 139why, one step back139 , "Perform a case-sensitive search. By default, fd uses case-insensitive searches, \Fix description of smart-case in help textsharkdpbefore adoptionc38ef0e
line 140why, one step back140 unless the pattern contains an uppercase character (smart case).");Add -i, --ignore-caseJ.Wbefore adoptione075e1c
lines 141–143why, one step back141 doc!(h, "ignore-case"142 , "Case-insensitive search (default: smart case)"143 , "Perform a case-insensitive search. By default, fd uses case-insensitive searches, \Fix description of smart-case in help textsharkdpbefore adoptionc38ef0e
line 144why, one step back144 unless the pattern contains an uppercase character (smart case).");app: refactor to ripgrep style for long_helpAlejandro Baezbefore adoptiona84536a
lines 145–146why, one step back145 doc!(h, "absolute-path"146 , "Show absolute instead of relative paths"Update long help textsharkdpbefore adoptiond8da6ec
line 147why, one step back147 , "Shows the full path starting from the root as opposed to relative paths.");app: refactor to ripgrep style for long_helpAlejandro Baezbefore adoptiona84536a
lines 148–149why, one step back148 doc!(h, "follow"149 , "Follow symbolic links"Typo fix: Change 'descent' to 'descend'John L. Villalovosbefore adoption4bf7ab6
line 150why, one step back150 , "By default, fd does not descend into symlinked directories. Using this flag, symbolic \Update long help textsharkdpbefore adoptiond8da6ec
line 151why, one step back151 links are also traversed.");app: refactor to ripgrep style for long_helpAlejandro Baezbefore adoptiona84536a
lines 152–153why, one step back152 doc!(h, "full-path"153 , "Search full path (default: file-/dirname only)"Update long help textsharkdpbefore adoptiond8da6ec
lines 154–155why, one step back154 , "By default, the search pattern is only matched against the filename (or directory \155 name). Using this flag, the pattern is matched against the full path.");app: refactor to ripgrep style for long_helpAlejandro Baezbefore adoptiona84536a
lines 156–157why, one step back156 doc!(h, "null_separator"157 , "Separate results by the null character"Update long help textsharkdpbefore adoptiond8da6ec
lines 158–159why, one step back158 , "Separate search results by the null character (instead of newlines). Useful for \159 piping results to 'xargs'.");app: refactor to ripgrep style for long_helpAlejandro Baezbefore adoptiona84536a
lines 160–161why, one step back160 doc!(h, "depth"161 , "Set maximum search depth (default: none)"Update long help textsharkdpbefore adoptiond8da6ec
lines 162–163why, one step back162 , "Limit the directory traversal to a given depth. By default, there is no limit \163 on the search depth.");app: refactor to ripgrep style for long_helpAlejandro Baezbefore adoptiona84536a
line 164why, one step back164 doc!(h, "file-type"Switch symlink arg from 's' to 'l' (#83)Jean-Christophe Petkovichbefore adoptionaffe419
line 165why, one step back165 , "Filter by type: f(ile), d(irectory), (sym)l(ink)"Update long help textsharkdpbefore adoptiond8da6ec
lines 166–168why, one step back166 , "Filter the search by type:\n \167 'f' or 'file': regular files\n \168 'd' or 'directory': directories\n \Switch symlink arg from 's' to 'l' (#83)Jean-Christophe Petkovichbefore adoptionaffe419
line 169why, one step back169 'l' or 'symlink': symbolic links");Add support for exclude-patternssharkdpbefore adoption5ad69fb
lines 170–172why, one step back170 doc!(h, "extension"171 , "Filter by file extension"172 , "(Additionally) filter search results by their file extension.");Merge pull request #116 from mmstick/execDavid Peterbefore adoptione0eab07
line 173why, one step back173 doc!(h, "exec"Updates and preparations for v5.0sharkdpbefore adoptione9cf8af
lines 174–175why, one step back174 , "Execute the given command for each search result"175 , "Execute the given command for each search result.\n\Merge pull request #116 from mmstick/execDavid Peterbefore adoptione0eab07
lines 176–181why, one step back176 The following are valid tokens that can be used within the expression for generating \177 commands:\n \178 '{}': places the input in the location of this token\n \179 '{.}': removes the extension from the input\n \180 '{/}': places the basename of the input\n \181 '{//}': places the parent of the input\n \Add support for exclude-patternssharkdpbefore adoption5ad69fb
lines 182–186why, one step back182 '{/.}': places the basename of the input, without the extension");183 doc!(h, "exclude"184 , "Exclude entries that match the given glob pattern."185 , "Exclude files/directories that match the given glob pattern. This overrides any \186 other ignore logic. Multiple exclude patterns can be specified.");app: refactor to ripgrep style for long_helpAlejandro Baezbefore adoptiona84536a
line 187why, one step back187 doc!(h, "color"Update long help textsharkdpbefore adoptiond8da6ec
lines 188–192why, one step back188 , "When to use colors: never, *auto*, always"189 , "Declare when to use color for the pattern match output:\n \190 'auto': show colors if the output goes to an interactive console (default)\n \191 'never': do not use colorized output\n \192 'always': always use colorized output");app: refactor to ripgrep style for long_helpAlejandro Baezbefore adoptiona84536a
line 193why, one step back193 doc!(h, "threads"Merge pull request #116 from mmstick/execDavid Peterbefore adoptione0eab07
lines 194–196why, one step back194 , "Set number of threads to use for searching & executing"195 , "Set number of threads to use for searching & executing (default: number of available \196 CPU cores)");app: refactor to ripgrep style for long_helpAlejandro Baezbefore adoptiona84536a
lines 197–199why, one step back197 doc!(h, "max-buffer-time"198 , "the time (in ms) to buffer, before streaming to the console"199 , "Amount of time in milliseconds to buffer, before streaming the search results to\Update long help textsharkdpbefore adoptiond8da6ec
line 200why, one step back200 the console.");app: refactor to ripgrep style for long_helpAlejandro Baezbefore adoptiona84536a
lines 201–204why, one step back201 doc!(h, "pattern"202 , "the search pattern, a regular expression (optional)");203 doc!(h, "path"204 , "the root directory for the filesystem search (optional)"Update long help textsharkdpbefore adoptiond8da6ec
lines 205–206why, one step back205 , "The directory where the filesystem search is rooted (optional). \206 If omitted, search the current working directory.");Add ripgrep aliases for no-ignore and hiddenRav Chandrabefore adoption4f2d9e7
lines 207–209why, one step back207 doc!(h, "rg-alias-hidden-ignore"208 , "Alias for no-ignore and/or hidden"209 , "Alias for no-ignore ('u') and no-ignore and hidden ('uu')");app: refactor to ripgrep style for long_helpAlejandro Baezbefore adoptiona84536a
lines 210–211why, one step back210211 hUse clap to generate shell completionsFlorian Hofmairbefore adoption396b9ba
line 212why, one step back212}