From a8c7cdf53be63abd5ad26901dd111da3f2acb1bd Mon Sep 17 00:00:00 2001 From: Adrian Malacoda Date: Mon, 18 Feb 2019 03:05:39 -0600 Subject: [PATCH] add a binary for shenlong that will expose some of shenlong's functionality. Currently it can detect the current project, run a command from the current project's root, and print the absolute path of the project. --- Cargo.lock | 5 +++++ Cargo.toml | 1 + src/main.rs | 29 +++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 src/main.rs diff --git a/Cargo.lock b/Cargo.lock index 2b051e1..52f3271 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -290,6 +290,10 @@ name = "scopeguard" version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "scouter" +version = "0.0.1" + [[package]] name = "shenlong" version = "0.0.1" @@ -297,6 +301,7 @@ dependencies = [ "c_str_macro 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "scouter 0.0.1", "shenlong-sys 0.0.1", ] diff --git a/Cargo.toml b/Cargo.toml index f5298a3..b659647 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,7 @@ log = "0.4.6" env_logger = "0.6.0" shenlong-sys = { path = "shenlong-sys", version = "0.0.1" } c_str_macro = "1.0.2" +scouter = { path = "scouter", version = "0.0.1" } #[build-dependencies] #cc = "1.0.28" diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..c26e0f6 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,29 @@ +use std::env; +use std::path::Path; +use scouter::Scouter; + +use std::process::Command; + +fn main() { + let path = Path::new(".").canonicalize().expect("failed to canonicalize path"); + let mut scouter = Scouter::new(path); + let project = scouter.next().expect("No supported project found"); + + let mut args = env::args(); + args.next(); + match args.next().as_ref().map(|arg| arg.as_str()) { + Some("info") => println!("{:?}", project), + Some("where") => println!("{}", project.path().display()), + Some("run") => { + Command::new(args.next().unwrap()) + .args(args) + .current_dir(project.path()) + .spawn() + .expect("command failed to start") + .wait() + .expect("failed to wait on child"); + }, + Some(_) => println!("unrecognized command"), + None => println!("{:?}", project) + } +}