Simplify args::parse using clap::Arg::conflicts_with (#1198)

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
Jiahao XU 2023-07-11 23:20:51 +10:00 committed by GitHub
parent 9d4694219b
commit 65670224b8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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<binstalk::helpers::git::GitUrl>,
/// Override Cargo.toml package manifest bin-dir.
@ -242,7 +242,12 @@ pub struct Args {
/// reading from `registries.<name>.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<CompactString>,
/// 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"