diff --git a/src/module/bm/commands.rs b/src/module/bm/commands.rs index 87ba320f..2d6f8bad 100644 --- a/src/module/bm/commands.rs +++ b/src/module/bm/commands.rs @@ -14,6 +14,7 @@ use ui::file::{FilePrinter, TablePrinter}; pub fn add_command(module: &Module, env: CommandEnv) -> CommandResult { use url::Url; + use module::helpers::utils::cli::get_tags; let url = env.matches.value_of("url").unwrap(); @@ -123,6 +124,8 @@ fn get_filtered_files_from_backend<'a>(module: &'a Module, env: &CommandEnv) -> Result>, ModuleError> { + use module::helpers::utils::cli::get_tags; + fn check_tags(tags: &Vec, file: &File) -> bool { if tags.len() != 0 { debug!("Checking tags of: {:?}", file.id()); @@ -159,28 +162,6 @@ fn get_filtered_files_from_backend<'a>(module: &'a Module, }) } -fn get_tags<'a>(rt: &Runtime, sub: &ArgMatches<'a, 'a>) -> Vec { - - fn reject_if_with_spaces(e: &String) -> bool { - if e.contains(" ") { - warn!("Tag contains spaces: '{}'", e); - false - } else { - true - } - } - - debug!("Fetching tags from commandline"); - sub.value_of("tags").and_then(|tags| { - Some(tags.split(",") - .into_iter() - .map(|s| s.to_string()) - .filter(|e| reject_if_with_spaces(e)) - .collect() - ) - }).or(Some(vec![])).unwrap() -} - fn get_matcher<'a>(rt: &Runtime, sub: &ArgMatches<'a, 'a>) -> Option { debug!("Fetching matcher from commandline"); if let Some(s) = sub.value_of("match") { diff --git a/src/module/helpers/mod.rs b/src/module/helpers/mod.rs index f505d688..9ed1a0a2 100644 --- a/src/module/helpers/mod.rs +++ b/src/module/helpers/mod.rs @@ -1 +1,2 @@ pub mod header; +pub mod utils; diff --git a/src/module/helpers/utils.rs b/src/module/helpers/utils.rs new file mode 100644 index 00000000..9589aa2a --- /dev/null +++ b/src/module/helpers/utils.rs @@ -0,0 +1,29 @@ +pub mod cli { + use clap::ArgMatches; + use regex::Regex; + + use runtime::Runtime; + + pub fn get_tags<'a>(rt: &Runtime, sub: &ArgMatches<'a, 'a>) -> Vec { + + fn reject_if_with_spaces(e: &String) -> bool { + if e.contains(" ") { + warn!("Tag contains spaces: '{}'", e); + false + } else { + true + } + } + + debug!("Fetching tags from commandline"); + sub.value_of("tags").and_then(|tags| { + Some(tags.split(",") + .into_iter() + .map(|s| s.to_string()) + .filter(|e| reject_if_with_spaces(e)) + .collect() + ) + }).or(Some(vec![])).unwrap() + } + +}