git-snip 0.3.0

Snip local Git branches that do not exist on the remote.
Documentation
use std::io;

use clap::{Parser, Subcommand};

/// Delete local Git branches that have no remote counterpart.
#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
struct Cli {
    #[command(subcommand)]
    command: Option<Command>,
}

#[derive(Subcommand, Debug)]
enum Command {
    /// Delete orphaned local branches (default when no subcommand is given).
    Run {
        /// Continue without confirmation.
        #[arg(short, long)]
        yes: bool,
    },
    /// Install post-merge & post-rewrite hook to automatically run git-snip.
    Install {
        /// Overwrite existing hooks.
        #[arg(short, long)]
        force: bool,
    },
}

/// Main entry point for git-snip.
fn main() {
    let cli = Cli::parse();

    let result = match cli.command.unwrap_or(Command::Run { yes: false }) {
        Command::Run { yes } => git_snip::snip(yes, io::stdin().lock()),
        Command::Install { force } => git_snip::install_hooks(force),
    };

    if let Err(err) = result {
        eprintln!("Error: {err}");
        std::process::exit(1);
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use clap::CommandFactory;

    #[test]
    fn verify_cli() {
        Cli::command().debug_assert()
    }
}