chore(code-update):added latest version of api+cli

APIs have additional files thanks to the build-script
requirement.
CLI has just seen minor changes though, making it
usable with a stable compiler.
This commit is contained in:
Sebastian Thiel
2015-06-19 13:27:40 +02:00
parent e336d37d13
commit 3484fecf9c
835 changed files with 641668 additions and 659095 deletions

View File

@@ -2,6 +2,7 @@
// DO NOT EDIT
use oauth2::{ApplicationSecret, ConsoleApplicationSecret, TokenStorage, Token};
use serde::json;
use serde::json::value::Value;
use mime::Mime;
use clap::{App, SubCommand};
use strsim;
@@ -19,11 +20,38 @@ use std::default::Default;
const FIELD_SEP: char = '.';
pub enum ComplexType {
Pod,
Vec,
Map,
}
// Null,
// Bool(bool),
// I64(i64),
// U64(u64),
// F64(f64),
// String(String),
pub enum JsonType {
Boolean,
Int,
Uint,
Float,
String,
}
pub struct JsonTypeInfo {
pub jtype: JsonType,
pub ctype: ComplexType,
}
// Based on @erickt user comment. Thanks for the idea !
// Remove all keys whose values are null from given value (changed in place)
pub fn remove_json_null_values(value: &mut json::value::Value) {
pub fn remove_json_null_values(value: &mut Value) {
match *value {
json::value::Value::Object(ref mut map) => {
Value::Object(ref mut map) => {
let mut for_removal = Vec::new();
for (key, mut value) in map.iter_mut() {
@@ -96,6 +124,14 @@ impl ToString for FieldCursor {
}
}
impl From<&'static str> for FieldCursor {
fn from(value: &'static str) -> FieldCursor {
let mut res = FieldCursor::default();
res.set(value).unwrap();
res
}
}
impl FieldCursor {
pub fn set(&mut self, value: &str) -> Result<(), CLIError> {
if value.len() == 0 {
@@ -201,6 +237,78 @@ impl FieldCursor {
}
}
pub fn set_json_value(&self, mut object: &mut Value,
value: &str, type_info: JsonTypeInfo,
err: &mut InvalidOptionsError,
orig_cursor: &FieldCursor) {
assert!(self.0.len() > 0);
for field in &self.0[..self.0.len()-1] {
let tmp = object;
object =
match *tmp {
Value::Object(ref mut mapping) => {
mapping.entry(field.to_owned()).or_insert(
Value::Object(Default::default())
)
},
_ => panic!("We don't expect non-object Values here ...")
};
}
match *object {
Value::Object(ref mut mapping) => {
let field = &self.0[self.0.len()-1];
let to_jval =
|value: &str, jtype: JsonType, err: &mut InvalidOptionsError|
-> Value {
match jtype {
JsonType::Boolean =>
Value::Bool(arg_from_str(value, err, &field, "boolean")),
JsonType::Int =>
Value::I64(arg_from_str(value, err, &field, "int")),
JsonType::Uint =>
Value::U64(arg_from_str(value, err, &field, "uint")),
JsonType::Float =>
Value::F64(arg_from_str(value, err, &field, "float")),
JsonType::String =>
Value::String(value.to_owned()),
}
};
match type_info.ctype {
ComplexType::Pod => {
if mapping.insert(field.to_owned(), to_jval(value, type_info.jtype, err)).is_some() {
err.issues.push(CLIError::Field(FieldError::Duplicate(orig_cursor.to_string())));
}
},
ComplexType::Vec => {
match *mapping.entry(field.to_owned())
.or_insert(Value::Array(Default::default())) {
Value::Array(ref mut values) => values.push(to_jval(value, type_info.jtype, err)),
_ => unreachable!()
}
},
ComplexType::Map => {
let (key, value) = parse_kv_arg(value, err, true);
let jval = to_jval(value.unwrap_or(""), type_info.jtype, err);
match *mapping.entry(field.to_owned())
.or_insert(Value::Object(Default::default())) {
Value::Object(ref mut value_map) => {
if value_map.insert(key.to_owned(), jval).is_some() {
err.issues.push(CLIError::Field(FieldError::Duplicate(orig_cursor.to_string())));
}
}
_ => unreachable!()
}
}
}
},
_ => unreachable!()
}
}
pub fn num_fields(&self) -> usize {
self.0.len()
}
@@ -268,15 +376,15 @@ pub fn writer_from_opts(arg: Option<&str>) -> Result<Box<Write>, io::Error> {
}
pub fn arg_from_str<T>(arg: &str, err: &mut InvalidOptionsError,
arg_name: &'static str,
arg_type: &'static str) -> T
pub fn arg_from_str<'a, T>(arg: &str, err: &mut InvalidOptionsError,
arg_name: &'a str,
arg_type: &'a str) -> T
where T: FromStr + Default,
<T as FromStr>::Err: fmt::Display {
match FromStr::from_str(arg) {
Err(perr) => {
err.issues.push(
CLIError::ParseError(arg_name, arg_type, arg.to_string(), format!("{}", perr))
CLIError::ParseError(arg_name.to_owned(), arg_type.to_owned(), arg.to_string(), format!("{}", perr))
);
Default::default()
},
@@ -411,6 +519,7 @@ pub enum FieldError {
PopOnEmpty(String),
TrailingFieldSep(String),
Unknown(String, Option<String>, Option<String>),
Duplicate(String),
Empty,
}
@@ -437,6 +546,8 @@ impl fmt::Display for FieldError {
};
writeln!(f, "Field '{}' does not exist.{}", field, suffix)
},
FieldError::Duplicate(ref cursor)
=> writeln!(f, "Value at '{}' was already set", cursor),
FieldError::Empty
=> writeln!(f, "Field names must not be empty."),
}
@@ -447,7 +558,7 @@ impl fmt::Display for FieldError {
#[derive(Debug)]
pub enum CLIError {
Configuration(ConfigurationError),
ParseError(&'static str, &'static str, String, String),
ParseError(String, String, String, String),
UnknownParameter(String, Vec<&'static str>),
InvalidUploadProtocol(String, Vec<String>),
InvalidKeyValueSyntax(String, bool),
@@ -465,7 +576,7 @@ impl fmt::Display for CLIError {
CLIError::Field(ref err) => write!(f, "Field -> {}", err),
CLIError::InvalidUploadProtocol(ref proto_name, ref valid_names)
=> writeln!(f, "'{}' is not a valid upload protocol. Choose from one of {}.", proto_name, valid_names.connect(", ")),
CLIError::ParseError(arg_name, type_name, ref value, ref err_desc)
CLIError::ParseError(ref arg_name, ref type_name, ref value, ref err_desc)
=> writeln!(f, "Failed to parse argument '{}' with value '{}' as {} with error: {}.",
arg_name, value, type_name, err_desc),
CLIError::UnknownParameter(ref param_name, ref possible_values) => {