implement builder pattern for CliCommand
This commit is contained in:
parent
baed30b702
commit
bf7f103944
|
@ -9,23 +9,19 @@ fn datastore_commands() -> CommandLineInterface {
|
||||||
|
|
||||||
let mut cmd_def = HashMap::<String, CommandLineInterface>::new();
|
let mut cmd_def = HashMap::<String, CommandLineInterface>::new();
|
||||||
|
|
||||||
cmd_def.insert("list".to_owned(), CliCommand {
|
use apitest::api3::config::datastore;
|
||||||
info: api3::config::datastore::get(),
|
|
||||||
arg_param: vec![],
|
|
||||||
fixed_param: vec![],
|
|
||||||
}.into());
|
|
||||||
|
|
||||||
cmd_def.insert("create".to_owned(), CliCommand {
|
cmd_def.insert("list".to_owned(), CliCommand::new(datastore::get()).into());
|
||||||
info: api3::config::datastore::post(),
|
|
||||||
arg_param: vec!["name", "path"],
|
|
||||||
fixed_param: vec![],
|
|
||||||
}.into());
|
|
||||||
|
|
||||||
cmd_def.insert("remove".to_owned(), CliCommand {
|
cmd_def.insert("create".to_owned(),
|
||||||
info: api3::config::datastore::delete(),
|
CliCommand::new(datastore::post())
|
||||||
arg_param: vec!["name"],
|
.arg_param(vec!["name", "path"])
|
||||||
fixed_param: vec![],
|
.into());
|
||||||
}.into());
|
|
||||||
|
cmd_def.insert("remove".to_owned(),
|
||||||
|
CliCommand::new(api3::config::datastore::delete())
|
||||||
|
.arg_param(vec!["name"])
|
||||||
|
.into());
|
||||||
|
|
||||||
cmd_def.into()
|
cmd_def.into()
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,6 +99,23 @@ pub struct CliCommand {
|
||||||
pub fixed_param: Vec<&'static str>,
|
pub fixed_param: Vec<&'static str>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl CliCommand {
|
||||||
|
|
||||||
|
pub fn new(info: ApiMethod) -> Self {
|
||||||
|
Self { info, arg_param: vec![], fixed_param: vec![] }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn arg_param(mut self, names: Vec<&'static str>) -> Self {
|
||||||
|
self.arg_param = names;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn fixed_param(mut self, args: Vec<&'static str>) -> Self {
|
||||||
|
self.fixed_param = args;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub enum CommandLineInterface {
|
pub enum CommandLineInterface {
|
||||||
Simple(CliCommand),
|
Simple(CliCommand),
|
||||||
Nested(HashMap<String, CommandLineInterface>),
|
Nested(HashMap<String, CommandLineInterface>),
|
||||||
|
|
Loading…
Reference in New Issue