Initial import of code for Notes module
This commit is contained in:
parent
1de0796507
commit
8a9f4c370e
3 changed files with 146 additions and 0 deletions
|
@ -4,6 +4,7 @@ use clap::ArgMatches;
|
||||||
|
|
||||||
pub mod bm;
|
pub mod bm;
|
||||||
pub mod helpers;
|
pub mod helpers;
|
||||||
|
pub mod notes;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Module interface, each module has to implement this.
|
* Module interface, each module has to implement this.
|
||||||
|
|
50
src/module/notes/header.rs
Normal file
50
src/module/notes/header.rs
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
/*
|
||||||
|
* Lets talk about header data first.
|
||||||
|
* We need:
|
||||||
|
*
|
||||||
|
* - tags
|
||||||
|
* - name (not unique)
|
||||||
|
*
|
||||||
|
* So an header could look like this:
|
||||||
|
*
|
||||||
|
* ```json
|
||||||
|
* {
|
||||||
|
* 'name': "kittennotes",
|
||||||
|
* 'tags': ['foo', 'bar', 'baz'],
|
||||||
|
* }
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* Nothing more is required for the header, I guess
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
use module::helpers;
|
||||||
|
use module::helpers::header as headerhelpers;
|
||||||
|
use storage::file::header::data::FileHeaderData as FHD;
|
||||||
|
use storage::file::header::spec::FileHeaderSpec as FHS;
|
||||||
|
|
||||||
|
pub fn get_spec() -> FHS {
|
||||||
|
FHS::Map { keys: vec![ helpers::spec::named_text("NAME"),
|
||||||
|
headerhelpers::tags::spec::tags_key() ] }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
pub fn build_header(name: String, tags: Vec<String>) -> FHD {
|
||||||
|
FHD::Map {
|
||||||
|
keys: vec![
|
||||||
|
FHD::Key {
|
||||||
|
name: String::from("NAME"),
|
||||||
|
value: Box::new(FHD::Text(name.clone()))
|
||||||
|
},
|
||||||
|
FHD::Key {
|
||||||
|
name: String::from("TAGS"),
|
||||||
|
value: Box::new(headerhelpers::tags::data::build_tag_array(tags))
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_tags_from_header(header: &FHD) -> Vec<String> {
|
||||||
|
headerhelpers::tags::data::get_tags_from_header(header)
|
||||||
|
}
|
||||||
|
|
95
src/module/notes/mod.rs
Normal file
95
src/module/notes/mod.rs
Normal file
|
@ -0,0 +1,95 @@
|
||||||
|
use std::fmt::{Debug, Formatter};
|
||||||
|
use std::fmt::Result as FMTResult;
|
||||||
|
|
||||||
|
mod header;
|
||||||
|
|
||||||
|
use module::Module;
|
||||||
|
use runtime::Runtime;
|
||||||
|
|
||||||
|
pub struct Notes<'a> {
|
||||||
|
rt: &'a Runtime<'a>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> Notes<'a> {
|
||||||
|
|
||||||
|
pub fn new(rt: &'a Runtime<'a>) -> Notes<'a> {
|
||||||
|
Notes {
|
||||||
|
rt: rt,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn command_add(&self, matches: &ArgMatches) -> bool {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn command_list(&self, matches: &ArgMatches) -> bool {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn command_remove(&self, matches: &ArgMatches) -> bool {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn command_add_tags(&self, matches: &ArgMatches) -> bool {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn command_rm_tags(&self, matches: &ArgMatches) -> bool {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn command_set_tags(&self, matches: &ArgMatches) -> bool {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> Module<'a> for Notes<'a> {
|
||||||
|
|
||||||
|
fn exec(&self, matches: &ArgMatches) -> bool {
|
||||||
|
match matches.subcommand_name() {
|
||||||
|
Some("add") => {
|
||||||
|
self.command_add(matches.subcommand_matches("add").unwrap())
|
||||||
|
},
|
||||||
|
|
||||||
|
Some("list") => {
|
||||||
|
self.command_list(matches.subcommand_matches("list").unwrap())
|
||||||
|
},
|
||||||
|
|
||||||
|
Some("remove") => {
|
||||||
|
self.command_remove(matches.subcommand_matches("remove").unwrap())
|
||||||
|
},
|
||||||
|
|
||||||
|
Some("add_tags") => {
|
||||||
|
self.command_add_tags(matches.subcommand_matches("add_tags").unwrap())
|
||||||
|
},
|
||||||
|
|
||||||
|
Some("rm_tags") => {
|
||||||
|
self.command_rm_tags(matches.subcommand_matches("rm_tags").unwrap())
|
||||||
|
},
|
||||||
|
|
||||||
|
Some("set_tags") => {
|
||||||
|
self.command_set_tags(matches.subcommand_matches("set_tags").unwrap())
|
||||||
|
},
|
||||||
|
|
||||||
|
Some(_) | None => {
|
||||||
|
info!("No command given, doing nothing");
|
||||||
|
false
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn name(&self) -> &'static str{
|
||||||
|
"notes"
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> Debug for Notes<'a> {
|
||||||
|
|
||||||
|
fn fmt(&self, fmt: &mut Formatter) -> FMTResult {
|
||||||
|
write!(fmt, "[Module][Notes]");
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue