Added logging
This commit is contained in:
@@ -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"
|
||||
|
@@ -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
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -24,18 +24,16 @@ pub fn extract_cuddle(config: CuddleConfig) -> anyhow::Result<Arc<Mutex<Vec<Cudd
|
||||
let fetch_policy = config.get_fetch_policy()?;
|
||||
if let CuddleFetchPolicy::Always = fetch_policy {
|
||||
if let Err(res) = std::fs::remove_dir_all(curr_dir) {
|
||||
println!("{}", res);
|
||||
panic!("{}", res)
|
||||
}
|
||||
}
|
||||
|
||||
// Load main cuddle file
|
||||
let cuddle_yaml = find_root_cuddle()?;
|
||||
// TODO: Set trace
|
||||
println!("{}", cuddle_yaml);
|
||||
let cuddle_plan = serde_yaml::from_str::<CuddlePlan>(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::<CuddlePlan>(cuddle_yaml.as_str())?;
|
||||
log::debug!(cuddle_plan=log::as_debug!(cuddle_yaml); "parse cuddle plan");
|
||||
|
||||
let context: Arc<Mutex<Vec<CuddleContext>>> = Arc::new(Mutex::new(Vec::new()));
|
||||
context.lock().unwrap().push(CuddleContext {
|
||||
@@ -51,7 +49,7 @@ pub fn extract_cuddle(config: CuddleConfig) -> anyhow::Result<Arc<Mutex<Vec<Cudd
|
||||
))
|
||||
}
|
||||
CuddleBase::Bool(false) => {
|
||||
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<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)
|
||||
}
|
||||
|
||||
@@ -80,7 +71,7 @@ fn create_cuddle_local() -> anyhow::Result<PathBuf> {
|
||||
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<PathBuf> {
|
||||
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<Mutex<Vec<CuddleContext>>>) -> any
|
||||
))
|
||||
}
|
||||
CuddleBase::Bool(false) => {
|
||||
println!("plan is root, finishing up");
|
||||
log::debug!("plan is root: finishing up");
|
||||
return Ok(());
|
||||
}
|
||||
CuddleBase::String(parent_plan) => {
|
||||
|
@@ -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())?;
|
||||
|
Reference in New Issue
Block a user