Skip to content
Myr

app: refactor to ripgrep style for long_help

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Alejandro Baez · committed by David Peter · parent 080e8a9 · Browse files · 1 file+113 added−73 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+113 added−73 removed

  • other:+113 added−73 removed

1 file+113 added−73 removed

modified:src/app.rs+113 added-73 removed
1use std::collections::HashMap;23use clap::{App, AppSettings, Arg};45struct Help {6 short: &'static str,7 long: &'static str,8}910macro_rules! doc {11 ($map:expr, $name:expr, $short:expr) => {12 doc!($map, $name, $short, $short)13 };14 ($map:expr, $name:expr, $short:expr, $long:expr) => {15 $map.insert($name, Help {16 short: $short,17 long: concat!($long, "\n ")18 });19 };20}2122pub fn build_app() -> App<'static, 'static> {23 let helps = usage();24 let arg = |name| {25 Arg::with_name(name).help(helps[name].short).long_help(26 helps[name].long,27 )28 };2930 App::new("fd")31 .version(crate_version!())32 .usage("fd [FLAGS/OPTIONS] [<pattern>] [<path>]")33 .setting(AppSettings::ColoredHelp)34 .setting(AppSettings::DeriveDisplayOrder)35 .arg(arg("hidden").long("hidden").short("H"))36 .arg(arg("no-ignore").long("no-ignore").short("I"))37 .arg(arg("case-sensitive").long("case-sensitive").short("s"))38 .arg(arg("absolute-path").long("absolute-path").short("a"))39 .arg(arg("follow").long("follow").short("L").alias("dereference"))40 .arg(arg("full-path").long("full-path").short("p"))41 .arg(arg("null_separator").long("print0").short("0"))42 .arg(arg("depth").long("max-depth").short("d").takes_value(true))43 .arg(10 Arg::with_name("hidden")11 .long("hidden")12 .short("H")13 .help("Search hidden files and directories"),14 )15 .arg(16 Arg::with_name("no-ignore")17 .long("no-ignore")18 .short("I")19 .help("Do not respect .(git)ignore files"),20 )21 .arg(22 Arg::with_name("case-sensitive")23 .long("case-sensitive")24 .short("s")25 .help("Case-sensitive search (default: smart case)"),26 )27 .arg(28 Arg::with_name("absolute-path")29 .long("absolute-path")30 .short("a")31 .help("Show absolute instead of relative paths"),32 )33 .arg(34 Arg::with_name("follow")35 .long("follow")36 .short("L")37 .alias("dereference")38 .help("Follow symbolic links"),39 )40 .arg(41 Arg::with_name("full-path")42 .long("full-path")43 .short("p")44 .help("Search full path (default: file-/dirname only)"),45 )46 .arg(47 Arg::with_name("null_separator")48 .long("print0")49 .short("0")50 .help("Separate results by the null character"),51 )52 .arg(53 Arg::with_name("depth")54 .long("max-depth")55 .short("d")56 .takes_value(true)57 .help("Set maximum search depth (default: none)"),58 )59 .arg(60 Arg::with_name("file-type")44 arg("file-type")45 .long("type")46 .short("t")47 .takes_value(true)48 .value_name("filetype")49 .possible_values(&["f", "file", "d", "directory", "s", "symlink"])66 .hide_possible_values(true)67 .help("Filter by type: f(ile), d(irectory), s(ymlink)"),50 .hide_possible_values(true),51 )52 .arg(70 Arg::with_name("extension")53 arg("extension")54 .long("extension")55 .short("e")56 .takes_value(true)74 .value_name("ext")75 .help("Filter by file extension"),57 .value_name("ext"),58 )59 .arg(78 Arg::with_name("color")60 arg("color")61 .long("color")62 .short("c")63 .takes_value(true)64 .value_name("when")65 .possible_values(&["never", "auto", "always"])84 .hide_possible_values(true)85 .help(86 "When to use color in the output:\n\87 never, auto, always (default: auto)",88 ),66 .hide_possible_values(true),67 )68 .arg(91 Arg::with_name("threads")69 arg("threads")70 .long("threads")71 .short("j")72 .takes_value(true)95 .value_name("num")96 .help(97 "Set number of threads to use for searching\n\98 (default: number of available CPU cores)",99 ),73 .value_name("num"),74 )75 .arg(102 Arg::with_name("max-buffer-time")76 arg("max-buffer-time")77 .long("max-buffer-time")78 .takes_value(true)105 .hidden(true)106 .help("the time (in ms) to buffer, before streaming to the console"),79 .hidden(true),80 )108 .arg(Arg::with_name("pattern").help("the search pattern, a regular expression (optional)"))109 .arg(Arg::with_name("path").help("the root directory for the filesystem search (optional)"))81 .arg(arg("pattern"))82 .arg(arg("path"))83}8485#[cfg_attr(rustfmt, rustfmt_skip)]86fn usage() -> HashMap<&'static str, Help> {87 let mut h = HashMap::new();88 doc!(h, "hidden"89 , "Search hidden files and directories"90 , "Also include hidden directories and files in the search results (default: hidden files\91 and directories are skipped).");92 doc!(h, "no-ignore"93 , "Do not respect .(git)ignore files"94 , "Show search results from files and directories that would otherwise be ignored by\95 '.*ignore' files.");96 doc!(h, "case-sensitive"97 , "Case-sensitive search (default: smart case)"98 , "Define your pattern as case sensitive. By default, fd uses 'smart case' for queries.\99 This option disables smart case.");100 doc!(h, "absolute-path"101 , "Show absolute instead of relative paths"102 , "Shows the result of a pattern match as an absolute path instead of relative path.");103 doc!(h, "follow"104 , "Follow symbolic links"105 , "By default, fd does not descent into symlinked directories. Using this flag, symbolic \106 links are also traversed.");107 doc!(h, "full-path"108 , "Search full path (default: file-/dirname only)"109 , "Searches the full path of directory. By default, fd only searches the last part of \110 the path (the file name or the directory name).");111 doc!(h, "null_separator"112 , "Separate results by the null character"113 , "Separate search results by the null character (instead of newlines). This is useful \114 for piping results to 'xargs'.");115 doc!(h, "depth"116 , "Set maximum search depth (default: none)"117 , "Set the limit of the maximum search depth in a pattern match query. By default, there\118 is no limit on the search depth.");119 doc!(h, "file-type"120 , "Filter by type: f(ile), d(irectory), s(ymlink)"121 , "Filter the search by type:\n\122 f file for file\n\123 d directory for directory\n\124 s symlink for symbolic links");125 doc!(h, "extension"126 , "Filter by file extension"127 , "Only show search results with a specific file extension.");128 doc!(h, "color"129 , "When to use color in the output:\n\130 never, auto, always (default: auto)"131 , "Declare when to use color for the pattern match output:\n\132 auto (default)\n\133 never\n\134 always");135 doc!(h, "threads"136 , "Set number of threads to use for searching:\n\137 (default: number of available CPU cores)");138 doc!(h, "max-buffer-time"139 , "the time (in ms) to buffer, before streaming to the console"140 , "Amount of time in milliseconds to buffer, before streaming the search results to\141 the console.");142 doc!(h, "pattern"143 , "the search pattern, a regular expression (optional)");144 doc!(h, "path"145 , "the root directory for the filesystem search (optional)"146 , "The root directory where you want to do the filesystem search of the pattern.\147 When not present, the default is to use the current working directory.");148149 h150}