mirror of
https://github.com/TECHNOFAB11/pay-respects.git
synced 2025-12-17 00:33:52 +01:00
refactor: initialization
This commit is contained in:
parent
b6b4afc226
commit
89be82307b
3 changed files with 75 additions and 62 deletions
25
src/args.rs
25
src/args.rs
|
|
@ -1,22 +1,20 @@
|
|||
use crate::shell::initialization;
|
||||
use crate::shell::{initialization, Init};
|
||||
use colored::Colorize;
|
||||
|
||||
|
||||
pub enum Status {
|
||||
Continue,
|
||||
Exit, // version, help, etc.
|
||||
Error,
|
||||
}
|
||||
|
||||
// returns true if should exit
|
||||
pub fn handle_args() -> Status {
|
||||
use Status::*;
|
||||
let args = std::env::args().collect::<Vec<String>>();
|
||||
if args.len() <= 1 {
|
||||
return Continue;
|
||||
}
|
||||
let mut auto_aliasing = String::new();
|
||||
let mut shell = String::new();
|
||||
let mut cnf = true;
|
||||
let mut init = Init::new();
|
||||
let mut index = 1;
|
||||
while index < args.len() {
|
||||
match args[index].as_str() {
|
||||
|
|
@ -31,35 +29,36 @@ pub fn handle_args() -> Status {
|
|||
"-a" | "--alias" => {
|
||||
if args.len() > index + 1 {
|
||||
if args[index + 1].starts_with('-') {
|
||||
auto_aliasing = String::from("f");
|
||||
init.alias = String::from("f");
|
||||
} else {
|
||||
auto_aliasing = args[index + 1].clone();
|
||||
init.alias = args[index + 1].clone();
|
||||
index += 1;
|
||||
}
|
||||
} else {
|
||||
auto_aliasing = String::from("f");
|
||||
init.alias = String::from("f");
|
||||
}
|
||||
init.auto_alias = true;
|
||||
index += 1;
|
||||
}
|
||||
"--noncf" => {
|
||||
cnf = false;
|
||||
init.cnf = false;
|
||||
index += 1
|
||||
}
|
||||
_ => {
|
||||
shell = args[index].clone();
|
||||
init.shell = args[index].clone();
|
||||
index += 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if shell.is_empty() {
|
||||
if init.shell.is_empty() {
|
||||
eprintln!("{}", t!("no-shell"));
|
||||
return Error;
|
||||
}
|
||||
|
||||
let binary_path = &args[0];
|
||||
init.binary_path = args[0].clone();
|
||||
|
||||
initialization(&shell, binary_path, &auto_aliasing, cnf);
|
||||
initialization(&mut init);
|
||||
Exit
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue