summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThayne McCombs <astrothayne@gmail.com>2022-11-08 00:03:55 -0700
committerThayne McCombs <astrothayne@gmail.com>2022-11-11 02:09:41 -0700
commit84bf65e02384845ae97dac04f89681028246e5f1 (patch)
tree1395330e7b28e3518ea5f0aa2728386b7b5243c9
parent2c3e40c9d9627141a4fd884823db52dabf4463cb (diff)
Use unit type for negating optins with clap_derive
As now supported by https://github.com/clap-rs/clap/pull/4371 and https://github.com/clap-rs/clap/pull/4459
-rw-r--r--Cargo.lock8
-rw-r--r--Cargo.toml2
-rw-r--r--src/cli.rs90
3 files changed, 28 insertions, 72 deletions
diff --git a/Cargo.lock b/Cargo.lock
index af137b4..cd9f42a 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -113,9 +113,9 @@ dependencies = [
[[package]]
name = "clap"
-version = "4.0.18"
+version = "4.0.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "335867764ed2de42325fafe6d18b8af74ba97ee0c590fa016f157535b42ab04b"
+checksum = "91b9970d7505127a162fdaa9b96428d28a479ba78c9ec7550a63a5d9863db682"
dependencies = [
"atty",
"bitflags",
@@ -138,9 +138,9 @@ dependencies = [
[[package]]
name = "clap_derive"
-version = "4.0.18"
+version = "4.0.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "16a1b0f6422af32d5da0c58e2703320f379216ee70198241c84173a8c5ac28f3"
+checksum = "0177313f9f02afc995627906bbd8967e2be069f5261954222dac78290c2b9014"
dependencies = [
"heck",
"proc-macro-error",
diff --git a/Cargo.toml b/Cargo.toml
index 6f57249..5ae8e9b 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -53,7 +53,7 @@ crossbeam-channel = "0.5.6"
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]
diff --git a/src/cli.rs b/src/cli.rs
index 004b0cb..09630a6 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -17,69 +17,6 @@ use crate::filesystem;
use crate::filter::OwnerFilter;
use crate::filter::SizeFilter;
-// Type for options that don't have any values, but are used to negate
-// earlier options
-struct Negations;
-
-impl clap::FromArgMatches for Negations {
- fn from_arg_matches(_: &ArgMatches) -> clap::error::Result<Self> {
- Ok(Negations)
- }
-
- fn update_from_arg_matches(&mut self, _: &ArgMatches) -> clap::error::Result<()> {
- Ok(())
- }
-}
-
-impl clap::Args for Negations {
- fn augment_args(cmd: Command) -> Command {
- Self::augment_args_for_update(cmd)
- }
-
- fn augment_args_for_update(cmd: Command) -> Command {
- cmd.arg(
- Arg::new("no_hidden")
- .action(ArgAction::Count)
- .long("no-hidden")
- .overrides_with("hidden")
- .hide(true)
- .long_help("Overrides --hidden."),
- )
- .arg(
- Arg::new("ignore")
- .action(ArgAction::Count)
- .long("ignore")
- .overrides_with("no_ignore")
- .hide(true)
- .long_help("Overrides --no-ignore."),
- )
- .arg(
- Arg::new("ignore_vcs")
- .action(ArgAction::Count)
- .long("ignore-vcs")
- .overrides_with("no_ignore_vcs")
- .hide(true)
- .long_help("Overrides --no-ignore-vcs."),
- )
- .arg(
- Arg::new("relative_path")
- .action(ArgAction::Count)
- .long("relative-path")
- .overrides_with("absolute_path")
- .hide(true)
- .long_help("Overrides --absolute-path."),
- )
- .arg(
- Arg::new("no_follow")
- .action(ArgAction::Count)
- .long("no-follow")
- .overrides_with("follow")
- .hide(true)
- .long_help("Overrides --follow."),
- )
- }
-}
-
#[derive(Parser)]
#[command(
name = "fd",
@@ -103,6 +40,10 @@ pub struct Opts {
)]
pub hidden: bool,
+ /// Overrides --hidden
+ #[arg(long, overrides_with = "hidden", hide = true, action = ArgAction::SetTrue)]
+ no_hidden: (),
+
/// Do not respect .(git|fd)ignore files
#[arg(
long,
@@ -113,6 +54,10 @@ pub struct Opts {
)]
pub no_ignore: bool,
+ /// Overrides --no-ignore
+ #[arg(long, overrides_with = "no_ignore", hide = true, action = ArgAction::SetTrue)]
+ ignore: (),
+
/// Do not respect .gitignore files
#[arg(
long,
@@ -122,6 +67,10 @@ pub struct Opts {
)]
pub no_ignore_vcs: bool,
+ /// Overrides --no-ignore-vcs
+ #[arg(long, overrides_with = "no_ignore_vcs", hide = true, action = ArgAction::SetTrue)]
+ ignore_vcs: (),
+
/// Do not respect .(git|fd)ignore files in parent directories
#[arg(
long,
@@ -204,6 +153,10 @@ pub struct Opts {
)]
pub absolute_path: bool,
+ /// Overrides --absolute-path
+ #[arg(long, overrides_with = "absolute_path", hide = true, action = ArgAction::SetTrue)]
+ relative_path: (),
+
/// Use a long listing format with file metadata
#[arg(
long,
@@ -227,6 +180,10 @@ pub struct Opts {
)]
pub follow: bool,
+ /// Overrides --follow
+ #[arg(long, overrides_with = "follow", hide = true, action = ArgAction::SetTrue)]
+ no_follow: (),
+
/// Search full abs. path (default: filename only)
#[arg(
long,
@@ -591,9 +548,6 @@ pub struct Opts {
#[cfg(feature = "completions")]
#[arg(long, hide = true, exclusive = true)]
gen_completions: Option<Option<Shell>>,
-
- #[clap(flatten)]
- _negations: Negations,
}
impl Opts {
@@ -673,7 +627,9 @@ impl Opts {
self.gen_completions
.map(|maybe_shell| match maybe_shell {
Some(sh) => Ok(sh),
- None => Shell::from_env().ok_or_else(|| anyhow!("Unable to get shell from environment")),
+ None => {
+ Shell::from_env().ok_or_else(|| anyhow!("Unable to get shell from environment"))
+ }
})
.transpose()
}