commit-emoji 0.2.4

A git hook for adorning conventional commits with emoji
//
// Entirely borrowed from https://gitlab.com/ogarcia/lazycc/-/blob/master/src/main.rs
// SPDX: GPL-3.0-only
//
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;

//# https://lib.rs/crates/lazycc install a githook with -i, uninstall with -u..

/// This program is intended to be executed as a git hook so simply install it with the `-i`
/// command and run `git commit`.
#[derive(FromArgs)]
struct Args {
    /// install hook
    #[argh(switch, short = 'i')]
    install: bool,

    /// uninstall hook
    #[argh(switch, short = 'u')]
    uninstall: bool,

    /// print version information
    #[argh(switch, short = 'V')]
    version: bool,

    /// prepare commit message arguments (generated by git)
    #[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 there is a rebase in progress do not show the conventional commits options
    if commit::check_rebase()? {
        return Ok(());
    }

    // If git has message do not show the conventional commits options
    if args.args.len() > 1 {
        if &args.args[1] == "message" {
            return Ok(());
        }
    }

    return commit::generate_commit_message(&args.args[0]);
}