mirror of
https://github.com/OMGeeky/google-apis-rs.git
synced 2026-02-23 15:49:49 +01:00
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:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user