Skip to content

Commit e8519ec

Browse files
committed
Fix the problem that help cannot be displayed properly
1 parent 7d7c370 commit e8519ec

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/bin/cargo/cli.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,13 @@ pub fn main(config: &mut Config) -> CliResult {
4242
}
4343
}
4444
};
45+
46+
// Global args need to be extracted before expanding aliases because the
47+
// clap code for extracting a subcommand discards global options
48+
// (appearing before the subcommand).
49+
let (expanded_args, global_args) = expand_aliases(config, args)?;
4550

46-
if args.value_of("unstable-features") == Some("help") {
51+
if expanded_args.value_of("unstable-features") == Some("help") {
4752
let options = CliUnstable::help();
4853
let non_hidden_options: Vec<(String, String)> = options
4954
.iter()
@@ -95,20 +100,20 @@ Run with 'cargo -Z [FLAG] [SUBCOMMAND]'",
95100
return Ok(());
96101
}
97102

98-
let is_verbose = args.occurrences_of("verbose") > 0;
103+
let is_verbose = expanded_args.occurrences_of("verbose") > 0;
99104
if args.is_present("version") {
100105
let version = get_version_string(is_verbose);
101106
drop_print!(config, "{}", version);
102107
return Ok(());
103108
}
104109

105-
if let Some(code) = args.value_of("explain") {
110+
if let Some(code) = expanded_args.value_of("explain") {
106111
let mut procss = config.load_global_rustc(None)?.process();
107112
procss.arg("--explain").arg(code).exec()?;
108113
return Ok(());
109114
}
110115

111-
if args.is_present("list") {
116+
if expanded_args.is_present("list") {
112117
drop_println!(config, "Installed Commands:");
113118
for (name, command) in list_commands(config) {
114119
let known_external_desc = KNOWN_EXTERNAL_COMMAND_DESCRIPTIONS.get(name.as_str());
@@ -140,10 +145,6 @@ Run with 'cargo -Z [FLAG] [SUBCOMMAND]'",
140145
return Ok(());
141146
}
142147

143-
// Global args need to be extracted before expanding aliases because the
144-
// clap code for extracting a subcommand discards global options
145-
// (appearing before the subcommand).
146-
let (expanded_args, global_args) = expand_aliases(config, args, vec![])?;
147148
let (cmd, subcommand_args) = match expanded_args.subcommand() {
148149
(cmd, Some(args)) => (cmd, args),
149150
_ => {

0 commit comments

Comments
 (0)