forked from tummychow/git-absorb
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.rs
More file actions
113 lines (106 loc) · 3.4 KB
/
main.rs
File metadata and controls
113 lines (106 loc) · 3.4 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#[macro_use]
extern crate slog;
use clap::{CommandFactory, Parser as _};
use clap_complete::{generate, Shell};
use clap_complete_nushell::Nushell;
use slog::Drain;
use std::io;
/// Automatically absorb staged changes into your current branch
#[derive(Debug, clap::Parser)]
#[command(version)]
struct Cli {
/// Use this commit as the base of the absorb stack
#[clap(long, short)]
base: Option<String>,
/// Don't make any actual changes
#[clap(long, short = 'n')]
dry_run: bool,
/// Generate fixups to commits not made by you
#[clap(long)]
force_author: bool,
/// Generate fixups even when on a non-branch (detached) HEAD
#[clap(long)]
force_detach: bool,
/// Skip all safety checks as if all --force-* flags were given
#[clap(long, short)]
force: bool,
/// Display more output
#[clap(long, short)]
verbose: bool,
/// Run rebase if successful
#[clap(long, short = 'r')]
and_rebase: bool,
/// Generate completions
#[clap(long, value_name = "SHELL", value_parser = ["bash", "fish", "nushell", "zsh", "powershell", "elvish"])]
gen_completions: Option<String>,
/// Match the change against the complete file
#[clap(long, short)]
whole_file: bool,
/// Only generate one fixup per commit
#[clap(long, short = 'F')]
one_fixup_per_commit: bool,
}
fn main() {
let Cli {
base,
dry_run,
force_author,
force_detach,
force,
verbose,
and_rebase,
gen_completions,
whole_file,
one_fixup_per_commit,
} = Cli::parse();
if let Some(shell) = gen_completions {
let app_name = "git-absorb";
let mut cmd = Cli::command();
match shell.as_str() {
"bash" => generate(Shell::Bash, &mut cmd, app_name, &mut io::stdout()),
"fish" => generate(Shell::Fish, &mut cmd, app_name, &mut io::stdout()),
"nushell" => generate(Nushell, &mut cmd, app_name, &mut io::stdout()),
"zsh" => generate(Shell::Zsh, &mut cmd, app_name, &mut io::stdout()),
"powershell" => generate(Shell::PowerShell, &mut cmd, app_name, &mut io::stdout()),
"elvish" => generate(Shell::Elvish, &mut cmd, app_name, &mut io::stdout()),
_ => unreachable!(),
}
return;
}
let decorator = slog_term::TermDecorator::new().build();
let drain = slog_term::FullFormat::new(decorator).build().fuse();
let drain = std::sync::Mutex::new(drain).fuse();
let drain = slog::LevelFilter::new(
drain,
if verbose {
slog::Level::Debug
} else {
slog::Level::Info
},
)
.fuse();
let mut logger = slog::Logger::root(drain, o!());
if verbose {
logger = logger.new(o!(
"module" => slog::FnValue(|record| record.module()),
"line" => slog::FnValue(|record| record.line()),
));
}
if let Err(e) = git_absorb::run(
&logger,
&git_absorb::Config {
dry_run,
force_author: force_author || force,
force_detach: force_detach || force,
base: base.as_deref(),
and_rebase,
whole_file,
one_fixup_per_commit,
},
) {
crit!(logger, "absorb failed"; "err" => e.to_string());
// wait for async logger to finish writing messages
drop(logger);
::std::process::exit(1);
}
}