diff options
author | Thayne McCombs <astrothayne@gmail.com> | 2022-10-08 23:51:45 -0600 |
---|---|---|
committer | Thayne McCombs <astrothayne@gmail.com> | 2022-10-08 23:51:45 -0600 |
commit | f4c34b81c71b8ab8185c089c8112670f849b1dd9 (patch) | |
tree | 6d304f64a050f6ed43ce31f9be02b274a7e73a13 | |
parent | a50e417c676dc867d6288aa15ef0385c7aa9cb5c (diff) |
Upgrade to clap 4.0
-rw-r--r-- | Cargo.lock | 96 | ||||
-rw-r--r-- | Cargo.toml | 5 | ||||
-rw-r--r-- | src/cli.rs | 88 | ||||
-rw-r--r-- | tests/tests.rs | 10 |
4 files changed, 110 insertions, 89 deletions
@@ -96,36 +96,34 @@ dependencies = [ [[package]] name = "clap" -version = "3.2.20" +version = "4.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23b71c3ce99b7611011217b366d923f1d0a7e07a92bb2dbf1e84508c673ca3bd" +checksum = "3b1a0a4208c6c483b952ad35c6eed505fc13b46f08f631b81e828084a9318d74" dependencies = [ "atty", "bitflags", "clap_derive", "clap_lex", - "indexmap", "once_cell", "strsim", "termcolor", "terminal_size", - "textwrap", ] [[package]] name = "clap_complete" -version = "3.2.2" +version = "4.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c09fbb00fb6e20e92f785598ecbf0c118f269737490c57af28b1ed07f392be16" +checksum = "11cba7abac9b56dfe2f035098cdb3a43946f276e6db83b72c4e692343f9aab9a" dependencies = [ "clap", ] [[package]] name = "clap_derive" -version = "3.2.18" +version = "4.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea0c8bce528c4be4da13ea6fead8965e95b6073585a2f05204bd8f4119f82a65" +checksum = "db342ce9fda24fb191e2ed4e102055a4d381c1086a06630174cd8da8d5d917ce" dependencies = [ "heck", "proc-macro-error", @@ -136,9 +134,9 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.2.3" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87eba3c8c7f42ef17f6c659fc7416d0f4758cd3e58861ee63c5fa4a4dde649e4" +checksum = "0d4198f73e42b4936b35b5bb248d81d2b595ecb170da0bac7655c54eedfa8da8" dependencies = [ "os_str_bytes", ] @@ -191,6 +189,27 @@ dependencies = [ ] [[package]] +name = "errno" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f639046355ee4f37944e44f60642c6f3a7efa3cf6b78c78a0d989a8ce6c396a1" +dependencies = [ + "errno-dragonfly", + "libc", + "winapi", +] + +[[package]] +name = "errno-dragonfly" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" +dependencies = [ + "cc", + "libc", +] + +[[package]] name = "fd-find" version = "8.4.0" dependencies = [ @@ -278,12 +297,6 @@ dependencies = [ ] [[package]] -name = "hashbrown" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db0d4cf898abf0081f964436dc980e96670a0f36863e4b83aaacdb65c9d7ccc3" - -[[package]] name = "heck" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -323,14 +336,10 @@ dependencies = [ ] [[package]] -name = "indexmap" -version = "1.9.1" +name = "io-lifetimes" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e" -dependencies = [ - "autocfg", - "hashbrown", -] +checksum = "1ea37f355c05dde75b84bba2d767906ad522e97cd9e2eef2be7a4ab7fb442c06" [[package]] name = "jemalloc-sys" @@ -366,6 +375,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8371e4e5341c3a96db127eb2465ac681ced4c433e01dd0e938adbef26ba93ba5" [[package]] +name = "linux-raw-sys" +version = "0.0.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4d2456c373231a208ad294c33dc5bff30051eafd954cd4caae83a712b12854d" + +[[package]] name = "log" version = "0.4.17" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -510,9 +525,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.40" +version = "1.0.46" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd96a1e8ed2596c337f8eae5f24924ec83f5ad5ab21ea8e455d3566c69fbcaf7" +checksum = "94e2ef8dbfc347b10c094890f778ee2e36ca9bb4262e86dc99cd217e35f3470b" dependencies = [ "unicode-ident", ] @@ -610,6 +625,20 @@ dependencies = [ ] [[package]] +name = "rustix" +version = "0.35.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72c825b8aa8010eb9ee99b75f05e10180b9278d161583034d7574c9d617aeada" +dependencies = [ + "bitflags", + "errno", + "io-lifetimes", + "libc", + "linux-raw-sys", + "windows-sys", +] + +[[package]] name = "same-file" version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -656,12 +685,12 @@ dependencies = [ [[package]] name = "terminal_size" -version = "0.1.17" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "633c1a546cee861a1a6d0dc69ebeca693bf4296661ba7852b9d21d159e0506df" +checksum = "8440c860cf79def6164e4a0a983bcc2305d82419177a0e0c71930d049e3ac5a1" dependencies = [ - "libc", - "winapi", + "rustix", + "windows-sys", ] [[package]] @@ -687,15 +716,6 @@ dependencies = [ ] [[package]] -name = "textwrap" -version = "0.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb" -dependencies = [ - "terminal_size", -] - -[[package]] name = "thiserror" version = "1.0.31" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -30,7 +30,6 @@ name = "fd" path = "src/main.rs" [build-dependencies] -clap = { version = "3.2", features = ["cargo"] } version_check = "0.9" [dependencies] @@ -50,10 +49,10 @@ dirs-next = "2.0" normpath = "0.3.2" chrono = "0.4" once_cell = "1.13.1" -clap_complete = {version = "3.2", optional = true} +clap_complete = {version = "4.0", optional = true} [dependencies.clap] -version = "3.2" +version = "4.0" features = ["suggestions", "color", "wrap_help", "cargo", "unstable-grouped", "derive"] [target.'cfg(unix)'.dependencies] @@ -4,8 +4,8 @@ use std::time::Duration; #[cfg(feature = "completions")] use anyhow::anyhow; use clap::{ - builder::RangedU64ValueParser, value_parser, AppSettings, Arg, ArgAction, ArgGroup, ArgMatches, - Command, ErrorKind, Parser, ValueEnum, + builder::RangedU64ValueParser, error::ErrorKind, value_parser, Arg, ArgAction, ArgGroup, + ArgMatches, Command, Parser, ValueEnum, }; #[cfg(feature = "completions")] use clap_complete::Shell; @@ -23,23 +23,24 @@ use crate::filter::SizeFilter; struct Negations; impl clap::FromArgMatches for Negations { - fn from_arg_matches(_: &ArgMatches) -> clap::Result<Self> { + fn from_arg_matches(_: &ArgMatches) -> clap::error::Result<Self> { Ok(Negations) } - fn update_from_arg_matches(&mut self, _: &ArgMatches) -> clap::Result<()> { + fn update_from_arg_matches(&mut self, _: &ArgMatches) -> clap::error::Result<()> { Ok(()) } } impl clap::Args for Negations { - fn augment_args(cmd: Command<'_>) -> Command<'_> { + fn augment_args(cmd: Command) -> Command { Self::augment_args_for_update(cmd) } - fn augment_args_for_update(cmd: Command<'_>) -> Command<'_> { + fn augment_args_for_update(cmd: Command) -> Command { cmd.arg( - Arg::new("no-hidden") + Arg::new("no_hidden") + .action(ArgAction::Count) .long("no-hidden") .overrides_with("hidden") .hide(true) @@ -47,27 +48,31 @@ impl clap::Args for Negations { ) .arg( Arg::new("ignore") + .action(ArgAction::Count) .long("ignore") - .overrides_with("no-ignore") + .overrides_with("no_ignore") .hide(true) .long_help("Overrides --no-ignore."), ) .arg( - Arg::new("ignore-vcs") + Arg::new("ignore_vcs") + .action(ArgAction::Count) .long("ignore-vcs") - .overrides_with("no-ignore-vcs") + .overrides_with("no_ignore_vcs") .hide(true) .long_help("Overrides --no-ignore-vcs."), ) .arg( - Arg::new("relative-path") + Arg::new("relative_path") + .action(ArgAction::Count) .long("relative-path") - .overrides_with("absolute-path") + .overrides_with("absolute_path") .hide(true) .long_help("Overrides --absolute-path."), ) .arg( - Arg::new("no-follow") + Arg::new("no_follow") + .action(ArgAction::Count) .long("no-follow") .overrides_with("follow") .hide(true) @@ -79,12 +84,12 @@ impl clap::Args for Negations { #[derive(Parser)] #[clap( version, - setting(AppSettings::DeriveDisplayOrder), dont_collapse_args_in_usage = true, after_help = "Note: `fd -h` prints a short and concise overview while `fd --help` gives all \ details.", - group(ArgGroup::new("execs").args(&["exec", "exec-batch", "list-details"]).conflicts_with_all(&[ - "max-results", "has-results", "count"])), + args_override_self = true, + group(ArgGroup::new("execs").args(&["exec", "exec_batch", "list_details"]).conflicts_with_all(&[ + "max_results", "has_results", "count"])), )] pub struct Opts { /// Search hidden files and directories @@ -121,24 +126,24 @@ pub struct Opts { /// ///Perform an unrestricted search, including ignored and hidden files. This is ///an alias for '--no-ignore --hidden'. - #[clap(long = "unrestricted", short = 'u', overrides_with_all(&["ignore", "no-hidden"]), action(ArgAction::Count), hide_short_help = true)] + #[clap(long = "unrestricted", short = 'u', overrides_with_all(&["ignore", "no_hidden"]), action(ArgAction::Count), hide_short_help = true)] rg_alias_hidden_ignore: u8, /// Case-sensitive search (default: smart case) /// ///Perform a case-sensitive search. By default, fd uses case-insensitive ///searches, unless the pattern contains an uppercase character (smart case). - #[clap(long, short = 's', action, overrides_with("ignore-case"))] + #[clap(long, short = 's', action, overrides_with("ignore_case"))] pub case_sensitive: bool, /// Case-insensitive search (default: smart case) /// /// Perform a case-insensitive search. By default, fd uses case-insensitive searches, unless /// the pattern contains an uppercase character (smart case). - #[clap(long, short = 'i', action, overrides_with("case-sensitive"))] + #[clap(long, short = 'i', action, overrides_with("case_sensitive"))] pub ignore_case: bool, /// Glob-based search (default: regular expression) /// /// Perform a glob-based search instead of a regular expression search. - #[clap(long, short = 'g', action, conflicts_with("fixed-strings"))] + #[clap(long, short = 'g', action, conflicts_with("fixed_strings"))] pub glob: bool, /// Regular-expression based search (default) /// @@ -164,7 +169,7 @@ pub struct Opts { /// for '--exec-batch ls -l' with some additional 'ls' options. This can be /// used to see more metadata, to show symlink targets and to achieve a /// deterministic sort order. - #[clap(long, short = 'l', action, conflicts_with("absolute-path"))] + #[clap(long, short = 'l', action, conflicts_with("absolute_path"))] pub list_details: bool, /// Follow symbolic links /// @@ -190,7 +195,7 @@ pub struct Opts { long = "print0", short = '0', action, - conflicts_with("list-details"), + conflicts_with("list_details"), hide_short_help = true )] pub null_separator: bool, @@ -216,13 +221,13 @@ pub struct Opts { /// /// Only show search results at the exact given depth. This is an alias for /// '--min-depth <depth> --max-depth <depth>'. - #[clap(long, value_name = "depth", hide_short_help = true, value_parser, conflicts_with_all(&["max-depth", "min-depth"]))] + #[clap(long, value_name = "depth", hide_short_help = true, value_parser, conflicts_with_all(&["max_depth", "min_depth"]))] exact_depth: Option<usize>, /// Do not travers into matching directories /// /// Do not traverse into directories that match the search criteria. If /// you want to exclude specific directories, use the '--exclude=…' option. - #[clap(long, hide_short_help = true, action, conflicts_with_all(&["size", "exact-depth"]))] + #[clap(long, hide_short_help = true, action, conflicts_with_all(&["size", "exact_depth"]))] pub prune: bool, /// Filter by type: file (f), directory (d), symlink (l), /// executable (x), empty (e), socket (s), pipe (p) @@ -296,7 +301,7 @@ pub struct Opts { long, value_name = "size", hide_short_help = true, - requires("exec-batch"), + requires("exec_batch"), value_parser = value_parser!(usize), default_value_t )] @@ -413,7 +418,7 @@ pub struct Opts { #[clap( short = '1', hide_short_help = true, - overrides_with("max-results"), + overrides_with("max_results"), action )] max_one_result: bool, @@ -429,7 +434,7 @@ pub struct Opts { short = 'q', alias = "has-results", hide_short_help = true, - conflicts_with("max-results"), + conflicts_with("max_results"), action )] pub quiet: bool, @@ -476,7 +481,7 @@ pub struct Opts { /// /// By default, relative paths are prefixed with './' when the output goes to a non /// interactive terminal (TTY). Use this flag to disable this behaviour. - #[clap(long, conflicts_with_all(&["path", "search-path"]), hide_short_help = true, action)] + #[clap(long, conflicts_with_all(&["path", "search_path"]), hide_short_help = true, action)] pub strip_cwd_prefix: bool, /// Filter by owning user and/or group /// @@ -501,7 +506,7 @@ pub struct Opts { pub one_file_system: bool, #[cfg(feature = "completions")] - #[clap(long, value_parser = value_parser!(Shell), hide = true, exclusive = true)] + #[clap(long, action, hide = true, exclusive = true)] gen_completions: Option<Option<Shell>>, #[clap(flatten)] @@ -642,13 +647,13 @@ pub struct Exec { } impl clap::FromArgMatches for Exec { - fn from_arg_matches(matches: &ArgMatches) -> clap::Result<Self> { + fn from_arg_matches(matches: &ArgMatches) -> clap::error::Result<Self> { let command = matches .grouped_values_of("exec") .map(CommandSet::new) .or_else(|| { matches - .grouped_values_of("exec-batch") + .grouped_values_of("exec_batch") .map(CommandSet::new_batch) }) .transpose() @@ -656,23 +661,23 @@ impl clap::FromArgMatches for Exec { Ok(Exec { command }) } - fn update_from_arg_matches(&mut self, matches: &ArgMatches) -> clap::Result<()> { + fn update_from_arg_matches(&mut self, matches: &ArgMatches) -> clap::error::Result<()> { *self = Self::from_arg_matches(matches)?; Ok(()) } } impl clap::Args for Exec { - fn augment_args(cmd: Command<'_>) -> Command<'_> { + fn augment_args(cmd: Command) -> Command { cmd.arg(Arg::new("exec") + .action(ArgAction::Append) .long("exec") .short('x') - .min_values(1) - .multiple_occurrences(true) + .num_args(1..) .allow_hyphen_values(true) .value_terminator(";") .value_name("cmd") - .conflicts_with("list-details") + .conflicts_with("list_details") .help("Execute a command for each search result") .long_help( "Execute a command for each search result in parallel (use --threads=1 for sequential command execution). \ @@ -696,15 +701,15 @@ impl clap::Args for Exec { ), ) .arg( - Arg::new("exec-batch") + Arg::new("exec_batch") + .action(ArgAction::Append) .long("exec-batch") .short('X') - .min_values(1) - .multiple_occurrences(true) + .num_args(1..) .allow_hyphen_values(true) .value_terminator(";") .value_name("cmd") - .conflicts_with_all(&["exec", "list-details"]) + .conflicts_with_all(&["exec", "list_details"]) .help("Execute a command with all search results at once") .long_help( "Execute the given command once, with all search results as arguments.\n\ @@ -725,7 +730,7 @@ impl clap::Args for Exec { ) } - fn augment_args_for_update(cmd: Command<'_>) -> Command<'_> { + fn augment_args_for_update(cmd: Command) -> Command { Self::augment_args(cmd) } } @@ -743,4 +748,3 @@ fn ensure_current_directory_exists(current_directory: &Path) -> anyhow::Result<( )) } } - diff --git a/tests/tests.rs b/tests/tests.rs index a55bf95..ab49543 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -1466,10 +1466,9 @@ fn test_exec_batch() { &["foo", "--exec-batch", "echo", "{}", "{}"], "error: Only one placeholder allowed for batch commands\n\ \n\ - USAGE:\n\ - fd-find [OPTIONS] [--] [PATTERN] [PATH]...\n\ + Usage: fd-find [OPTIONS] [PATTERN] [PATH]...\n\ \n\ - For more information try --help\n\ + For more information try '--help'\n\ ", ); @@ -1487,10 +1486,9 @@ fn test_exec_batch() { &["foo", "--exec-batch", "echo {}"], "error: First argument of exec-batch is expected to be a fixed executable\n\ \n\ - USAGE:\n\ - fd-find [OPTIONS] [--] [PATTERN] [PATH]...\n\ + Usage: fd-find [OPTIONS] [PATTERN] [PATH]...\n\ \n\ - For more information try --help\n\ + For more information try '--help'\n\ ", ); } |