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
|
#![cfg_attr(feature = "clippy", feature(plugin))]
#![cfg_attr(feature = "clippy", plugin(clippy))]
mod action;
mod cli;
mod color;
mod commit;
mod config;
mod confirm_abort;
mod confirm_rebase;
mod constants;
mod edit;
mod error;
mod exiting;
mod external_editor;
mod git_interactive;
mod help;
mod input;
mod line;
mod list;
mod process;
mod scroll;
mod show_commit;
mod view;
mod window;
mod window_size_error;
use crate::config::Config;
use crate::git_interactive::GitInteractive;
use crate::input::InputHandler;
use crate::process::{ExitStatus, Process};
use crate::view::View;
use crate::window::Window;
struct Exit {
message: String,
status: ExitStatus,
}
fn main() {
match try_main() {
Ok(code) => std::process::exit(code.to_code()),
Err(err) => {
eprintln!("{}", err.message);
std::process::exit(err.status.to_code());
},
}
}
fn try_main() -> Result<ExitStatus, Exit> {
let matches = cli::build_cli().get_matches();
let filepath = matches.value_of("rebase-todo-filepath").unwrap();
let config = match Config::new() {
Ok(c) => c,
Err(message) => {
return Err(Exit {
message,
status: ExitStatus::ConfigError,
});
},
};
let git_interactive = match GitInteractive::new_from_filepath(filepath, config.comment_char.as_str()) {
Ok(gi) => gi,
Err(message) => {
return Err(Exit {
message,
status: ExitStatus::FileReadError,
});
},
};
if git_interactive.get_lines().is_empty() {
return Err(Exit {
message: String::from("Nothing to rebase"),
status: ExitStatus::FileReadError,
});
}
let window = Window::new(&config);
let input_handler = InputHandler::new(&window);
let view = View::new(&window);
let mut process = Process::new(git_interactive, &view, &input_handler, &config);
let result = process.run();
window.end();
let exit_code = match result {
Ok(c) => c,
Err(message) => {
return Err(Exit {
message,
status: ExitStatus::FileWriteError,
});
},
};
Ok(exit_code.unwrap_or(ExitStatus::Good))
}
|