Added logging
This commit is contained in:
parent
faf15d1398
commit
270c138419
68
Cargo.lock
generated
68
Cargo.lock
generated
@ -74,6 +74,16 @@ dependencies = [
|
|||||||
"os_str_bytes",
|
"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]]
|
[[package]]
|
||||||
name = "cuddle_cli"
|
name = "cuddle_cli"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
@ -82,8 +92,10 @@ dependencies = [
|
|||||||
"clap",
|
"clap",
|
||||||
"envconfig",
|
"envconfig",
|
||||||
"git2",
|
"git2",
|
||||||
|
"log",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_yaml",
|
"serde_yaml",
|
||||||
|
"simplelog",
|
||||||
"walkdir",
|
"walkdir",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -236,6 +248,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e"
|
checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
|
"serde",
|
||||||
|
"value-bag",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -244,6 +258,15 @@ version = "0.1.9"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f"
|
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]]
|
[[package]]
|
||||||
name = "openssl-probe"
|
name = "openssl-probe"
|
||||||
version = "0.1.5"
|
version = "0.1.5"
|
||||||
@ -347,6 +370,17 @@ dependencies = [
|
|||||||
"unsafe-libyaml",
|
"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]]
|
[[package]]
|
||||||
name = "strsim"
|
name = "strsim"
|
||||||
version = "0.10.0"
|
version = "0.10.0"
|
||||||
@ -379,6 +413,24 @@ version = "0.15.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb"
|
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]]
|
[[package]]
|
||||||
name = "tinyvec"
|
name = "tinyvec"
|
||||||
version = "1.6.0"
|
version = "1.6.0"
|
||||||
@ -433,12 +485,28 @@ dependencies = [
|
|||||||
"percent-encoding",
|
"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]]
|
[[package]]
|
||||||
name = "vcpkg"
|
name = "vcpkg"
|
||||||
version = "0.2.15"
|
version = "0.2.15"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
|
checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "version_check"
|
||||||
|
version = "0.9.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "walkdir"
|
name = "walkdir"
|
||||||
version = "2.3.2"
|
version = "2.3.2"
|
||||||
|
@ -13,3 +13,5 @@ walkdir = "2.3.2"
|
|||||||
git2 = { version = "0.15.0", features = ["ssh"] }
|
git2 = { version = "0.15.0", features = ["ssh"] }
|
||||||
clap = "3.2.16"
|
clap = "3.2.16"
|
||||||
envconfig = "0.10.0"
|
envconfig = "0.10.0"
|
||||||
|
log = { version = "0.4.17", features = ["kv_unstable", "serde", "std"] }
|
||||||
|
simplelog = "0.12.0"
|
||||||
|
@ -13,9 +13,9 @@ impl ShellAction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn execute(self) -> anyhow::Result<()> {
|
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: {}
|
Starting running shell action: {}
|
||||||
@ -35,13 +35,13 @@ Starting running shell action: {}
|
|||||||
let stdout_reader = BufReader::new(stdout);
|
let stdout_reader = BufReader::new(stdout);
|
||||||
let mut stdout_lines = stdout_reader.lines();
|
let mut stdout_lines = stdout_reader.lines();
|
||||||
while let Some(Ok(line)) = stdout_lines.next() {
|
while let Some(Ok(line)) = stdout_lines.next() {
|
||||||
println!("{}", line);
|
log::info!("{}", line)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
process.wait()?;
|
process.wait()?;
|
||||||
|
|
||||||
println!(
|
log::info!(
|
||||||
"
|
"
|
||||||
===
|
===
|
||||||
Finished running shell action
|
Finished running shell action
|
||||||
|
@ -35,7 +35,7 @@ impl CuddleAction {
|
|||||||
{
|
{
|
||||||
Ok(()) => {}
|
Ok(()) => {}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
eprintln!("{}", e)
|
log::error!("{}", e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -109,11 +109,11 @@ impl<'a> CuddleCli<'a> {
|
|||||||
|
|
||||||
let res = match matches.subcommand() {
|
let res = match matches.subcommand() {
|
||||||
Some(("x", exe_submatch)) => {
|
Some(("x", exe_submatch)) => {
|
||||||
println!("executing: x");
|
log::trace!("executing x");
|
||||||
|
|
||||||
match exe_submatch.subcommand() {
|
match exe_submatch.subcommand() {
|
||||||
Some((name, _action_matches)) => {
|
Some((name, _action_matches)) => {
|
||||||
println!("running action: {}", name);
|
log::trace!(action=name; "running action");
|
||||||
match self.scripts.iter().find(|ele| ele.name == name) {
|
match self.scripts.iter().find(|ele| ele.name == name) {
|
||||||
Some(script) => {
|
Some(script) => {
|
||||||
script.clone().execute();
|
script.clone().execute();
|
||||||
@ -131,8 +131,8 @@ impl<'a> CuddleCli<'a> {
|
|||||||
match res {
|
match res {
|
||||||
Ok(()) => {}
|
Ok(()) => {}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
eprintln!("{}", e);
|
|
||||||
let _ = cli.print_long_help();
|
let _ = cli.print_long_help();
|
||||||
|
return Err(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,18 +24,16 @@ pub fn extract_cuddle(config: CuddleConfig) -> anyhow::Result<Arc<Mutex<Vec<Cudd
|
|||||||
let fetch_policy = config.get_fetch_policy()?;
|
let fetch_policy = config.get_fetch_policy()?;
|
||||||
if let CuddleFetchPolicy::Always = fetch_policy {
|
if let CuddleFetchPolicy::Always = fetch_policy {
|
||||||
if let Err(res) = std::fs::remove_dir_all(curr_dir) {
|
if let Err(res) = std::fs::remove_dir_all(curr_dir) {
|
||||||
println!("{}", res);
|
panic!("{}", res)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load main cuddle file
|
// Load main cuddle file
|
||||||
let cuddle_yaml = find_root_cuddle()?;
|
let cuddle_yaml = find_root_cuddle()?;
|
||||||
// TODO: Set trace
|
log::trace!(cuddle_yaml=log::as_debug!(cuddle_yaml); "Find root cuddle");
|
||||||
println!("{}", cuddle_yaml);
|
|
||||||
let cuddle_plan = serde_yaml::from_str::<CuddlePlan>(cuddle_yaml.as_str())?;
|
|
||||||
|
|
||||||
// TODO: Set debug
|
let cuddle_plan = serde_yaml::from_str::<CuddlePlan>(cuddle_yaml.as_str())?;
|
||||||
println!("{:?}", cuddle_plan);
|
log::debug!(cuddle_plan=log::as_debug!(cuddle_yaml); "parse cuddle plan");
|
||||||
|
|
||||||
let context: Arc<Mutex<Vec<CuddleContext>>> = Arc::new(Mutex::new(Vec::new()));
|
let context: Arc<Mutex<Vec<CuddleContext>>> = Arc::new(Mutex::new(Vec::new()));
|
||||||
context.lock().unwrap().push(CuddleContext {
|
context.lock().unwrap().push(CuddleContext {
|
||||||
@ -51,7 +49,7 @@ pub fn extract_cuddle(config: CuddleConfig) -> anyhow::Result<Arc<Mutex<Vec<Cudd
|
|||||||
))
|
))
|
||||||
}
|
}
|
||||||
CuddleBase::Bool(false) => {
|
CuddleBase::Bool(false) => {
|
||||||
println!("plan is root skipping")
|
log::debug!("plan is root: skipping");
|
||||||
}
|
}
|
||||||
CuddleBase::String(parent_plan) => {
|
CuddleBase::String(parent_plan) => {
|
||||||
let destination_path = create_cuddle_local()?;
|
let destination_path = create_cuddle_local()?;
|
||||||
@ -65,13 +63,6 @@ pub fn extract_cuddle(config: CuddleConfig) -> anyhow::Result<Arc<Mutex<Vec<Cudd
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Ok(ctx) = context.clone().lock() {
|
|
||||||
// TODO: set trace
|
|
||||||
println!("{:?}", ctx)
|
|
||||||
} else {
|
|
||||||
return Err(anyhow::anyhow!("could not acquire lock"));
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(context)
|
Ok(context)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,7 +71,7 @@ fn create_cuddle_local() -> anyhow::Result<PathBuf> {
|
|||||||
curr_dir.push(".cuddle/");
|
curr_dir.push(".cuddle/");
|
||||||
|
|
||||||
if curr_dir.exists() {
|
if curr_dir.exists() {
|
||||||
println!(".cuddle already exists skipping");
|
log::debug!(".cuddle/ already exists: skipping");
|
||||||
return Ok(curr_dir);
|
return Ok(curr_dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,7 +85,7 @@ fn create_cuddle(path: PathBuf) -> anyhow::Result<PathBuf> {
|
|||||||
curr_dir.push(".cuddle/");
|
curr_dir.push(".cuddle/");
|
||||||
|
|
||||||
if curr_dir.exists() {
|
if curr_dir.exists() {
|
||||||
println!(".cuddle already exists skipping");
|
log::debug!(".cuddle/ already exists: skipping");
|
||||||
return Ok(curr_dir);
|
return Ok(curr_dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,7 +115,7 @@ fn pull_parent_cuddle_into_local(
|
|||||||
.fetch_options(fo)
|
.fetch_options(fo)
|
||||||
.clone(&parent_cuddle, &destination)?;
|
.clone(&parent_cuddle, &destination)?;
|
||||||
|
|
||||||
println!("pulled: {}", parent_cuddle);
|
log::debug!(parent_cuddle=log::as_display!(parent_cuddle); "pulled repository");
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -150,7 +141,7 @@ fn recurse_parent(path: PathBuf, context: Arc<Mutex<Vec<CuddleContext>>>) -> any
|
|||||||
))
|
))
|
||||||
}
|
}
|
||||||
CuddleBase::Bool(false) => {
|
CuddleBase::Bool(false) => {
|
||||||
println!("plan is root, finishing up");
|
log::debug!("plan is root: finishing up");
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
CuddleBase::String(parent_plan) => {
|
CuddleBase::String(parent_plan) => {
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
use config::CuddleConfig;
|
use config::CuddleConfig;
|
||||||
|
use simplelog::{ColorChoice, Config, TermLogger, TerminalMode};
|
||||||
|
|
||||||
mod actions;
|
mod actions;
|
||||||
mod cli;
|
mod cli;
|
||||||
@ -7,6 +8,15 @@ mod context;
|
|||||||
mod model;
|
mod model;
|
||||||
|
|
||||||
fn main() -> anyhow::Result<()> {
|
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 config = CuddleConfig::from_env()?;
|
||||||
|
|
||||||
let context = context::extract_cuddle(config.clone())?;
|
let context = context::extract_cuddle(config.clone())?;
|
||||||
|
Loading…
Reference in New Issue
Block a user