Implement list_command
This commit is contained in:
parent
42181afde5
commit
6fcccc8297
1 changed files with 24 additions and 11 deletions
|
@ -7,9 +7,11 @@ use module::CommandResult;
|
||||||
use module::CommandEnv;
|
use module::CommandEnv;
|
||||||
|
|
||||||
use module::bm::header::build_header;
|
use module::bm::header::build_header;
|
||||||
|
use module::bm::header::get_tags_from_header;
|
||||||
use storage::json::parser::JsonHeaderParser;
|
use storage::json::parser::JsonHeaderParser;
|
||||||
use storage::parser::{Parser, FileHeaderParser};
|
use storage::parser::{Parser, FileHeaderParser};
|
||||||
use storage::file::File;
|
use storage::file::File;
|
||||||
|
use ui::file::{FilePrinter, TablePrinter};
|
||||||
|
|
||||||
use clap::ArgMatches;
|
use clap::ArgMatches;
|
||||||
use regex::Regex;
|
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 {
|
pub fn list_command(module: &Module, env: CommandEnv) -> CommandResult {
|
||||||
let tags = get_tags(env.rt, env.matches);
|
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::<Vec<File>>();
|
||||||
|
Some(f)
|
||||||
|
}).unwrap_or(Vec::<File>::new()).into_iter();
|
||||||
|
|
||||||
match matcher {
|
debug!("Printing files now");
|
||||||
Some(reg) => {
|
printer.print_files(files);
|
||||||
info!("Listing urls with matcher '{}' and with tags {:?}",
|
|
||||||
reg.as_str(),
|
|
||||||
tags);
|
|
||||||
}
|
|
||||||
None => {
|
|
||||||
info!("Listing urls with tags {:?}", tags);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue