rename CmdDef to CommandLineInterface

This commit is contained in:
Dietmar Maurer 2018-12-10 13:40:10 +01:00
parent b7329c8a1a
commit 9f6ab1fc58
2 changed files with 14 additions and 14 deletions

View File

@ -5,29 +5,29 @@ use std::collections::HashMap;
use apitest::api3;
use apitest::cli::command::*;
fn datastore_commands() -> CmdDef {
fn datastore_commands() -> CommandLineInterface {
let mut cmd_def = HashMap::new();
cmd_def.insert("list".to_owned(), CmdDef::Simple(CliCommand {
cmd_def.insert("list".to_owned(), CommandLineInterface::Simple(CliCommand {
info: api3::config::datastore::get(),
arg_param: vec![],
fixed_param: vec![],
}));
cmd_def.insert("create".to_owned(), CmdDef::Simple(CliCommand {
cmd_def.insert("create".to_owned(), CommandLineInterface::Simple(CliCommand {
info: api3::config::datastore::post(),
arg_param: vec!["name", "path"],
fixed_param: vec![],
}));
cmd_def.insert("remove".to_owned(), CmdDef::Simple(CliCommand {
cmd_def.insert("remove".to_owned(), CommandLineInterface::Simple(CliCommand {
info: api3::config::datastore::delete(),
arg_param: vec!["name"],
fixed_param: vec![],
}));
CmdDef::Nested(cmd_def)
CommandLineInterface::Nested(cmd_def)
}
fn main() {
@ -36,7 +36,7 @@ fn main() {
cmd_def.insert("datastore".to_owned(), datastore_commands());
if let Err(err) = run_cli_command(&CmdDef::Nested(cmd_def)) {
if let Err(err) = run_cli_command(&CommandLineInterface::Nested(cmd_def)) {
eprintln!("Error: {}", err);
print_cli_usage();
std::process::exit(-1);

View File

@ -27,7 +27,7 @@ fn handle_simple_command(cli_cmd: &CliCommand, args: Vec<String>) -> Result<(),
Ok(())
}
fn handle_nested_command(def: &HashMap<String, CmdDef>, mut args: Vec<String>) -> Result<(), Error> {
fn handle_nested_command(def: &HashMap<String, CommandLineInterface>, mut args: Vec<String>) -> Result<(), Error> {
if args.len() < 1 {
let mut cmds: Vec<&String> = def.keys().collect();
@ -52,10 +52,10 @@ fn handle_nested_command(def: &HashMap<String, CmdDef>, mut args: Vec<String>) -
};
match sub_cmd {
CmdDef::Simple(cli_cmd) => {
CommandLineInterface::Simple(cli_cmd) => {
handle_simple_command(cli_cmd, args)?;
}
CmdDef::Nested(map) => {
CommandLineInterface::Nested(map) => {
handle_nested_command(map, args)?;
}
}
@ -63,13 +63,13 @@ fn handle_nested_command(def: &HashMap<String, CmdDef>, mut args: Vec<String>) -
Ok(())
}
pub fn run_cli_command(def: &CmdDef) -> Result<(), Error> {
pub fn run_cli_command(def: &CommandLineInterface) -> Result<(), Error> {
let args: Vec<String> = std::env::args().skip(1).collect();
match def {
CmdDef::Simple(cli_cmd) => handle_simple_command(cli_cmd, args),
CmdDef::Nested(map) => handle_nested_command(map, args),
CommandLineInterface::Simple(cli_cmd) => handle_simple_command(cli_cmd, args),
CommandLineInterface::Nested(map) => handle_nested_command(map, args),
}
}
@ -79,7 +79,7 @@ pub struct CliCommand {
pub fixed_param: Vec<&'static str>,
}
pub enum CmdDef {
pub enum CommandLineInterface {
Simple(CliCommand),
Nested(HashMap<String, CmdDef>),
Nested(HashMap<String, CommandLineInterface>),
}