1
0
Fork 0
mirror of synced 2024-05-20 20:32:59 +12:00
czkawka/czkawka_cli/src/arguments_pair.rs

33 lines
956 B
Rust
Raw Normal View History

2020-09-30 01:37:50 +13:00
use std::process;
pub struct ArgumentsPair {
pub command: String,
pub argument: Option<String>,
}
impl ArgumentsPair {
pub fn has_command(ar: &[ArgumentsPair], command: &str) -> bool {
for a in ar {
if a.command == command {
return true;
}
}
false
}
pub fn get_argument(ar: &[ArgumentsPair], command: &str, can_be_empty: bool) -> String {
for a in ar {
if a.command == command {
if !can_be_empty && a.argument == Option::None {
println!("FATAL ERROR: {} commands should have argument passed", command);
process::exit(1);
}
return match &a.argument {
Some(t) => t.clone(),
None => "".to_string(),
};
}
}
panic!("INTERNAL ERROR: Get argument should always return value");
}
}