1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#![deny(warnings)]

extern crate clap;

pub mod cli;

use clap::ArgMatches;

mod branches;
use branches::Branches;

mod commands;
pub use commands::validate_git_installation;

mod error;
use error::Error;

mod options;
use options::Options;

pub fn run(matches: &ArgMatches) -> Result<(), error::Error> {
    validate_git_installation()?;

    let options = Options::new(matches);
    options.validate()?;

    let branches = Branches::merged(&options);

    if branches.string.is_empty() {
        println!("No branches to delete, you're clean!");
        return Ok(());
    }

    if !matches.is_present("yes") {
        branches.print_warning_and_prompt(&options.delete_mode)?;
    }

    let msg = branches.delete(&options);
    println!("\n{}", msg);

    Ok(())
}

pub fn print_and_exit(error: &Error) {
    println!("{}", error);
    std::process::exit(1);
}