Move arguments pair to different file
This commit is contained in:
parent
735ac49919
commit
bf05cd5372
32
czkawka_cli/src/arguments_pair.rs
Normal file
32
czkawka_cli/src/arguments_pair.rs
Normal file
|
@ -0,0 +1,32 @@
|
|||
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");
|
||||
}
|
||||
}
|
|
@ -1,3 +1,6 @@
|
|||
mod arguments_pair;
|
||||
|
||||
use crate::arguments_pair::ArgumentsPair;
|
||||
use czkawka_core::common_traits::*;
|
||||
use czkawka_core::*;
|
||||
use std::{env, process};
|
||||
|
@ -391,34 +394,3 @@ fn print_help() {
|
|||
"###
|
||||
);
|
||||
}
|
||||
|
||||
struct ArgumentsPair {
|
||||
command: String,
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue