Implement: BM::command_add()

This commit is contained in:
Matthias Beyer 2015-12-28 00:52:59 +01:00
parent df27e5d2a3
commit 523e6f8f66

View file

@ -6,6 +6,10 @@ use clap::ArgMatches;
use runtime::Runtime;
use module::Module;
use storage::parser::FileHeaderParser;
use storage::parser::Parser;
use storage::json::parser::JsonHeaderParser;
pub struct BM<'a> {
rt: &'a Runtime<'a>,
}
@ -23,7 +27,25 @@ impl<'a> BM<'a> {
}
fn command_add(&self, matches: &ArgMatches) -> bool {
unimplemented!()
use self::header::build_header;
let parser = Parser::new(JsonHeaderParser::new(None));
let url = matches.value_of("url").map(String::from).unwrap(); // clap ensures this is present
let tags = matches.value_of("tags").and_then(|s| {
Some(s.split(",").map(String::from).collect())
}).unwrap_or(vec![]);
debug!("Building header with");
debug!(" url = '{:?}'", url);
debug!(" tags = '{:?}'", tags);
let header = build_header(url, tags);
let fileid = self.rt.store().new_file_with_header(self, header);
self.rt.store().load(&fileid).and_then(|file| {
info!("Created file in memory: {}", fileid);
Some(self.rt.store().persist(&parser, file))
}).unwrap_or(false)
}
fn command_list(&self, matches: &ArgMatches) -> bool {