Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions src/bin/cargo/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@ pub fn main(config: &mut Config) -> CliResult {
}
};

if args.value_of("unstable-features") == Some("help") {
// 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![])?;

if expanded_args.value_of("unstable-features") == Some("help") {
let options = CliUnstable::help();
let non_hidden_options: Vec<(String, String)> = options
.iter()
Expand Down Expand Up @@ -95,20 +100,20 @@ Run with 'cargo -Z [FLAG] [SUBCOMMAND]'",
return Ok(());
}

let is_verbose = args.occurrences_of("verbose") > 0;
if args.is_present("version") {
let is_verbose = expanded_args.occurrences_of("verbose") > 0;
if expanded_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());
Expand Down Expand Up @@ -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),
_ => {
Expand Down
51 changes: 51 additions & 0 deletions tests/testsuite/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}