Skip to content

Commit

Permalink
Auto merge of #2551 - alexcrichton:explain, r=brson
Browse files Browse the repository at this point in the history
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!
  • Loading branch information
bors committed Apr 21, 2016
2 parents e12d5ad 8dad57e commit b462d50
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/bin/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -23,6 24,7 @@ pub struct Flags {
flag_verbose: Option<bool>,
flag_quiet: Option<bool>,
flag_color: Option<String>,
flag_explain: Option<String>,
arg_command: String,
arg_args: Vec<String>,
}
Expand All @@ -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
Expand Down Expand Up @@ -129,6 132,12 @@ fn execute(flags: Flags, config: &Config) -> CliResult<Option<()>> {
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
Expand Down
5 changes: 5 additions & 0 deletions tests/test_cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
});

0 comments on commit b462d50

Please sign in to comment.