forked from gitext-rs/git-stack
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.rs
More file actions
61 lines (53 loc) · 1.49 KB
/
Copy pathmain.rs
File metadata and controls
61 lines (53 loc) · 1.49 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
#![allow(clippy::collapsible_else_if)]
#![allow(clippy::let_and_return)]
#![allow(clippy::if_same_then_else)]
#![allow(clippy::bool_to_int_with_if)]
use clap::Parser;
use proc_exit::WithCodeResultExt;
mod alias;
mod amend;
mod args;
mod config;
mod logger;
mod next;
mod ops;
mod prev;
mod reword;
mod run;
mod stack;
mod sync;
fn main() {
human_panic::setup_panic!();
let result = run();
proc_exit::exit(result);
}
fn run() -> proc_exit::ExitResult {
// clap's `get_matches` uses Failure rather than Usage, so bypass it for `get_matches_safe`.
let args = match args::Args::try_parse() {
Ok(args) => args,
Err(e) if e.use_stderr() => {
let _ = e.print();
return proc_exit::sysexits::USAGE_ERR.ok();
}
Err(e) => {
let _ = e.print();
return proc_exit::Code::SUCCESS.ok();
}
};
args.color.write_global();
let colored_stderr = !matches!(
anstream::AutoStream::choice(&std::io::stderr()),
anstream::ColorChoice::Never
);
logger::init_logging(args.verbose.clone(), colored_stderr);
if let Some(current_dir) = args.current_dir.as_deref() {
let current_dir = current_dir
.iter()
.fold(std::path::PathBuf::new(), |current, next| {
current.join(next)
});
log::trace!("CWD={}", current_dir.display());
std::env::set_current_dir(current_dir).with_code(proc_exit::sysexits::USAGE_ERR)?;
}
args.exec()
}