From 65670224b8b43c6f8d13a1b321fd47ce868258ba Mon Sep 17 00:00:00 2001 From: Jiahao XU Date: Tue, 11 Jul 2023 23:20:51 +1000 Subject: [PATCH] Simplify `args::parse` using `clap::Arg::conflicts_with` (#1198) Signed-off-by: Jiahao XU --- crates/bin/src/args.rs | 34 +++++++--------------------------- 1 file changed, 7 insertions(+), 27 deletions(-) diff --git a/crates/bin/src/args.rs b/crates/bin/src/args.rs index 74584025..137f2d50 100644 --- a/crates/bin/src/args.rs +++ b/crates/bin/src/args.rs @@ -101,7 +101,7 @@ pub struct Args { /// runs as if `--manifest-path $cloned_repo` is passed to binstall. /// /// This option cannot be used with `--manifest-path`. - #[clap(help_heading = "Overrides", long)] + #[clap(help_heading = "Overrides", long, conflicts_with("manifest_path"))] pub git: Option, /// Override Cargo.toml package manifest bin-dir. @@ -242,7 +242,12 @@ pub struct Args { /// reading from `registries..index`. /// /// Cannot be used with `--index`. - #[clap(help_heading = "Options", long, env = "CARGO_REGISTRY_DEFAULT")] + #[clap( + help_heading = "Options", + long, + env = "CARGO_REGISTRY_DEFAULT", + conflicts_with("index") + )] pub registry: Option, /// This option will be passed through to all `cargo-install` invocations. @@ -426,31 +431,6 @@ pub fn parse() -> Args { // Ensure no conflict let mut command = Args::command(); - #[cfg(feature = "git")] - if opts.manifest_path.is_some() && opts.git.is_some() { - command - .error( - ErrorKind::ArgumentConflict, - format_args!( - r#"Multiple override options for Cargo.toml fetching. -You cannot use --manifest-path and --git. Do one or the other."# - ), - ) - .exit(); - } - - if opts.index.is_some() && opts.registry.is_some() { - command - .error( - ErrorKind::ArgumentConflict, - format_args!( - r#"Multiple override options for registry. -You cannot use --index and --registry. Do one or the other."# - ), - ) - .exit(); - } - if opts.crate_names.len() > 1 { let option = if opts.version_req.is_some() { "version"