From 2ff5f53b98d13b5ae05c84ab2cd13c2774a6e4f1 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 16 Mar 2015 06:32:50 -0700 Subject: [PATCH] Re-fix the `help` command's implementation This was accidentally broken in a recent refactoring. Closes #1421 --- src/bin/cargo.rs | 6 +++--- tests/test_cargo.rs | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/bin/cargo.rs b/src/bin/cargo.rs index 733d0dd1cf2..e87288d1d25 100644 --- a/src/bin/cargo.rs +++ b/src/bin/cargo.rs @@ -118,14 +118,14 @@ fn execute(flags: Flags, config: &Config) -> CliResult> { // message for `cargo help` "help" if flags.arg_args[0] == "-h" || flags.arg_args[0] == "--help" => { - vec!["cargo".to_string(), "help".to_string(), "help".to_string()] + vec!["cargo".to_string(), "help".to_string(), "-h".to_string()] } // For `cargo help foo`, print out the usage message for the specified // subcommand by executing the command with the `-h` flag. "help" => { - vec!["cargo".to_string(), "help".to_string(), - flags.arg_args[0].clone()] + vec!["cargo".to_string(), flags.arg_args[0].clone(), + "-h".to_string()] } // For all other invocations, we're of the form `cargo foo args...`. We diff --git a/tests/test_cargo.rs b/tests/test_cargo.rs index e0a3615b37d..04f55c6f29e 100644 --- a/tests/test_cargo.rs +++ b/tests/test_cargo.rs @@ -105,3 +105,24 @@ test!(override_cargo_home { File::open(&toml).unwrap().read_to_string(&mut contents).unwrap(); assert!(contents.contains(r#"authors = ["foo "]"#)); }); + +test!(cargo_help { + assert_that(process(&cargo_dir().join("cargo")).unwrap(), + execs().with_status(0)); + assert_that(process(&cargo_dir().join("cargo")).unwrap().arg("help"), + execs().with_status(0)); + assert_that(process(&cargo_dir().join("cargo")).unwrap().arg("-h"), + execs().with_status(0)); + assert_that(process(&cargo_dir().join("cargo")).unwrap() + .arg("help").arg("build"), + execs().with_status(0)); + assert_that(process(&cargo_dir().join("cargo")).unwrap() + .arg("build").arg("-h"), + execs().with_status(0)); + assert_that(process(&cargo_dir().join("cargo")).unwrap() + .arg("help").arg("-h"), + execs().with_status(0)); + assert_that(process(&cargo_dir().join("cargo")).unwrap() + .arg("help").arg("help"), + execs().with_status(0)); +});