Pass StorageBackend to subcommand function

This commit is contained in:
Matthias Beyer 2015-11-28 11:43:30 +01:00
parent 3f19aba7b2
commit 18ea01b854
3 changed files with 10 additions and 5 deletions

View file

@ -14,6 +14,7 @@ use clap::App;
use module::Module; use module::Module;
use module::ModuleError; use module::ModuleError;
use module::bm::BMModule; use module::bm::BMModule;
use storage::backend::StorageBackend;
mod cli; mod cli;
mod configuration; mod configuration;
@ -43,8 +44,11 @@ fn main() {
let commands = module.get_commands(&rt); let commands = module.get_commands(&rt);
if let Some(command) = matches.subcommand_name() { if let Some(command) = matches.subcommand_name() {
debug!("Subcommand: {}", command); debug!("Subcommand: {}", command);
let backend = StorageBackend::new(rt.get_rtp());
match commands.get(command) { match commands.get(command) {
Some(f) => f(&rt), Some(f) => f(&rt, &backend),
None => debug!("No command '{}' found", command), None => debug!("No command '{}' found", command),
} }
} else { } else {

View file

@ -1,14 +1,15 @@
use runtime::Runtime; use runtime::Runtime;
use storage::backend::StorageBackend;
pub fn add_command(rt: &Runtime) { pub fn add_command(rt: &Runtime, backend: &StorageBackend) {
unimplemented!() unimplemented!()
} }
pub fn list_command(rt: &Runtime) { pub fn list_command(rt: &Runtime, backend: &StorageBackend) {
unimplemented!() unimplemented!()
} }
pub fn remove_command(rt: &Runtime) { pub fn remove_command(rt: &Runtime, backend: &StorageBackend) {
unimplemented!() unimplemented!()
} }

View file

@ -42,7 +42,7 @@ impl Display for ModuleError {
} }
pub type ModuleResult = Result<(), ModuleError>; pub type ModuleResult = Result<(), ModuleError>;
pub type CommandMap<'a> = HashMap<&'a str, fn(&Runtime)>; pub type CommandMap<'a> = HashMap<&'a str, fn(&Runtime, &StorageBackend)>;
pub trait Module { pub trait Module {