From 0a026002b0da6c14f016cad102ce85114fb1ce1f Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sat, 28 Nov 2015 11:54:27 +0100 Subject: [PATCH] Pass CommandEnv struct to command exec function So we can add parameters rather easily. Also define CommandResult as result type. --- src/module/bm/commands.rs | 9 ++++++--- src/module/mod.rs | 11 ++++++++++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/module/bm/commands.rs b/src/module/bm/commands.rs index 60318061..af922fbe 100644 --- a/src/module/bm/commands.rs +++ b/src/module/bm/commands.rs @@ -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!() } diff --git a/src/module/mod.rs b/src/module/mod.rs index 33b1f8d0..7ad0ea48 100644 --- a/src/module/mod.rs +++ b/src/module/mod.rs @@ -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 {