From 6fcccc82973058294844a090a7ff9ed7ee269c81 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Mon, 30 Nov 2015 19:55:13 +0100 Subject: [PATCH] Implement list_command --- src/module/bm/commands.rs | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/src/module/bm/commands.rs b/src/module/bm/commands.rs index 3385f6e4..dcb3db17 100644 --- a/src/module/bm/commands.rs +++ b/src/module/bm/commands.rs @@ -7,9 +7,11 @@ use module::CommandResult; use module::CommandEnv; use module::bm::header::build_header; +use module::bm::header::get_tags_from_header; use storage::json::parser::JsonHeaderParser; use storage::parser::{Parser, FileHeaderParser}; use storage::file::File; +use ui::file::{FilePrinter, TablePrinter}; use clap::ArgMatches; use regex::Regex; @@ -33,18 +35,29 @@ pub fn add_command(module: &Module, env: CommandEnv) -> CommandResult { pub fn list_command(module: &Module, env: CommandEnv) -> CommandResult { let tags = get_tags(env.rt, env.matches); - let matcher = get_matcher(env.rt, env.matches); + debug!("Tags: {:?}", tags); + let parser = Parser::new(JsonHeaderParser::new(None)); + let printer = TablePrinter::new(env.rt.is_verbose(), env.rt.is_debugging()); + let files = env.bk.iter_files(module, &parser).and_then(|files| { + let f = files.filter(|file| { + if tags.len() != 0 { + debug!("Checking tags of: {:?}", file.id()); + get_tags_from_header(&file.header()).iter() + .any(|t| tags.contains(t)) + } else { + true + } + }).filter(|file| { + debug!("Checking matches of: {:?}", file.id()); + get_matcher(env.rt, env.matches) + .and_then(|r| Some(file.matches_with(&r))) + .unwrap_or(true) + }).collect::>(); + Some(f) + }).unwrap_or(Vec::::new()).into_iter(); - match matcher { - Some(reg) => { - info!("Listing urls with matcher '{}' and with tags {:?}", - reg.as_str(), - tags); - } - None => { - info!("Listing urls with tags {:?}", tags); - } - } + debug!("Printing files now"); + printer.print_files(files); Ok(()) }