Implement: BM::command_add()
This commit is contained in:
parent
df27e5d2a3
commit
523e6f8f66
1 changed files with 23 additions and 1 deletions
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue