From 8dad57e8d64d32cca4d7cd9ada227eec8ba79bbc Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 7 Apr 2016 17:27:49 -0700 Subject: [PATCH] Add support for `cargo --explain` The error messages in the compiler are being tweaked and will likely drop the `rustc --explain` part of the error message in favor of `--explain`. In that case you're expected to basically take whatever tool you're using and pass `--explain` to it with an error code, so let's add it to Cargo as well! --- src/bin/cargo.rs | 9 +++++++++ tests/test_cargo.rs | 5 +++++ 2 files changed, 14 insertions(+) diff --git a/src/bin/cargo.rs b/src/bin/cargo.rs index be0f9b3f224..2d0a15d6bf2 100644 --- a/src/bin/cargo.rs +++ b/src/bin/cargo.rs @@ -15,6 +15,7 @@ use cargo::core::shell::Verbosity; use cargo::execute_main_without_stdin; use cargo::util::ChainError; use cargo::util::{self, CliResult, lev_distance, Config, human, CargoResult}; +use cargo::util::process_builder::process; #[derive(RustcDecodable)] pub struct Flags { @@ -23,6 +24,7 @@ pub struct Flags { flag_verbose: Option, flag_quiet: Option, flag_color: Option, + flag_explain: Option, arg_command: String, arg_args: Vec, } @@ -38,6 +40,7 @@ Options: -h, --help Display this message -V, --version Print version info and exit --list List installed commands + --explain CODE Run `rustc --explain CODE` -v, --verbose Use verbose output -q, --quiet No output printed to stdout --color WHEN Coloring: auto, always, never @@ -129,6 +132,12 @@ fn execute(flags: Flags, config: &Config) -> CliResult> { return Ok(None) } + if let Some(ref code) = flags.flag_explain { + try!(process(config.rustc()).arg("--explain").arg(code).exec() + .map_err(human)); + return Ok(None) + } + let args = match &flags.arg_command[..] { // For the commands `cargo` and `cargo help`, re-execute ourselves as // `cargo -h` so we can go through the normal process of printing the diff --git a/tests/test_cargo.rs b/tests/test_cargo.rs index ebd69024cc2..1dd5b3ed92d 100644 --- a/tests/test_cargo.rs +++ b/tests/test_cargo.rs @@ -162,3 +162,8 @@ test!(cargo_help { assert_that(cargo_process().arg("help").arg("help"), execs().with_status(0)); }); + +test!(explain { + assert_that(cargo_process().arg("--explain").arg("E0001"), + execs().with_status(0)); +});