2023-08-04 15:40:45 +02:00
|
|
|
use crate::shell::initialization;
|
2024-12-07 01:01:04 +01:00
|
|
|
use colored::Colorize;
|
2023-07-31 21:12:57 +02:00
|
|
|
|
2024-12-06 19:12:40 +01:00
|
|
|
pub enum Status {
|
|
|
|
|
Continue,
|
|
|
|
|
Exit, // version, help, etc.
|
|
|
|
|
Error,
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-06 17:35:48 +01:00
|
|
|
// returns true if should exit
|
2024-12-06 19:12:40 +01:00
|
|
|
pub fn handle_args() -> Status {
|
|
|
|
|
use Status::*;
|
2023-07-31 14:12:45 +02:00
|
|
|
let args = std::env::args().collect::<Vec<String>>();
|
2023-08-04 15:40:45 +02:00
|
|
|
if args.len() <= 1 {
|
2024-12-06 19:12:40 +01:00
|
|
|
return Continue;
|
2023-08-04 15:40:45 +02:00
|
|
|
}
|
|
|
|
|
let mut auto_aliasing = String::new();
|
|
|
|
|
let mut shell = String::new();
|
2024-11-23 22:51:43 +01:00
|
|
|
let mut cnf = true;
|
2024-09-26 02:34:37 +02:00
|
|
|
let mut index = 1;
|
2023-08-04 15:40:45 +02:00
|
|
|
while index < args.len() {
|
|
|
|
|
match args[index].as_str() {
|
|
|
|
|
"-h" | "--help" => {
|
|
|
|
|
print_help();
|
2024-12-06 19:12:40 +01:00
|
|
|
return Exit;
|
2023-08-04 15:40:45 +02:00
|
|
|
}
|
2024-11-16 15:54:42 +01:00
|
|
|
"-v" | "--version" => {
|
|
|
|
|
print_version();
|
2024-12-06 19:12:40 +01:00
|
|
|
return Exit;
|
2024-11-16 15:54:42 +01:00
|
|
|
}
|
2023-08-04 15:40:45 +02:00
|
|
|
"-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;
|
|
|
|
|
}
|
2024-11-23 22:51:43 +01:00
|
|
|
"--noncf" => {
|
|
|
|
|
cnf = false;
|
|
|
|
|
index += 1
|
|
|
|
|
}
|
2023-08-04 15:40:45 +02:00
|
|
|
_ => {
|
|
|
|
|
shell = args[index].clone();
|
|
|
|
|
index += 1
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-31 14:12:45 +02:00
|
|
|
|
2023-08-04 15:40:45 +02:00
|
|
|
if shell.is_empty() {
|
2024-09-25 17:55:55 +02:00
|
|
|
eprintln!("{}", t!("no-shell"));
|
2024-12-06 19:12:40 +01:00
|
|
|
return Error;
|
2023-07-31 14:12:45 +02:00
|
|
|
}
|
2023-08-04 15:40:45 +02:00
|
|
|
|
|
|
|
|
let binary_path = &args[0];
|
|
|
|
|
|
2024-11-23 22:51:43 +01:00
|
|
|
initialization(&shell, binary_path, &auto_aliasing, cnf);
|
2024-12-06 19:12:40 +01:00
|
|
|
Exit
|
2023-08-04 15:40:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn print_help() {
|
2024-09-25 17:55:55 +02:00
|
|
|
println!(
|
|
|
|
|
"{}",
|
|
|
|
|
t!(
|
|
|
|
|
"help",
|
2024-12-07 01:01:04 +01:00
|
|
|
eval = "Bash / Zsh / Fish".bold(),
|
|
|
|
|
eval_examples = r#"
|
|
|
|
|
eval "$(pay-respects bash --alias)"
|
|
|
|
|
eval "$(pay-respects zsh --alias)"
|
|
|
|
|
pay-respects fish --alias | source
|
|
|
|
|
"#,
|
|
|
|
|
manual = "Nushell / PowerShell".bold(),
|
|
|
|
|
manual_examples = r#"
|
|
|
|
|
pay-respects nushell [--alias <alias>]
|
|
|
|
|
pay-respects pwsh [--alias <alias>] [--nocnf]
|
|
|
|
|
"#
|
2024-09-25 17:55:55 +02:00
|
|
|
)
|
2023-08-04 15:40:45 +02:00
|
|
|
);
|
2023-07-31 14:12:45 +02:00
|
|
|
}
|
2024-11-16 15:54:42 +01:00
|
|
|
|
|
|
|
|
fn print_version() {
|
2024-11-16 17:36:16 +01:00
|
|
|
println!(
|
|
|
|
|
"version: {}",
|
|
|
|
|
option_env!("CARGO_PKG_VERSION").unwrap_or("unknown")
|
|
|
|
|
);
|
2024-11-16 15:54:42 +01:00
|
|
|
println!("compile features:");
|
2024-11-16 17:36:16 +01:00
|
|
|
#[cfg(feature = "runtime-rules")]
|
|
|
|
|
{
|
2024-11-22 17:28:49 +01:00
|
|
|
println!(" - runtime-rules");
|
2024-11-19 21:17:00 +01:00
|
|
|
}
|
|
|
|
|
#[cfg(feature = "request-ai")]
|
|
|
|
|
{
|
2024-11-22 17:28:49 +01:00
|
|
|
println!(" - request-ai");
|
|
|
|
|
}
|
|
|
|
|
#[cfg(feature = "libcurl")]
|
|
|
|
|
{
|
|
|
|
|
println!(" - libcurl");
|
2024-11-16 15:54:42 +01:00
|
|
|
}
|
|
|
|
|
}
|