Start adding logging in cargo command
authorCarl Lerche <me@carllerche.com>
Thu, 22 May 2014 21:03:56 +0000 (14:03 -0700)
committerCarl Lerche <me@carllerche.com>
Thu, 22 May 2014 21:03:56 +0000 (14:03 -0700)
src/bin/cargo.rs
src/cargo/lib.rs

index 800c848645c01c147b28437c2a581a7c103bde52..db3558616fd758d33bd9d151dd02551d3a6b053c 100644 (file)
@@ -1,8 +1,12 @@
+#![feature(phase)]
+
 extern crate cargo;
 extern crate toml;
 extern crate hammer;
 extern crate serialize;
 extern crate collections;
+#[phase(syntax, link)]
+extern crate log;
 
 use hammer::{FlagConfig,FlagConfiguration};
 use std::os;
@@ -27,14 +31,30 @@ struct ProjectLocation {
   on this top-level information.
 */
 fn execute() {
+    debug!("executing; cmd=cargo; args={}", os::args());
+
     let (cmd, _) = match process(os::args()) {
         Ok((cmd, args)) => (cmd, args),
         Err(err) => return handle_error(err)
     };
 
-    if cmd == "config-for-key".to_strbuf() { execute_main_without_stdin(config_for_key) }
-    else if cmd == "config-list".to_strbuf() { execute_main_without_stdin(config_list) }
-    else if cmd == "locate-project".to_strbuf() { execute_main_without_stdin(locate_project) }
+    if cmd == "config-for-key".to_strbuf() {
+        log!(4, "cmd == config-for-key");
+        execute_main_without_stdin(config_for_key)
+    }
+    else if cmd == "config-list".to_strbuf() {
+        log!(4, "cmd == config-list");
+        execute_main_without_stdin(config_list)
+    }
+    else if cmd == "locate-project".to_strbuf() {
+        log!(4, "cmd == locate-project");
+        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");
+    }
 }
 
 fn process(args: Vec<~str>) -> CLIResult<(StrBuf, Vec<StrBuf>)> {
index 93ada512ff9a01f55fd94b8ea078a92c2f9deda4..c497df8092b63f4a55ddcb4639e8cf58a8724963 100644 (file)
@@ -2,7 +2,7 @@
 #![crate_type="rlib"]
 
 #![allow(deprecated_owned_vector)]
-#![feature(macro_rules)]
+#![feature(macro_rules,phase)]
 
 extern crate collections;
 extern crate url;
@@ -11,6 +11,9 @@ extern crate serialize;
 extern crate semver;
 extern crate toml;
 
+#[phase(syntax, link)]
+extern crate log;
+
 #[cfg(test)]
 extern crate hamcrest;
 
@@ -77,6 +80,8 @@ pub fn process_executed<'a, T: Encodable<json::Encoder<'a>, io::IoError>>(result
 }
 
 pub fn handle_error(err: CLIError) {
+    log!(4, "handle_error; err={}", err);
+
     let CLIError { msg, exit_code, .. } = err;
     let _ = write!(&mut std::io::stderr(), "{}", msg);
     //detail.map(|d| write!(&mut std::io::stderr(), ":\n{}", d));