mirror of
https://github.com/TECHNOFAB11/pay-respects.git
synced 2025-12-15 15:53:51 +01:00
chore: rearrange directories
This commit is contained in:
parent
d5fb7462e0
commit
4c9aac45a8
46 changed files with 11 additions and 18 deletions
90
core/src/args.rs
Normal file
90
core/src/args.rs
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
use crate::shell::{initialization, Init};
|
||||
use colored::Colorize;
|
||||
|
||||
pub enum Status {
|
||||
Continue,
|
||||
Exit, // version, help, etc.
|
||||
Error,
|
||||
}
|
||||
|
||||
pub fn handle_args() -> Status {
|
||||
use Status::*;
|
||||
let args = std::env::args().collect::<Vec<String>>();
|
||||
if args.len() <= 1 {
|
||||
return Continue;
|
||||
}
|
||||
let mut init = Init::new();
|
||||
let mut index = 1;
|
||||
while index < args.len() {
|
||||
match args[index].as_str() {
|
||||
"-h" | "--help" => {
|
||||
print_help();
|
||||
return Exit;
|
||||
}
|
||||
"-v" | "--version" => {
|
||||
print_version();
|
||||
return Exit;
|
||||
}
|
||||
"-a" | "--alias" => {
|
||||
if args.len() > index + 1 {
|
||||
if args[index + 1].starts_with('-') {
|
||||
init.alias = String::from("f");
|
||||
} else {
|
||||
init.alias = args[index + 1].clone();
|
||||
index += 1;
|
||||
}
|
||||
} else {
|
||||
init.alias = String::from("f");
|
||||
}
|
||||
init.auto_alias = true;
|
||||
index += 1;
|
||||
}
|
||||
"--noncf" => {
|
||||
init.cnf = false;
|
||||
index += 1
|
||||
}
|
||||
_ => {
|
||||
init.shell = args[index].clone();
|
||||
index += 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if init.shell.is_empty() {
|
||||
eprintln!("{}", t!("no-shell"));
|
||||
return Error;
|
||||
}
|
||||
|
||||
init.binary_path = args[0].clone();
|
||||
|
||||
initialization(&mut init);
|
||||
Exit
|
||||
}
|
||||
|
||||
fn print_help() {
|
||||
println!(
|
||||
"{}",
|
||||
t!(
|
||||
"help",
|
||||
usage = "pay-respects <shell> [--alias [<alias>]] [--noncf]",
|
||||
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]
|
||||
"#
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
fn print_version() {
|
||||
println!(
|
||||
"version: {}",
|
||||
option_env!("CARGO_PKG_VERSION").unwrap_or("unknown")
|
||||
);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue