1
0
Fork 0
mirror of synced 2024-05-02 11:33:00 +12:00

Move arguments pair to different file

This commit is contained in:
Rafał Mikrut 2020-09-29 14:37:50 +02:00
parent 735ac49919
commit bf05cd5372
2 changed files with 35 additions and 31 deletions

View 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");
}
}

View file

@ -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");
}
}