From b6edd331cb591b80cf0013e02efdbb8adac0ae73 Mon Sep 17 00:00:00 2001 From: hi-rustin Date: Tue, 10 Oct 2023 08:44:17 +0800 Subject: [PATCH] Move arg_config and arg_unstable_feature out of command prelude Signed-off-by: hi-rustin --- src/bin/cargo/cli.rs | 26 ++++++++++++++++++---- src/cargo/util/command_prelude.rs | 37 ------------------------------- 2 files changed, 22 insertions(+), 41 deletions(-) diff --git a/src/bin/cargo/cli.rs b/src/bin/cargo/cli.rs index 3189a789c581..71a53c8a3955 100644 --- a/src/bin/cargo/cli.rs +++ b/src/bin/cargo/cli.rs @@ -2,7 +2,7 @@ use anyhow::{anyhow, Context as _}; use cargo::core::shell::Shell; use cargo::core::{features, CliUnstable}; use cargo::{self, drop_print, drop_println, CargoResult, CliResult, Config}; -use clap::{Arg, ArgMatches}; +use clap::{builder::UnknownArgumentValueParser, Arg, ArgMatches}; use itertools::Itertools; use std::collections::HashMap; use std::ffi::OsStr; @@ -618,11 +618,29 @@ See 'cargo help <>' for more information on a sp .help_heading(heading::MANIFEST_OPTIONS) .global(true), ) - .arg_config() - .arg_unstable_feature() + .arg( Arg::new("unsupported-short-config-flag") + .help("") + .short('c') + .value_parser(UnknownArgumentValueParser::suggest_arg("--config")) + .action(ArgAction::SetTrue) + .global(true) + .hide(true)) + .arg(multi_opt("config", "KEY=VALUE", "Override a configuration value").global(true)) + .arg( Arg::new("unsupported-lowercase-unstable-feature-flag") + .help("") + .short('z') + .value_parser(UnknownArgumentValueParser::suggest_arg("-Z")) + .action(ArgAction::SetTrue) + .global(true) + .hide(true)) + .arg(Arg::new("unstable-features") + .help("Unstable (nightly-only) flags to Cargo, see 'cargo -Z help' for details") + .short('Z') + .value_name("FLAG") + .action(ArgAction::Append) + .global(true)) .subcommands(commands::builtin()) } - /// Delay loading [`Config`] until access. /// /// In the common path, the [`Config`] is dependent on CLI parsing and shouldn't be loaded until diff --git a/src/cargo/util/command_prelude.rs b/src/cargo/util/command_prelude.rs index 09857b76f580..a8b8e31c7eb4 100644 --- a/src/cargo/util/command_prelude.rs +++ b/src/cargo/util/command_prelude.rs @@ -378,43 +378,6 @@ pub trait CommandExt: Sized { ) ._arg(unsupported_short_arg) } - - fn arg_config(self) -> Self { - let unsupported_short_arg = { - let value_parser = UnknownArgumentValueParser::suggest_arg("--config"); - Arg::new("unsupported-short-config-flag") - .help("") - .short('c') - .value_parser(value_parser) - .action(ArgAction::SetTrue) - .global(true) - .hide(true) - }; - self._arg(unsupported_short_arg) - ._arg(multi_opt("config", "KEY=VALUE", "Override a configuration value").global(true)) - } - - fn arg_unstable_feature(self) -> Self { - let unsupported_short_arg = { - let value_parser = UnknownArgumentValueParser::suggest_arg("-Z"); - Arg::new("unsupported-lowercase-unstable-feature-flag") - .help("") - .short('z') - .value_parser(value_parser) - .action(ArgAction::SetTrue) - .global(true) - .hide(true) - }; - self._arg( - Arg::new("unstable-features") - .help("Unstable (nightly-only) flags to Cargo, see 'cargo -Z help' for details") - .short('Z') - .value_name("FLAG") - .action(ArgAction::Append) - .global(true), - ) - ._arg(unsupported_short_arg) - } } impl CommandExt for Command {