pay-respects/core/src/main.rs

87 lines
1.9 KiB
Rust
Raw Normal View History

// pay-respects: Press F to correct your command
2023-08-09 00:14:54 +02:00
// Copyright (C) 2023 iff
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
2024-11-13 16:31:31 +01:00
use sys_locale::get_locale;
2023-07-31 14:27:44 +02:00
mod args;
2024-11-23 22:51:43 +01:00
mod modes;
mod rules;
2023-07-30 18:40:18 +02:00
mod shell;
mod style;
2023-08-01 20:29:02 +02:00
mod suggestions;
mod system;
2023-07-30 18:40:18 +02:00
2024-09-25 17:55:55 +02:00
#[macro_use]
extern crate rust_i18n;
i18n!("i18n", fallback = "en", minify_key = true);
2024-12-06 19:12:40 +01:00
fn main() -> Result<(), std::io::Error> {
2023-08-12 22:39:00 +02:00
colored::control::set_override(true);
2024-12-06 19:12:40 +01:00
let init = init();
let mut data = if let Err(status) = init {
match status {
args::Status::Exit => {
return Ok(());
}
args::Status::Error => {
return Err(std::io::Error::new(
std::io::ErrorKind::InvalidInput,
"Invalid input",
));
}
_ => {
unreachable!()
}
2024-12-06 17:35:48 +01:00
}
2024-12-06 19:12:40 +01:00
} else {
init.ok().unwrap()
2024-12-06 17:35:48 +01:00
};
data.expand_command();
2024-12-07 17:50:38 +01:00
use shell::Mode::*;
2024-12-06 17:35:48 +01:00
match data.mode {
2024-12-07 17:50:38 +01:00
Suggestion => modes::suggestion(&mut data),
Cnf => modes::cnf(&mut data),
2024-12-06 17:35:48 +01:00
}
Ok(())
}
2024-12-06 19:12:40 +01:00
fn init() -> Result<shell::Data, args::Status> {
2024-11-23 00:02:34 +01:00
let locale = {
let sys_locale = get_locale().unwrap_or("en-US".to_string());
if sys_locale.len() < 2 {
2024-12-08 16:39:29 +01:00
"en-US".to_string()
2024-11-23 00:02:34 +01:00
} else {
sys_locale
}
};
2024-09-26 03:02:00 +02:00
rust_i18n::set_locale(&locale[0..2]);
2023-08-12 22:39:00 +02:00
2024-12-06 19:12:40 +01:00
let status = args::handle_args();
match status {
args::Status::Exit => {
return Err(status);
}
args::Status::Error => {
return Err(status);
}
_ => {}
2024-12-06 17:35:48 +01:00
}
2024-12-06 19:12:40 +01:00
Ok(shell::Data::init())
2023-07-30 18:40:18 +02:00
}