use core::db;
use std::process::Command;
#[cfg(not(debug_assertions))]
use human_panic::setup_panic;
#[cfg(debug_assertions)]
extern crate better_panic;
use utils::app_config::AppConfig;
use utils::error::{GitonError, Result};
fn main() -> Result<()> {
#[cfg(not(debug_assertions))]
{
setup_panic!();
}
#[cfg(debug_assertions)]
{
better_panic::Settings::debug()
.most_recent_first(false)
.lineno_suffix(true)
.verbosity(better_panic::Verbosity::Full)
.install();
}
let _guard = utils::logger::setup_logging()?;
let config_contents = include_str!("resources/default_config.toml");
AppConfig::init(Some(config_contents))?;
if AppConfig::get::<String>("openai_key")?.is_empty() {
println!("No OpenAI API key set. Please set one with `export GITON_OPENAI_KEY=<key>`");
return Ok(());
}
let cli_match = cli::cli_match();
match cli_match {
Ok(_) => {}
Err(e) => {
match e {
GitonError::Clap(_clap_error) => {
let args: Vec<String> = std::env::args().skip(1).collect();
let args_string: String = args.join(" ");
Command::new("git")
.args(args)
.spawn()
.expect("git command failed to start");
db::insert_command(args_string)?;
}
_ => {
println!("{}", e);
}
}
}
}
Ok(())
}