mirror of
https://github.com/TECHNOFAB11/pay-respects.git
synced 2025-12-16 16:23:51 +01:00
refactor: data passing
This commit is contained in:
parent
94d011cdd1
commit
dae09adb76
5 changed files with 313 additions and 241 deletions
41
src/main.rs
41
src/main.rs
|
|
@ -37,9 +37,28 @@ mod requests;
|
|||
extern crate rust_i18n;
|
||||
i18n!("i18n", fallback = "en", minify_key = true);
|
||||
|
||||
fn main() {
|
||||
fn main() -> Result<(), std::io::Error>{
|
||||
colored::control::set_override(true);
|
||||
// let locale = std::env::var("LANG").unwrap_or("en_US".to_string());
|
||||
let mut data = {
|
||||
let init = init();
|
||||
if init.is_none() {
|
||||
return Ok(());
|
||||
} else {
|
||||
init.unwrap()
|
||||
}
|
||||
};
|
||||
|
||||
data.expand_command();
|
||||
use shell::Mode;
|
||||
match data.mode {
|
||||
Mode::Suggestion => modes::suggestion(&mut data),
|
||||
Mode::CNF => modes::cnf(&mut data),
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn init() -> Option<shell::Data> {
|
||||
let locale = {
|
||||
let sys_locale = get_locale().unwrap_or("en-US".to_string());
|
||||
if sys_locale.len() < 2 {
|
||||
|
|
@ -50,6 +69,11 @@ fn main() {
|
|||
};
|
||||
rust_i18n::set_locale(&locale[0..2]);
|
||||
|
||||
let exit = args::handle_args();
|
||||
if exit {
|
||||
return None;
|
||||
}
|
||||
|
||||
#[cfg(feature = "request-ai")]
|
||||
{
|
||||
if std::env::var("_PR_AI_LOCALE").is_err() {
|
||||
|
|
@ -57,16 +81,5 @@ fn main() {
|
|||
}
|
||||
}
|
||||
|
||||
args::handle_args();
|
||||
|
||||
let mode = match std::env::var("_PR_MODE") {
|
||||
Ok(mode) => mode,
|
||||
Err(_) => "suggestion".to_string(),
|
||||
};
|
||||
|
||||
match mode.as_str() {
|
||||
"suggestion" => modes::suggestion(),
|
||||
"cnf" => modes::cnf(),
|
||||
_ => {}
|
||||
}
|
||||
Some(shell::Data::init())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue