Skip to content

Commit 5080dd3

Browse files
committed
Auto merge of #9933 - QiangHeisenberg:help, r=ehuss
Fix the problem that help cannot be displayed properly close #9883
2 parents 0121d66 + 128ed4c commit 5080dd3

File tree

2 files changed

+61
-9
lines changed

2 files changed

+61
-9
lines changed

src/bin/cargo/cli.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,12 @@ pub fn main(config: &mut Config) -> CliResult {
4343
}
4444
};
4545

46-
if args.value_of("unstable-features") == Some("help") {
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, vec![])?;
50+
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;
99-
if args.is_present("version") {
103+
let is_verbose = expanded_args.occurrences_of("verbose") > 0;
104+
if expanded_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
_ => {

tests/testsuite/help.rs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,54 @@ fn help_alias() {
138138
.unwrap();
139139
help_with_man_and_path("", "my-alias", "build", Path::new(""));
140140
}
141+
142+
#[cargo_test]
143+
fn alias_z_flag_help() {
144+
cargo_process("build -Z help")
145+
.with_stdout_contains(
146+
" -Z allow-features[..]-- Allow *only* the listed unstable features",
147+
)
148+
.run();
149+
150+
cargo_process("run -Z help")
151+
.with_stdout_contains(
152+
" -Z allow-features[..]-- Allow *only* the listed unstable features",
153+
)
154+
.run();
155+
156+
cargo_process("check -Z help")
157+
.with_stdout_contains(
158+
" -Z allow-features[..]-- Allow *only* the listed unstable features",
159+
)
160+
.run();
161+
162+
cargo_process("test -Z help")
163+
.with_stdout_contains(
164+
" -Z allow-features[..]-- Allow *only* the listed unstable features",
165+
)
166+
.run();
167+
168+
cargo_process("b -Z help")
169+
.with_stdout_contains(
170+
" -Z allow-features[..]-- Allow *only* the listed unstable features",
171+
)
172+
.run();
173+
174+
cargo_process("r -Z help")
175+
.with_stdout_contains(
176+
" -Z allow-features[..]-- Allow *only* the listed unstable features",
177+
)
178+
.run();
179+
180+
cargo_process("c -Z help")
181+
.with_stdout_contains(
182+
" -Z allow-features[..]-- Allow *only* the listed unstable features",
183+
)
184+
.run();
185+
186+
cargo_process("t -Z help")
187+
.with_stdout_contains(
188+
" -Z allow-features[..]-- Allow *only* the listed unstable features",
189+
)
190+
.run();
191+
}

0 commit comments

Comments
 (0)