use {anyhow::Result, argh::FromArgs};
const APP_NAME: &str = env!("CARGO_PKG_NAME");
const APP_VERSION: &str = env!("CARGO_PKG_VERSION");
mod commit;
mod config;
mod hook;
mod repo;
#[derive(FromArgs)]
struct Args {
#[argh(switch, short = 'i')]
install: bool,
#[argh(switch, short = 'u')]
uninstall: bool,
#[argh(switch, short = 'V')]
version: bool,
#[argh(positional)]
args: Vec<String>,
}
fn main() -> Result<()> {
let args: Args = argh::from_env();
if args.install {
return hook::install();
}
if args.uninstall {
return hook::uninstall();
}
if args.version {
println!("{} {}", APP_NAME, APP_VERSION);
return Ok(());
}
if args.args.is_empty() {
println!("Run {} --help for more information.", APP_NAME);
return Ok(());
}
if commit::check_rebase()? {
return Ok(());
}
if args.args.len() > 1 {
if &args.args[1] == "message" {
return Ok(());
}
}
return commit::generate_commit_message(&args.args[0]);
}