-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.rs
More file actions
70 lines (68 loc) · 2.12 KB
/
Copy pathmain.rs
File metadata and controls
70 lines (68 loc) · 2.12 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
mod app;
pub mod buffer;
mod cli;
mod commands;
pub mod highlighter;
mod input;
mod keymap;
mod picker;
pub mod renderer;
mod terminal;
mod update;
pub mod view;
use cli::{parse_args, ParseResult, USAGE};
use std::{env, process::ExitCode};
fn main() -> ExitCode {
match parse_args(env::args().skip(1)) {
Ok(ParseResult::Help) => {
print!("{USAGE}");
ExitCode::SUCCESS
}
Ok(ParseResult::Version) => {
println!("cortex {}", env!("CARGO_PKG_VERSION"));
ExitCode::SUCCESS
}
Ok(ParseResult::CheckUpdate) => match update::check_latest(env!("CARGO_PKG_VERSION")) {
Ok(status) if status.has_update() => {
println!(
"Update available: {} -> {}",
env!("CARGO_PKG_VERSION"),
status.latest_tag().unwrap_or("unknown")
);
println!("Run install.sh again to install the latest release.");
ExitCode::SUCCESS
}
Ok(status) => {
if let Some(latest_tag) = status.latest_tag() {
println!(
"cortex {} is up to date (latest {})",
env!("CARGO_PKG_VERSION"),
latest_tag
);
} else {
println!(
"No GitHub releases found; cortex {} is the current local version",
env!("CARGO_PKG_VERSION")
);
}
ExitCode::SUCCESS
}
Err(error) => {
eprintln!("error: failed to check for updates: {error}");
ExitCode::FAILURE
}
},
Ok(ParseResult::Run(args)) => {
if let Err(error) = app::run(&args.path) {
eprintln!("error: failed to run editor: {error}");
ExitCode::FAILURE
} else {
ExitCode::SUCCESS
}
}
Err(message) => {
eprintln!("error: {message}");
ExitCode::FAILURE
}
}
}