Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for cargo --explain #2551

Merged
merged 1 commit into from
Apr 21, 2016
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
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));
});