feat(CLI): hashmap handling

* with native support for type conversion and error handling
* improved hash-map key-value parsing to at least state that it knows
  it's dealing with a hashmap. Error text is still not what it should
  be because we don't know at runtime (initially) what type we handle.

Fixes #68
Related to #77
This commit is contained in:
Sebastian Thiel
2015-04-22 10:55:50 +02:00
parent c14ef9afc8
commit b830c1c6de
2 changed files with 26 additions and 21 deletions

View File

@@ -91,10 +91,10 @@ impl FieldCursor {
}
}
pub fn parse_kv_arg<'a>(kv: &'a str, err: &mut InvalidOptionsError)
pub fn parse_kv_arg<'a>(kv: &'a str, err: &mut InvalidOptionsError, for_hashmap: bool)
-> (&'a str, Option<&'a str>) {
let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string()));
match kv.rfind('=') {
let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string(),for_hashmap));
match kv.find('=') {
None => {
add_err();
return (kv, None)
@@ -284,7 +284,7 @@ pub enum CLIError {
Configuration(ConfigurationError),
ParseError((&'static str, &'static str, String, String)),
UnknownParameter(String),
InvalidKeyValueSyntax(String),
InvalidKeyValueSyntax(String, bool),
Input(InputError),
Field(FieldError),
}
@@ -300,9 +300,10 @@ impl fmt::Display for CLIError {
arg_name, value, type_name, err_desc),
CLIError::UnknownParameter(ref param_name)
=> writeln!(f, "Parameter '{}' is unknown.", param_name),
CLIError::InvalidKeyValueSyntax(ref kv)
=> writeln!(f, "'{}' does not match pattern <key>=<value>", kv),
CLIError::InvalidKeyValueSyntax(ref kv, is_hashmap) => {
let hashmap_info = if is_hashmap { "hashmap " } else { "" };
writeln!(f, "'{}' does not match {}pattern <key>=<value>", kv, hashmap_info)
},
}
}
}