cuddle-v2/cuddle_cli/src/main.rs

43 lines
898 B
Rust
Raw Normal View History

2022-08-11 02:03:19 +02:00
use std::{
env::current_dir,
sync::{Arc, Mutex},
};
2022-08-10 16:46:56 +02:00
use config::CuddleConfig;
2022-08-12 00:54:22 +02:00
use tracing::Level;
2022-08-10 16:46:56 +02:00
mod actions;
2022-08-10 12:34:04 +02:00
mod cli;
2022-08-10 16:46:56 +02:00
mod config;
2022-08-10 12:34:04 +02:00
mod context;
mod model;
2022-08-09 17:53:53 +02:00
fn main() -> anyhow::Result<()> {
2022-08-10 17:55:56 +02:00
init_logging()?;
2022-08-10 17:33:31 +02:00
2022-08-10 16:46:56 +02:00
let config = CuddleConfig::from_env()?;
2022-08-09 17:53:53 +02:00
2022-08-11 02:03:19 +02:00
match git2::Repository::open(current_dir()?) {
Ok(_) => {
let context = context::extract_cuddle(config.clone())?;
_ = cli::CuddleCli::new(context)?.execute()?;
}
Err(_) => {
// Only build bare bones cli
2022-08-12 00:54:22 +02:00
log::info!("was not opened in a repo with git, only showing bare-bones options");
2022-08-11 02:03:19 +02:00
_ = cli::CuddleCli::new(Arc::new(Mutex::new(vec![])))?.execute()?;
}
}
2022-08-09 17:53:53 +02:00
Ok(())
}
2022-08-10 17:55:56 +02:00
fn init_logging() -> anyhow::Result<()> {
2022-08-12 00:54:22 +02:00
tracing_subscriber::fmt()
.pretty()
2022-08-13 18:44:01 +02:00
.with_max_level(Level::DEBUG)
2022-08-12 00:54:22 +02:00
.init();
2022-08-10 17:55:56 +02:00
Ok(())
}