refactor(CLI): use arg_enum! clap-rs macro

That way, we get a better (case-insensitive) implementation of `FromStr`
which reduces the amount of code we have to maintain.

Closes #101
[skip ci]
This commit is contained in:
Sebastian Thiel
2015-05-06 11:58:37 +02:00
parent 294da41a30
commit 2485343caa
3 changed files with 9 additions and 18 deletions

View File

@@ -37,9 +37,11 @@ pub enum CallType {
Standard,
}
pub enum UploadProtocol {
Simple,
Resumable,
arg_enum!{
pub enum UploadProtocol {
Simple,
Resumable
}
}
impl AsRef<str> for UploadProtocol {
@@ -60,18 +62,6 @@ impl AsRef<str> for CallType {
}
}
impl FromStr for UploadProtocol {
type Err = String;
fn from_str(s: &str) -> Result<UploadProtocol, String> {
match s {
"simple" => Ok(UploadProtocol::Simple),
"resumable" => Ok(UploadProtocol::Resumable),
_ => Err(format!("Protocol '{}' is unknown", s)),
}
}
}
#[derive(Clone, Default)]
pub struct FieldCursor(Vec<String>);
@@ -210,7 +200,7 @@ pub fn parse_kv_arg<'a>(kv: &'a str, err: &mut InvalidOptionsError, for_hashmap:
}
}
pub fn protocol_from_str(name: &str, valid_protocols: Vec<String>, err: &mut InvalidOptionsError) -> CallType {
pub fn calltype_from_str(name: &str, valid_protocols: Vec<String>, err: &mut InvalidOptionsError) -> CallType {
CallType::Upload(
match UploadProtocol::from_str(name) {
Ok(up) => up,