Skip to content

Commit

Permalink
Move arg_config and arg_unstable_feature out of command prelude
Browse files Browse the repository at this point in the history
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
  • Loading branch information
Rustin170506 committed Oct 10, 2023
1 parent f9719dc commit c3f67ad
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 41 deletions.
28 changes: 24 additions & 4 deletions src/bin/cargo/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -618,11 +618,31 @@ See '<cyan,bold>cargo help</> <cyan><<command>></>' for more information on a sp
.help_heading(heading::MANIFEST_OPTIONS)
.global(true),
)
.arg_config()
.arg_unstable_feature()
// Better suggestion for the unsupported short config flag.
.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))
// Better suggestion for the unsupported lowercase unstable feature flag.
.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
Expand Down
37 changes: 0 additions & 37 deletions src/cargo/util/command_prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit c3f67ad

Please sign in to comment.