From bf05cd53722aed5a348db653f45c93a4e6a93f91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Mikrut?= Date: Tue, 29 Sep 2020 14:37:50 +0200 Subject: [PATCH] Move arguments pair to different file --- czkawka_cli/src/arguments_pair.rs | 32 +++++++++++++++++++++++++++++ czkawka_cli/src/main.rs | 34 +++---------------------------- 2 files changed, 35 insertions(+), 31 deletions(-) create mode 100644 czkawka_cli/src/arguments_pair.rs diff --git a/czkawka_cli/src/arguments_pair.rs b/czkawka_cli/src/arguments_pair.rs new file mode 100644 index 0000000..43068e6 --- /dev/null +++ b/czkawka_cli/src/arguments_pair.rs @@ -0,0 +1,32 @@ +use std::process; + +pub struct ArgumentsPair { + pub command: String, + pub argument: Option, +} + +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"); + } +} diff --git a/czkawka_cli/src/main.rs b/czkawka_cli/src/main.rs index 79a02db..db730ec 100644 --- a/czkawka_cli/src/main.rs +++ b/czkawka_cli/src/main.rs @@ -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, -} - -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"); - } -}