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
        /// Overwrite existing hooks.
24
        #[arg(short, long)]
25
        force: bool,
26
    },
27
}
28

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

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

            
38
    if let Err(err) = result {
39
        eprintln!("Error: {err}");
40
        std::process::exit(1);
41
    }
42
}
43

            
44
#[cfg(test)]
45
mod tests {
46
    use super::*;
47
    use clap::CommandFactory;
48

            
49
    #[test]
50
3
    fn verify_cli() {
51
3
        Cli::command().debug_assert()
52
3
    }
53
}