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:
parent
9bf9f96ab1
commit
0a026002b0
2 changed files with 16 additions and 4 deletions
|
@ -1,15 +1,18 @@
|
|||
use runtime::Runtime;
|
||||
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!()
|
||||
}
|
||||
|
||||
pub fn list_command(rt: &Runtime, backend: &StorageBackend) {
|
||||
pub fn list_command(env: CommandEnv) -> CommandResult {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn remove_command(rt: &Runtime, backend: &StorageBackend) {
|
||||
pub fn remove_command(env: CommandEnv) -> CommandResult {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,8 @@ use std::fmt::Display;
|
|||
use std::result::Result;
|
||||
use std::collections::HashMap;
|
||||
|
||||
use clap::{App, ArgMatches};
|
||||
|
||||
use storage::backend::{StorageBackend, StorageBackendError};
|
||||
|
||||
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 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 {
|
||||
|
||||
|
|
Loading…
Reference in a new issue