Start adding the BM submodule
This commit is contained in:
parent
2246ae42e8
commit
750f4cd31c
4 changed files with 182 additions and 2 deletions
65
etc/cli.yml
65
etc/cli.yml
|
@ -113,6 +113,71 @@ subcommands:
|
|||
help: Sets the level of debugging information
|
||||
required: false
|
||||
|
||||
subcommands:
|
||||
- add:
|
||||
about: Add bookmark
|
||||
version: 0.1
|
||||
author: Matthias Beyer <mail@beyermatthias.de>
|
||||
args:
|
||||
- url:
|
||||
short: u
|
||||
long: url
|
||||
help: Add a new URL as bookmark
|
||||
required: true
|
||||
takes_value: true
|
||||
|
||||
- tags:
|
||||
short: t
|
||||
long: tags
|
||||
help: Add these tags to the URL
|
||||
required: false
|
||||
takes_value: true
|
||||
|
||||
- list:
|
||||
about: List bookmarks
|
||||
version: 0.1
|
||||
author: Matthias Beyer <mail@beyermatthias.de>
|
||||
args:
|
||||
- match:
|
||||
short: m
|
||||
long: match
|
||||
help: Match for regex
|
||||
required: false
|
||||
takes_value: true
|
||||
|
||||
- tags:
|
||||
short: t
|
||||
long: tags
|
||||
help: Filter for these tags
|
||||
required: false
|
||||
takes_value: true
|
||||
|
||||
- remove:
|
||||
about: Remove bookmark(s)
|
||||
version: 0.1
|
||||
author: Matthias Beyer <mail@beyermatthias.de>
|
||||
args:
|
||||
- id:
|
||||
long: id
|
||||
help: Delete Bookmark with ID
|
||||
required: false
|
||||
takes_value: true
|
||||
|
||||
- match:
|
||||
short: m
|
||||
long: match
|
||||
help: Match for regex
|
||||
required: false
|
||||
takes_value: true
|
||||
|
||||
- tags:
|
||||
short: t
|
||||
long: tags
|
||||
help: Filter for these tags
|
||||
required: false
|
||||
takes_value: true
|
||||
|
||||
|
||||
- todo:
|
||||
about: Todo module
|
||||
version: 0.1
|
||||
|
|
16
src/main.rs
16
src/main.rs
|
@ -4,14 +4,16 @@
|
|||
#[macro_use] extern crate serde_json;
|
||||
#[macro_use] extern crate glob;
|
||||
#[macro_use] extern crate uuid;
|
||||
#[macro_use] extern crate prettytable;
|
||||
#[macro_use] extern crate regex;
|
||||
extern crate config;
|
||||
extern crate regex;
|
||||
|
||||
use cli::CliConfig;
|
||||
use configuration::Configuration;
|
||||
use runtime::{ImagLogger, Runtime};
|
||||
use clap::App;
|
||||
use module::Module;
|
||||
use module::ModuleError;
|
||||
use module::bm::BMModule;
|
||||
|
||||
mod cli;
|
||||
mod configuration;
|
||||
|
@ -36,5 +38,15 @@ fn main() {
|
|||
|
||||
debug!("Runtime : {:?}", &rt);
|
||||
|
||||
if let Some(matches) = rt.config.cli_matches.subcommand_matches("bm") {
|
||||
let module : BMModule = Module::new(&rt);
|
||||
module.execute(&rt);
|
||||
module.shutdown(&rt);
|
||||
} else {
|
||||
// Err(ModuleError::mk("No commandline call"))
|
||||
info!("No commandline call...")
|
||||
}
|
||||
|
||||
|
||||
info!("Hello, world!");
|
||||
}
|
||||
|
|
99
src/module/bm/mod.rs
Normal file
99
src/module/bm/mod.rs
Normal file
|
@ -0,0 +1,99 @@
|
|||
use runtime::Runtime;
|
||||
use module::Module;
|
||||
use module::ModuleResult;
|
||||
use module::ModuleError;
|
||||
use std::path::Path;
|
||||
use std::result::Result;
|
||||
use clap::ArgMatches;
|
||||
use regex::Regex;
|
||||
|
||||
pub struct BMModule {
|
||||
path: Option<String>,
|
||||
}
|
||||
|
||||
const CALLNAMES : &'static [&'static str] = &[ "bm", "bookmark" ];
|
||||
|
||||
impl Module for BMModule {
|
||||
|
||||
fn new(rt : &Runtime) -> BMModule {
|
||||
BMModule {
|
||||
path: None
|
||||
}
|
||||
}
|
||||
|
||||
fn callnames() -> &'static [&'static str] {
|
||||
CALLNAMES
|
||||
}
|
||||
|
||||
fn name(&self) -> &'static str{
|
||||
"Bookmark"
|
||||
}
|
||||
|
||||
fn execute(&self, rt : &Runtime) -> ModuleResult {
|
||||
let cmd = rt.config.cli_matches.subcommand_matches("bm").unwrap();
|
||||
match cmd.subcommand_name() {
|
||||
Some("add") => { add(rt, cmd.subcommand_matches("add").unwrap()) }
|
||||
Some("list") => { list(rt, cmd.subcommand_matches("list").unwrap()) }
|
||||
Some("remove") => { list(rt, cmd.subcommand_matches("remove").unwrap()) }
|
||||
_ => {
|
||||
info!("Not calling any of add, list, remove");
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn shutdown(&self, rt : &Runtime) -> ModuleResult {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
fn add<'a>(rt: &Runtime, sub: &ArgMatches<'a, 'a>) -> ModuleResult {
|
||||
let url = sub.value_of("url").unwrap();
|
||||
let tags = get_tags(rt, sub);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn list<'a>(rt: &Runtime, sub: &ArgMatches<'a, 'a>) -> ModuleResult {
|
||||
let tags = get_tags(rt, sub);
|
||||
let matcher = get_matcher(rt, sub);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn remove<'a>(rt: &Runtime, sub: &ArgMatches<'a, 'a>) -> ModuleResult {
|
||||
let tags = get_tags(rt, sub);
|
||||
let matcher = get_matcher(rt, sub);
|
||||
let id = get_id(rt, sub);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn get_tags<'a>(rt: &Runtime, sub: &ArgMatches<'a, 'a>) -> Option<Vec<String>> {
|
||||
sub.value_of("tags").and_then(|tags|
|
||||
Some(tags.split(",")
|
||||
.collect::<Vec<_>>()
|
||||
.iter()
|
||||
.map(|s| s.to_string())
|
||||
.collect()
|
||||
)
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
fn get_matcher<'a>(rt: &Runtime, sub: &ArgMatches<'a, 'a>) -> Option<Regex> {
|
||||
if let Some(s) = sub.value_of("match") {
|
||||
if let Ok(r) = Regex::new(s) {
|
||||
return Some(r)
|
||||
} else {
|
||||
error!("Regex error, continuing without regex");
|
||||
}
|
||||
}
|
||||
None
|
||||
|
||||
}
|
||||
|
||||
fn get_id<'a>(rt: &Runtime, sub: &ArgMatches<'a, 'a>) -> Option<String> {
|
||||
sub.value_of("id").and_then(|s| Some(String::from(s)))
|
||||
}
|
||||
|
|
@ -7,7 +7,11 @@ use std::result::Result;
|
|||
|
||||
use storage::backend::StorageBackend;
|
||||
use self::command::ExecutableCommand;
|
||||
use module::todo::TodoModule;
|
||||
|
||||
mod command;
|
||||
pub mod todo;
|
||||
pub mod bm;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct ModuleError {
|
||||
|
|
Loading…
Reference in a new issue