Pass CommandEnv struct to command exec function

So we can add parameters rather easily.
Also define CommandResult as result type.
This commit is contained in:
Matthias Beyer 2015-11-28 11:54:27 +01:00
parent 9bf9f96ab1
commit 0a026002b0
2 changed files with 16 additions and 4 deletions

View file

@ -1,15 +1,18 @@
use runtime::Runtime; use runtime::Runtime;
use storage::backend::StorageBackend; use storage::backend::StorageBackend;
pub fn add_command(rt: &Runtime, backend: &StorageBackend) { use module::CommandResult;
use module::CommandEnv;
pub fn add_command(env: CommandEnv) -> CommandResult {
unimplemented!() unimplemented!()
} }
pub fn list_command(rt: &Runtime, backend: &StorageBackend) { pub fn list_command(env: CommandEnv) -> CommandResult {
unimplemented!() unimplemented!()
} }
pub fn remove_command(rt: &Runtime, backend: &StorageBackend) { pub fn remove_command(env: CommandEnv) -> CommandResult {
unimplemented!() unimplemented!()
} }

View file

@ -6,6 +6,8 @@ use std::fmt::Display;
use std::result::Result; use std::result::Result;
use std::collections::HashMap; use std::collections::HashMap;
use clap::{App, ArgMatches};
use storage::backend::{StorageBackend, StorageBackendError}; use storage::backend::{StorageBackend, StorageBackendError};
pub mod bm; pub mod bm;
@ -41,8 +43,15 @@ impl Display for ModuleError {
} }
} }
pub struct CommandEnv<'a> {
pub rt: &'a Runtime<'a>,
pub bk: &'a StorageBackend,
pub matches: &'a ArgMatches<'a, 'a>,
}
pub type ModuleResult = Result<(), ModuleError>; pub type ModuleResult = Result<(), ModuleError>;
pub type CommandMap<'a> = HashMap<&'a str, fn(&Runtime, &StorageBackend)>; pub type CommandResult = ModuleResult;
pub type CommandMap<'a> = HashMap<&'a str, fn(CommandEnv) -> CommandResult>;
pub trait Module { pub trait Module {