2022-08-10 17:55:56 +02:00
|
|
|
use std::fs::File;
|
|
|
|
|
2022-08-10 16:46:56 +02:00
|
|
|
use config::CuddleConfig;
|
2022-08-10 17:55:56 +02:00
|
|
|
use simplelog::{ColorChoice, CombinedLogger, Config, TermLogger, TerminalMode, WriteLogger};
|
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-10 16:46:56 +02:00
|
|
|
let context = context::extract_cuddle(config.clone())?;
|
|
|
|
_ = cli::CuddleCli::new(context)?.execute()?;
|
2022-08-09 17:53:53 +02:00
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
2022-08-10 17:55:56 +02:00
|
|
|
|
|
|
|
fn init_logging() -> anyhow::Result<()> {
|
|
|
|
let mut log_file = dirs::state_dir().ok_or(anyhow::anyhow!("could not find state_dir"))?;
|
|
|
|
log_file.push("cuddle_cli.log");
|
|
|
|
|
|
|
|
CombinedLogger::init(vec![
|
|
|
|
TermLogger::new(
|
|
|
|
log::LevelFilter::Info,
|
|
|
|
Config::default(),
|
|
|
|
TerminalMode::Mixed,
|
|
|
|
ColorChoice::Auto,
|
|
|
|
),
|
|
|
|
WriteLogger::new(
|
|
|
|
log::LevelFilter::Debug,
|
|
|
|
Config::default(),
|
|
|
|
File::create(log_file).unwrap(),
|
|
|
|
),
|
|
|
|
])?;
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|