Merge pull request #1170 from tmccombs/clap-improvements-2
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Clap improvements 2
authored by Thayne McCombs · committed by GitHub · parents 9e88f91, 38d4068 · Browse files · 5 files·+33 added−96 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
5 files+33 added−96 removed
- tests:+2 added−1 removed
- other:+31 added−95 removed
Provenance
- Commit
85e3ada- Tree
0a807a8- Author
Thayne McCombs <astrothayne@gmail.com>- Committer
GitHub <noreply@github.com>- Parent 1
9e88f91- Parent 2
38d4068
5 files changed+33 added−96 removed
modified:src/cli.rs+23 added-87 removed
15 unmodified lines16 #[cfg(unix)]17 use crate::filter::OwnerFilter;18 use crate::filter::SizeFilter;19 20-// Type for options that don't have any values, but are used to negate21-// earlier options22-struct Negations;23-24-impl clap::FromArgMatches for Negations {25- fn from_arg_matches(_: &ArgMatches) -> clap::error::Result<Self> {26- Ok(Negations)27- }28-29- fn update_from_arg_matches(&mut self, _: &ArgMatches) -> clap::error::Result<()> {30- Ok(())31- }32-}33-34-impl clap::Args for Negations {35- fn augment_args(cmd: Command) -> Command {36- Self::augment_args_for_update(cmd)37- }38-39- fn augment_args_for_update(cmd: Command) -> Command {40- cmd.arg(41- Arg::new("no_hidden")42- .action(ArgAction::Count)43- .long("no-hidden")44- .overrides_with("hidden")45- .hide(true)46- .long_help("Overrides --hidden."),47- )48- .arg(49- Arg::new("ignore")50- .action(ArgAction::Count)51- .long("ignore")52- .overrides_with("no_ignore")53- .hide(true)54- .long_help("Overrides --no-ignore."),55- )56- .arg(57- Arg::new("ignore_vcs")58- .action(ArgAction::Count)59- .long("ignore-vcs")60- .overrides_with("no_ignore_vcs")61- .hide(true)62- .long_help("Overrides --no-ignore-vcs."),63- )64- .arg(65- Arg::new("relative_path")66- .action(ArgAction::Count)67- .long("relative-path")68- .overrides_with("absolute_path")69- .hide(true)70- .long_help("Overrides --absolute-path."),71- )72- .arg(73- Arg::new("no_follow")74- .action(ArgAction::Count)75- .long("no-follow")76- .overrides_with("follow")77- .hide(true)78- .long_help("Overrides --follow."),79- )80- }81-}82-20 #[derive(Parser)]21 #[command(22 name = "fd",23 version,15 unmodified lines39 The flag can be overridden with --no-hidden."40 )]41 pub hidden: bool,42 43+ /// Overrides --hidden44+ #[arg(long, overrides_with = "hidden", hide = true, action = ArgAction::SetTrue)]45+ no_hidden: (),46+47 /// Do not respect .(git|fd)ignore files48 #[arg(49 long,50 short = 'I',2 unmodified lines53 The flag can be overridden with --ignore."54 )]55 pub no_ignore: bool,56 57+ /// Overrides --no-ignore58+ #[arg(long, overrides_with = "no_ignore", hide = true, action = ArgAction::SetTrue)]59+ ignore: (),60+61 /// Do not respect .gitignore files62 #[arg(63 long,64 hide_short_help = true,1 unmodified line66 ignored by '.gitignore' files. The flag can be overridden with --ignore-vcs."67 )]68 pub no_ignore_vcs: bool,69 70+ /// Overrides --no-ignore-vcs71+ #[arg(long, overrides_with = "no_ignore_vcs", hide = true, action = ArgAction::SetTrue)]72+ ignore_vcs: (),73+74 /// Do not respect .(git|fd)ignore files in parent directories75 #[arg(76 long,77 hide_short_help = true,74 unmodified lines152 The flag can be overridden with --relative-path."153 )]154 pub absolute_path: bool,155 156+ /// Overrides --absolute-path157+ #[arg(long, overrides_with = "absolute_path", hide = true, action = ArgAction::SetTrue)]158+ relative_path: (),159+160 /// Use a long listing format with file metadata161 #[arg(162 long,163 short = 'l',15 unmodified lines179 Flag can be overriden with --no-follow."180 )]181 pub follow: bool,182 183+ /// Overrides --follow184+ #[arg(long, overrides_with = "follow", hide = true, action = ArgAction::SetTrue)]185+ no_follow: (),186+187 /// Search full abs. path (default: filename only)188 #[arg(189 long,190 short = 'p',356 unmodified lines547 548 #[cfg(feature = "completions")]549 #[arg(long, hide = true, exclusive = true)]550 gen_completions: Option<Option<Shell>>,594-595- #[clap(flatten)]596- _negations: Negations,551 }552 553 impl Opts {554 pub fn search_paths(&self) -> anyhow::Result<Vec<PathBuf>> {71 unmodified lines626 pub fn gen_completions(&self) -> anyhow::Result<Option<Shell>> {627 self.gen_completions628 .map(|maybe_shell| match maybe_shell {629 Some(sh) => Ok(sh),676- None => guess_shell(),630+ None => {631+ Shell::from_env().ok_or_else(|| anyhow!("Unable to get shell from environment"))632+ }633 })634 .transpose()635 }636 }637 682-#[cfg(feature = "completions")]683-fn guess_shell() -> anyhow::Result<Shell> {684- let env_shell = std::env::var_os("SHELL").map(PathBuf::from);685- if let Some(shell) = env_shell686- .as_ref()687- .and_then(|s| s.file_name())688- .and_then(|s| s.to_str())689- {690- shell691- .parse::<Shell>()692- .map_err(|_| anyhow!("Unknown shell {}", shell))693- } else {694- // Assume powershell on windows695- #[cfg(windows)]696- return Ok(Shell::PowerShell);697- #[cfg(not(windows))]698- return Err(anyhow!("Unable to get shell from environment"));699- }700-}701-638 #[derive(Copy, Clone, PartialEq, Eq, ValueEnum)]639 pub enum FileType {640 #[value(alias = "f")]641 File,143 unmodified linesmodified:tests/testenv/mod.rs+1 added
184 unmodified lines185 self.temp_dir.path().to_path_buf()186 }187 188 /// Get the path of the fd executable.189+ #[cfg_attr(windows, allow(unused))]190 pub fn test_exe(&self) -> &PathBuf {191 &self.fd_exe192 }193 128 unmodified linesmodified:tests/tests.rs+1 added-1 removed
2206 unmodified lines2207 fs::create_dir(&root).unwrap();2208 std::env::set_current_dir(&root).unwrap();2209 fs::remove_dir(&root).unwrap();2210 2211- let output = std::process::Command::new(&te.test_exe())2211+ let output = std::process::Command::new(te.test_exe())2212 .arg("query")2213 .arg(te.test_root())2214 .output()2215 .unwrap();5 unmodified linesmodified:Cargo.lock+6 added-6 removed
111 unmodified lines112 ]113 114 [[package]]115 name = "clap"116-version = "4.0.18"116+version = "4.0.22"117 source = "registry+https://github.com/rust-lang/crates.io-index"118-checksum = "335867764ed2de42325fafe6d18b8af74ba97ee0c590fa016f157535b42ab04b"118+checksum = "91b9970d7505127a162fdaa9b96428d28a479ba78c9ec7550a63a5d9863db682"119 dependencies = [120 "atty",121 "bitflags",122 "clap_derive",5 unmodified lines128 ]129 130 [[package]]131 name = "clap_complete"132-version = "4.0.3"132+version = "4.0.5"133 source = "registry+https://github.com/rust-lang/crates.io-index"134-checksum = "dfe581a2035db4174cdbdc91265e1aba50f381577f0510d0ad36c7bc59cc84a3"134+checksum = "96b0fba905b035a30d25c1b585bf1171690712fbb0ad3ac47214963aa4acc36c"135 dependencies = [136 "clap",137 ]138 139 [[package]]140 name = "clap_derive"141-version = "4.0.18"141+version = "4.0.21"142 source = "registry+https://github.com/rust-lang/crates.io-index"143-checksum = "16a1b0f6422af32d5da0c58e2703320f379216ee70198241c84173a8c5ac28f3"143+checksum = "0177313f9f02afc995627906bbd8967e2be069f5261954222dac78290c2b9014"144 dependencies = [145 "heck",146 "proc-macro-error",147 "proc-macro2",970 unmodified linesmodified:Cargo.toml+2 added-2 removed
48 unmodified lines495051525353545556565758596029 unmodified lines48 unmodified linesnormpath = "0.3.2"chrono = "0.4"once_cell = "1.15.0"crossbeam-channel = "0.5.6"clap_complete = {version = "4.0", optional = true}clap_complete = {version = "4.0.5", optional = true}
[dependencies.clap]version = "4.0.12"version = "4.0.22"features = ["suggestions", "color", "wrap_help", "cargo", "unstable-grouped", "derive"]
[target.'cfg(unix)'.dependencies]users = "0.11.0"29 unmodified lines