From 6a809efba60541f8019dff1165717153c11e1ec8 Mon Sep 17 00:00:00 2001 From: Yehuda Katz + Carl Lerche Date: Mon, 16 Jun 2014 14:51:19 -0700 Subject: [PATCH] Make `cargo foo` work --- src/bin/cargo.rs | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/bin/cargo.rs b/src/bin/cargo.rs index 96f2ecb62..8646a6adb 100644 --- a/src/bin/cargo.rs +++ b/src/bin/cargo.rs @@ -9,11 +9,12 @@ extern crate log; use hammer::{FlagConfig,FlagConfiguration}; use std::os; +use std::io::process::{Command,InheritFd,ExitStatus,ExitSignal}; use serialize::Encodable; use cargo::{NoFlags,execute_main_without_stdin,handle_error}; use cargo::core::errors::{CLIError,CLIResult,ToResult}; use cargo::util::important_paths::find_project; -use cargo::util::config; +use cargo::util::{ToCLI,Wrap,config,io_error,simple_human}; fn main() { execute(); @@ -32,7 +33,7 @@ struct ProjectLocation { fn execute() { debug!("executing; cmd=cargo; args={}", os::args()); - let (cmd, _) = match process(os::args()) { + let (cmd, args) = match process(os::args()) { Ok((cmd, args)) => (cmd, args), Err(err) => return handle_error(err) }; @@ -50,9 +51,18 @@ fn execute() { execute_main_without_stdin(locate_project) } else { - // TODO: Handle automatic dispatching to cargo-* - debug!("unknown command"); - println!("Automatic execing of cargo-* commands has not yet been implemented. Call cargo-* commands directly for now"); + let command = Command::new(format!("cargo-{}", cmd)) + .args(args.as_slice()) + .stdin(InheritFd(0)) + .stdout(InheritFd(1)) + .stderr(InheritFd(2)) + .status(); + + match command.map_err(|_| simple_human("No such subcommand")) { + Ok(ExitStatus(0)) => (), + Ok(ExitStatus(i)) | Ok(ExitSignal(i)) => handle_error(simple_human("").to_cli(i as uint)), + Err(err) => handle_error(err.to_cli(127)) + } } } -- 2.30.2