Skip to content
Myr

Use clap to generate shell completions

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

authored by Florian Hofmair · committed by David Peter · parent 083b1cf · Browse files · 4 files+104 added−78 removed
This commit

State

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

Diff stats

4 files+104 added−78 removed

  • other:+104 added−78 removed

4 files+104 added−78 removed

added:src/app.rs+79 added
1use clap::{App, AppSettings, Arg};23pub fn build_app() -> App<'static, 'static> {4 App::new("fd")5 .version(crate_version!())6 .usage("fd [FLAGS/OPTIONS] [<pattern>] [<path>]")7 .setting(AppSettings::ColoredHelp)8 .setting(AppSettings::DeriveDisplayOrder)9 .arg(Arg::with_name("hidden")10 .long("hidden")11 .short("H")12 .help("Search hidden files and directories"))13 .arg(Arg::with_name("no-ignore")14 .long("no-ignore")15 .short("I")16 .help("Do not respect .(git)ignore files"))17 .arg(Arg::with_name("case-sensitive")18 .long("case-sensitive")19 .short("s")20 .help("Case-sensitive search (default: smart case)"))21 .arg(Arg::with_name("absolute-path")22 .long("absolute-path")23 .short("a")24 .help("Show absolute instead of relative paths"))25 .arg(Arg::with_name("follow")26 .long("follow")27 .short("L")28 .alias("dereference")29 .help("Follow symbolic links"))30 .arg(Arg::with_name("full-path")31 .long("full-path")32 .short("p")33 .help("Search full path (default: file-/dirname only)"))34 .arg(Arg::with_name("null_separator")35 .long("print0")36 .short("0")37 .help("Separate results by the null character"))38 .arg(Arg::with_name("depth")39 .long("max-depth")40 .short("d")41 .takes_value(true)42 .help("Set maximum search depth (default: none)"))43 .arg(Arg::with_name("file-type")44 .long("type")45 .short("t")46 .takes_value(true)47 .possible_values(&["f", "file", "d", "directory", "s", "symlink"])48 .hide_possible_values(true)49 .help("Filter by type: f(ile), d(irectory), s(ymlink)"))50 .arg(Arg::with_name("extension")51 .long("extension")52 .short("e")53 .takes_value(true)54 .value_name("ext")55 .help("Filter by file extension"))56 .arg(Arg::with_name("color")57 .long("color")58 .short("c")59 .takes_value(true)60 .possible_values(&["never", "auto", "always"])61 .hide_possible_values(true)62 .help("When to use color in the output:\n\63 never, auto, always (default: auto)"))64 .arg(Arg::with_name("threads")65 .long("threads")66 .short("j")67 .takes_value(true)68 .help("Set number of threads to use for searching\n\69 (default: number of available CPU cores)"))70 .arg(Arg::with_name("max-buffer-time")71 .long("max-buffer-time")72 .takes_value(true)73 .hidden(true)74 .help("the time (in ms) to buffer, before streaming to the console"))75 .arg(Arg::with_name("pattern")76 .help("the search pattern, a regular expression (optional)"))77 .arg(Arg::with_name("path")78 .help("the root directory for the filesystem search (optional)"))79}
modified:src/main.rs+2 added-78 removed
6 unmodified lines
7extern crate num_cpus;89pub mod lscolors;10pub mod fshelper;11mod app;1213use std::borrow::Cow;14use std::env;15use std::error::Error;
7 unmodified lines
23use std::sync::mpsc::channel;24use std::thread;25use std::time;2626use clap::{App, AppSettings, Arg};27use atty::Stream;28use regex::{Regex, RegexBuilder};29use ignore::WalkBuilder;30
322 unmodified lines
353 process::exit(1);354}355356fn main() {357 let matches =358 App::new("fd")359 .version(crate_version!())360 .usage("fd [FLAGS/OPTIONS] [<pattern>] [<path>]")361 .setting(AppSettings::ColoredHelp)362 .setting(AppSettings::DeriveDisplayOrder)363 .arg(Arg::with_name("hidden")364 .long("hidden")365 .short("H")366 .help("Search hidden files and directories"))367 .arg(Arg::with_name("no-ignore")368 .long("no-ignore")369 .short("I")370 .help("Do not respect .(git)ignore files"))371 .arg(Arg::with_name("case-sensitive")372 .long("case-sensitive")373 .short("s")374 .help("Case-sensitive search (default: smart case)"))375 .arg(Arg::with_name("absolute-path")376 .long("absolute-path")377 .short("a")378 .help("Show absolute instead of relative paths"))379 .arg(Arg::with_name("follow")380 .long("follow")381 .short("L")382 .alias("dereference")383 .help("Follow symbolic links"))384 .arg(Arg::with_name("full-path")385 .long("full-path")386 .short("p")387 .help("Search full path (default: file-/dirname only)"))388 .arg(Arg::with_name("null_separator")389 .long("print0")390 .short("0")391 .help("Separate results by the null character"))392 .arg(Arg::with_name("depth")393 .long("max-depth")394 .short("d")395 .takes_value(true)396 .help("Set maximum search depth (default: none)"))397 .arg(Arg::with_name("file-type")398 .long("type")399 .short("t")400 .takes_value(true)401 .possible_values(&["f", "file", "d", "directory", "s", "symlink"])402 .hide_possible_values(true)403 .help("Filter by type: f(ile), d(irectory), s(ymlink)"))404 .arg(Arg::with_name("extension")405 .long("extension")406 .short("e")407 .takes_value(true)408 .value_name("ext")409 .help("Filter by file extension"))410 .arg(Arg::with_name("color")411 .long("color")412 .short("c")413 .takes_value(true)414 .possible_values(&["never", "auto", "always"])415 .hide_possible_values(true)416 .help("When to use color in the output:\n\417 never, auto, always (default: auto)"))418 .arg(Arg::with_name("threads")419 .long("threads")420 .short("j")421 .takes_value(true)422 .help("Set number of threads to use for searching\n\423 (default: number of available CPU cores)"))424 .arg(Arg::with_name("max-buffer-time")425 .long("max-buffer-time")426 .takes_value(true)427 .hidden(true)428 .help("the time (in ms) to buffer, before streaming to the console"))429 .arg(Arg::with_name("pattern")430 .help("the search pattern, a regular expression (optional)"))431 .arg(Arg::with_name("path")432 .help("the root directory for the filesystem search (optional)"))433 .get_matches();357 let matches = app::build_app().get_matches();358359 // Get the search pattern360 let empty_pattern = String::new();361 let pattern = matches.value_of("pattern").unwrap_or(&empty_pattern);
98 unmodified lines
added:build.rs+19 added
1#[macro_use]2extern crate clap;34use clap::Shell;56include!("src/app.rs");78fn main() {9 let outdir = match std::env::var_os("OUT_DIR") {10 None => return,11 Some(outdir) => outdir,12 };1314 let mut app = build_app();15 app.gen_completions("fd", Shell::Bash, &outdir);16 app.gen_completions("fd", Shell::Fish, &outdir);17 app.gen_completions("fd", Shell::Zsh, &outdir);18 app.gen_completions("fd", Shell::PowerShell, &outdir);19}
modified:Cargo.toml+4 added