diff --git a/Cargo.lock b/Cargo.lock index 3e96294..a3f44b7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -74,6 +74,16 @@ dependencies = [ "os_str_bytes", ] +[[package]] +name = "ctor" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdffe87e1d521a10f9696f833fe502293ea446d7f256c06128293a4119bdf4cb" +dependencies = [ + "quote", + "syn", +] + [[package]] name = "cuddle_cli" version = "0.1.0" @@ -82,8 +92,10 @@ dependencies = [ "clap", "envconfig", "git2", + "log", "serde", "serde_yaml", + "simplelog", "walkdir", ] @@ -236,6 +248,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" dependencies = [ "cfg-if", + "serde", + "value-bag", ] [[package]] @@ -244,6 +258,15 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f" +[[package]] +name = "num_threads" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2819ce041d2ee131036f4fc9d6ae7ae125a3a40e97ba64d04fe799ad9dabbb44" +dependencies = [ + "libc", +] + [[package]] name = "openssl-probe" version = "0.1.5" @@ -347,6 +370,17 @@ dependencies = [ "unsafe-libyaml", ] +[[package]] +name = "simplelog" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48dfff04aade74dd495b007c831cd6f4e0cee19c344dd9dc0884c0289b70a786" +dependencies = [ + "log", + "termcolor", + "time", +] + [[package]] name = "strsim" version = "0.10.0" @@ -379,6 +413,24 @@ version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb" +[[package]] +name = "time" +version = "0.3.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db76ff9fa4b1458b3c7f077f3ff9887394058460d21e634355b273aaf11eea45" +dependencies = [ + "itoa", + "libc", + "num_threads", + "time-macros", +] + +[[package]] +name = "time-macros" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42657b1a6f4d817cda8e7a0ace261fe0cc946cf3a80314390b22cc61ae080792" + [[package]] name = "tinyvec" version = "1.6.0" @@ -433,12 +485,28 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "value-bag" +version = "1.0.0-alpha.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2209b78d1249f7e6f3293657c9779fe31ced465df091bbd433a1cf88e916ec55" +dependencies = [ + "ctor", + "version_check", +] + [[package]] name = "vcpkg" version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + [[package]] name = "walkdir" version = "2.3.2" diff --git a/cuddle_cli/Cargo.toml b/cuddle_cli/Cargo.toml index 98b1eb8..b55aa65 100644 --- a/cuddle_cli/Cargo.toml +++ b/cuddle_cli/Cargo.toml @@ -13,3 +13,5 @@ walkdir = "2.3.2" git2 = { version = "0.15.0", features = ["ssh"] } clap = "3.2.16" envconfig = "0.10.0" +log = { version = "0.4.17", features = ["kv_unstable", "serde", "std"] } +simplelog = "0.12.0" diff --git a/cuddle_cli/src/actions/shell.rs b/cuddle_cli/src/actions/shell.rs index a6eb17c..18b3a6c 100644 --- a/cuddle_cli/src/actions/shell.rs +++ b/cuddle_cli/src/actions/shell.rs @@ -13,9 +13,9 @@ impl ShellAction { } pub fn execute(self) -> anyhow::Result<()> { - println!("executing shell action: {}", self.path.clone()); + log::debug!("executing shell action: {}", self.path.clone()); - println!( + log::info!( " === Starting running shell action: {} @@ -35,13 +35,13 @@ Starting running shell action: {} let stdout_reader = BufReader::new(stdout); let mut stdout_lines = stdout_reader.lines(); while let Some(Ok(line)) = stdout_lines.next() { - println!("{}", line); + log::info!("{}", line) } } process.wait()?; - println!( + log::info!( " === Finished running shell action diff --git a/cuddle_cli/src/cli.rs b/cuddle_cli/src/cli.rs index 1b829f8..0790317 100644 --- a/cuddle_cli/src/cli.rs +++ b/cuddle_cli/src/cli.rs @@ -35,7 +35,7 @@ impl CuddleAction { { Ok(()) => {} Err(e) => { - eprintln!("{}", e) + log::error!("{}", e) } } } @@ -109,11 +109,11 @@ impl<'a> CuddleCli<'a> { let res = match matches.subcommand() { Some(("x", exe_submatch)) => { - println!("executing: x"); + log::trace!("executing x"); match exe_submatch.subcommand() { Some((name, _action_matches)) => { - println!("running action: {}", name); + log::trace!(action=name; "running action"); match self.scripts.iter().find(|ele| ele.name == name) { Some(script) => { script.clone().execute(); @@ -131,8 +131,8 @@ impl<'a> CuddleCli<'a> { match res { Ok(()) => {} Err(e) => { - eprintln!("{}", e); let _ = cli.print_long_help(); + return Err(e); } } } diff --git a/cuddle_cli/src/context.rs b/cuddle_cli/src/context.rs index 44f74a0..bfa5518 100644 --- a/cuddle_cli/src/context.rs +++ b/cuddle_cli/src/context.rs @@ -24,18 +24,16 @@ pub fn extract_cuddle(config: CuddleConfig) -> anyhow::Result(cuddle_yaml.as_str())?; + log::trace!(cuddle_yaml=log::as_debug!(cuddle_yaml); "Find root cuddle"); - // TODO: Set debug - println!("{:?}", cuddle_plan); + let cuddle_plan = serde_yaml::from_str::(cuddle_yaml.as_str())?; + log::debug!(cuddle_plan=log::as_debug!(cuddle_yaml); "parse cuddle plan"); let context: Arc>> = Arc::new(Mutex::new(Vec::new())); context.lock().unwrap().push(CuddleContext { @@ -51,7 +49,7 @@ pub fn extract_cuddle(config: CuddleConfig) -> anyhow::Result { - println!("plan is root skipping") + log::debug!("plan is root: skipping"); } CuddleBase::String(parent_plan) => { let destination_path = create_cuddle_local()?; @@ -65,13 +63,6 @@ pub fn extract_cuddle(config: CuddleConfig) -> anyhow::Result anyhow::Result { curr_dir.push(".cuddle/"); if curr_dir.exists() { - println!(".cuddle already exists skipping"); + log::debug!(".cuddle/ already exists: skipping"); return Ok(curr_dir); } @@ -94,7 +85,7 @@ fn create_cuddle(path: PathBuf) -> anyhow::Result { curr_dir.push(".cuddle/"); if curr_dir.exists() { - println!(".cuddle already exists skipping"); + log::debug!(".cuddle/ already exists: skipping"); return Ok(curr_dir); } @@ -124,7 +115,7 @@ fn pull_parent_cuddle_into_local( .fetch_options(fo) .clone(&parent_cuddle, &destination)?; - println!("pulled: {}", parent_cuddle); + log::debug!(parent_cuddle=log::as_display!(parent_cuddle); "pulled repository"); Ok(()) } @@ -150,7 +141,7 @@ fn recurse_parent(path: PathBuf, context: Arc>>) -> any )) } CuddleBase::Bool(false) => { - println!("plan is root, finishing up"); + log::debug!("plan is root: finishing up"); return Ok(()); } CuddleBase::String(parent_plan) => { diff --git a/cuddle_cli/src/main.rs b/cuddle_cli/src/main.rs index b12fc75..f47cedf 100644 --- a/cuddle_cli/src/main.rs +++ b/cuddle_cli/src/main.rs @@ -1,4 +1,5 @@ use config::CuddleConfig; +use simplelog::{ColorChoice, Config, TermLogger, TerminalMode}; mod actions; mod cli; @@ -7,6 +8,15 @@ mod context; mod model; fn main() -> anyhow::Result<()> { + TermLogger::init( + log::LevelFilter::Info, + Config::default(), + TerminalMode::Mixed, + ColorChoice::Auto, + )?; + + log::set_max_level(log::LevelFilter::Info); + let config = CuddleConfig::from_env()?; let context = context::extract_cuddle(config.clone())?;