From e8519ec09058ecd31cfc379945d90aba7dcc6e91 Mon Sep 17 00:00:00 2001 From: l00556901 Date: Wed, 22 Sep 2021 10:16:22 +0800 Subject: [PATCH 1/4] Fix the problem that help cannot be displayed properly --- src/bin/cargo/cli.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/bin/cargo/cli.rs b/src/bin/cargo/cli.rs index f9599160003..97b92afdc6c 100644 --- a/src/bin/cargo/cli.rs +++ b/src/bin/cargo/cli.rs @@ -42,8 +42,13 @@ pub fn main(config: &mut Config) -> CliResult { } } }; + + // Global args need to be extracted before expanding aliases because the + // clap code for extracting a subcommand discards global options + // (appearing before the subcommand). + let (expanded_args, global_args) = expand_aliases(config, args)?; - if args.value_of("unstable-features") == Some("help") { + if expanded_args.value_of("unstable-features") == Some("help") { let options = CliUnstable::help(); let non_hidden_options: Vec<(String, String)> = options .iter() @@ -95,20 +100,20 @@ Run with 'cargo -Z [FLAG] [SUBCOMMAND]'", return Ok(()); } - let is_verbose = args.occurrences_of("verbose") > 0; + let is_verbose = expanded_args.occurrences_of("verbose") > 0; if args.is_present("version") { let version = get_version_string(is_verbose); drop_print!(config, "{}", version); return Ok(()); } - if let Some(code) = args.value_of("explain") { + if let Some(code) = expanded_args.value_of("explain") { let mut procss = config.load_global_rustc(None)?.process(); procss.arg("--explain").arg(code).exec()?; return Ok(()); } - if args.is_present("list") { + if expanded_args.is_present("list") { drop_println!(config, "Installed Commands:"); for (name, command) in list_commands(config) { let known_external_desc = KNOWN_EXTERNAL_COMMAND_DESCRIPTIONS.get(name.as_str()); @@ -140,10 +145,6 @@ Run with 'cargo -Z [FLAG] [SUBCOMMAND]'", return Ok(()); } - // Global args need to be extracted before expanding aliases because the - // clap code for extracting a subcommand discards global options - // (appearing before the subcommand). - let (expanded_args, global_args) = expand_aliases(config, args, vec![])?; let (cmd, subcommand_args) = match expanded_args.subcommand() { (cmd, Some(args)) => (cmd, args), _ => { From 7bf9a502c0612c6e86e040dc3f0e791fb8f7873e Mon Sep 17 00:00:00 2001 From: l00556901 Date: Wed, 22 Sep 2021 10:58:16 +0800 Subject: [PATCH 2/4] fmt&Update Code --- src/bin/cargo/cli.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bin/cargo/cli.rs b/src/bin/cargo/cli.rs index 97b92afdc6c..88e3487a26d 100644 --- a/src/bin/cargo/cli.rs +++ b/src/bin/cargo/cli.rs @@ -42,11 +42,11 @@ pub fn main(config: &mut Config) -> CliResult { } } }; - + // Global args need to be extracted before expanding aliases because the // clap code for extracting a subcommand discards global options // (appearing before the subcommand). - let (expanded_args, global_args) = expand_aliases(config, args)?; + let (expanded_args, global_args) = expand_aliases(config, args, vec![])?; if expanded_args.value_of("unstable-features") == Some("help") { let options = CliUnstable::help(); From 471e11c16b34d81c7a6247ebcd48ea02f9764af5 Mon Sep 17 00:00:00 2001 From: l00556901 Date: Wed, 22 Sep 2021 11:08:32 +0800 Subject: [PATCH 3/4] fix error --- src/bin/cargo/cli.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bin/cargo/cli.rs b/src/bin/cargo/cli.rs index 88e3487a26d..627d2ea0594 100644 --- a/src/bin/cargo/cli.rs +++ b/src/bin/cargo/cli.rs @@ -101,7 +101,7 @@ Run with 'cargo -Z [FLAG] [SUBCOMMAND]'", } let is_verbose = expanded_args.occurrences_of("verbose") > 0; - if args.is_present("version") { + if expanded_args.is_present("version") { let version = get_version_string(is_verbose); drop_print!(config, "{}", version); return Ok(()); From 128ed4c9642b634e5c78497ef237a1833716e0f1 Mon Sep 17 00:00:00 2001 From: l00556901 Date: Wed, 22 Sep 2021 11:36:08 +0800 Subject: [PATCH 4/4] add test --- tests/testsuite/help.rs | 51 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/tests/testsuite/help.rs b/tests/testsuite/help.rs index 0f094e44a8c..ed91c5fcf27 100644 --- a/tests/testsuite/help.rs +++ b/tests/testsuite/help.rs @@ -138,3 +138,54 @@ fn help_alias() { .unwrap(); help_with_man_and_path("", "my-alias", "build", Path::new("")); } + +#[cargo_test] +fn alias_z_flag_help() { + cargo_process("build -Z help") + .with_stdout_contains( + " -Z allow-features[..]-- Allow *only* the listed unstable features", + ) + .run(); + + cargo_process("run -Z help") + .with_stdout_contains( + " -Z allow-features[..]-- Allow *only* the listed unstable features", + ) + .run(); + + cargo_process("check -Z help") + .with_stdout_contains( + " -Z allow-features[..]-- Allow *only* the listed unstable features", + ) + .run(); + + cargo_process("test -Z help") + .with_stdout_contains( + " -Z allow-features[..]-- Allow *only* the listed unstable features", + ) + .run(); + + cargo_process("b -Z help") + .with_stdout_contains( + " -Z allow-features[..]-- Allow *only* the listed unstable features", + ) + .run(); + + cargo_process("r -Z help") + .with_stdout_contains( + " -Z allow-features[..]-- Allow *only* the listed unstable features", + ) + .run(); + + cargo_process("c -Z help") + .with_stdout_contains( + " -Z allow-features[..]-- Allow *only* the listed unstable features", + ) + .run(); + + cargo_process("t -Z help") + .with_stdout_contains( + " -Z allow-features[..]-- Allow *only* the listed unstable features", + ) + .run(); +}