pay-respects/src/args.rs

60 lines
1.2 KiB
Rust
Raw Normal View History

2023-08-04 15:40:45 +02:00
use crate::shell::initialization;
2023-07-31 21:12:57 +02:00
pub fn handle_args() {
let args = std::env::args().collect::<Vec<String>>();
2023-08-04 15:40:45 +02:00
if args.len() <= 1 {
return;
}
let mut auto_aliasing = String::new();
let mut shell = String::new();
let mut index = 0;
while index < args.len() {
match args[index].as_str() {
"-h" | "--help" => {
print_help();
}
"-a" | "--alias" => {
if args.len() > index + 1 {
if args[index + 1].starts_with('-') {
auto_aliasing = String::from("f");
} else {
auto_aliasing = args[index + 1].clone();
index += 1;
}
} else {
auto_aliasing = String::from("f");
}
index += 1;
}
_ => {
shell = args[index].clone();
index += 1
}
}
}
2023-08-04 15:40:45 +02:00
if shell.is_empty() {
2024-09-25 17:55:55 +02:00
eprintln!("{}", t!("no-shell"));
2023-08-04 15:40:45 +02:00
std::process::exit(1);
}
2023-08-04 15:40:45 +02:00
let binary_path = &args[0];
initialization(&shell, binary_path, &auto_aliasing);
}
fn print_help() {
2024-09-25 17:55:55 +02:00
println!(
"{}",
t!(
"help",
manual = "pay-respects bash",
manual_example = "alias f=$(pay-respects bash)",
auto = "pay-respects bash --alias f",
auto_example = "eval $(pay-respects bash --alias f)",
auto_example_fish = "pay-respects fish --alias | source",
)
2023-08-04 15:40:45 +02:00
);
std::process::exit(0);
}