1
use std::io;
2

            
3
use clap::{Parser, Subcommand};
4

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

            
13
#[derive(Subcommand, Debug)]
14
enum Command {
15
    /// Delete orphaned local branches (default when no subcommand is given).
16
    Run {
17
        /// Continue without confirmation.
18
        #[arg(short, long)]
19
        yes: bool,
20
    },
21
    /// Install post-merge & post-rewrite hook to automatically run git-snip.
22
    Install,
23
}
24

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

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

            
34
    if let Err(err) = result {
35
        eprintln!("Error: {err}");
36
        std::process::exit(1);
37
    }
38
}
39

            
40
#[cfg(test)]
41
mod tests {
42
    use super::*;
43
    use clap::CommandFactory;
44

            
45
    #[test]
46
2
    fn verify_cli() {
47
2
        Cli::command().debug_assert()
48
2
    }
49
}