Skip to content

Commit d1540cc

Browse files
committed
Move arg_config and arg_unstable_feature out of command prelude
Signed-off-by: hi-rustin <[email protected]>
1 parent f9719dc commit d1540cc

File tree

2 files changed

+24
-40
lines changed

2 files changed

+24
-40
lines changed

src/bin/cargo/cli.rs

+24-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use anyhow::{anyhow, Context as _};
22
use cargo::core::shell::Shell;
33
use cargo::core::{features, CliUnstable};
44
use cargo::{self, drop_print, drop_println, CargoResult, CliResult, Config};
5-
use clap::{Arg, ArgMatches};
5+
use clap::{builder::UnknownArgumentValueParser, Arg, ArgMatches};
66
use itertools::Itertools;
77
use std::collections::HashMap;
88
use std::ffi::OsStr;
@@ -618,8 +618,29 @@ See '<cyan,bold>cargo help</> <cyan><<command>></>' for more information on a sp
618618
.help_heading(heading::MANIFEST_OPTIONS)
619619
.global(true),
620620
)
621-
.arg_config()
622-
.arg_unstable_feature()
621+
// Better suggestion for the unsupported short config flag.
622+
.arg( Arg::new("unsupported-short-config-flag")
623+
.help("")
624+
.short('c')
625+
.value_parser(UnknownArgumentValueParser::suggest_arg("--config"))
626+
.action(ArgAction::SetTrue)
627+
.global(true)
628+
.hide(true))
629+
.arg(multi_opt("config", "KEY=VALUE", "Override a configuration value").global(true))
630+
// Better suggestion for the unsupported lowercase unstable feature flag.
631+
.arg( Arg::new("unsupported-lowercase-unstable-feature-flag")
632+
.help("")
633+
.short('z')
634+
.value_parser(UnknownArgumentValueParser::suggest_arg("-Z"))
635+
.action(ArgAction::SetTrue)
636+
.global(true)
637+
.hide(true))
638+
.arg(Arg::new("unstable-features")
639+
.help("Unstable (nightly-only) flags to Cargo, see 'cargo -Z help' for details")
640+
.short('Z')
641+
.value_name("FLAG")
642+
.action(ArgAction::Append)
643+
.global(true))
623644
.subcommands(commands::builtin())
624645
}
625646

src/cargo/util/command_prelude.rs

-37
Original file line numberDiff line numberDiff line change
@@ -378,43 +378,6 @@ pub trait CommandExt: Sized {
378378
)
379379
._arg(unsupported_short_arg)
380380
}
381-
382-
fn arg_config(self) -> Self {
383-
let unsupported_short_arg = {
384-
let value_parser = UnknownArgumentValueParser::suggest_arg("--config");
385-
Arg::new("unsupported-short-config-flag")
386-
.help("")
387-
.short('c')
388-
.value_parser(value_parser)
389-
.action(ArgAction::SetTrue)
390-
.global(true)
391-
.hide(true)
392-
};
393-
self._arg(unsupported_short_arg)
394-
._arg(multi_opt("config", "KEY=VALUE", "Override a configuration value").global(true))
395-
}
396-
397-
fn arg_unstable_feature(self) -> Self {
398-
let unsupported_short_arg = {
399-
let value_parser = UnknownArgumentValueParser::suggest_arg("-Z");
400-
Arg::new("unsupported-lowercase-unstable-feature-flag")
401-
.help("")
402-
.short('z')
403-
.value_parser(value_parser)
404-
.action(ArgAction::SetTrue)
405-
.global(true)
406-
.hide(true)
407-
};
408-
self._arg(
409-
Arg::new("unstable-features")
410-
.help("Unstable (nightly-only) flags to Cargo, see 'cargo -Z help' for details")
411-
.short('Z')
412-
.value_name("FLAG")
413-
.action(ArgAction::Append)
414-
.global(true),
415-
)
416-
._arg(unsupported_short_arg)
417-
}
418381
}
419382

420383
impl CommandExt for Command {

0 commit comments

Comments
 (0)