mirror of
https://github.com/OMGeeky/google-apis-rs.git
synced 2026-01-23 03:33:51 +01:00
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:
@@ -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) => {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
// DO NOT EDIT !
|
||||
// This file was generated automatically from 'src/mako/cli/main.rs.mako'
|
||||
// DO NOT EDIT !
|
||||
#![feature(plugin, exit_status)]
|
||||
#![allow(unused_variables, unused_imports, dead_code, unused_mut)]
|
||||
|
||||
#[macro_use]
|
||||
@@ -22,7 +21,7 @@ mod cmn;
|
||||
|
||||
use cmn::{InvalidOptionsError, CLIError, JsonTokenStorage, arg_from_str, writer_from_opts, parse_kv_arg,
|
||||
input_file_from_opts, input_mime_from_opts, FieldCursor, FieldError, CallType, UploadProtocol,
|
||||
calltype_from_str, remove_json_null_values};
|
||||
calltype_from_str, remove_json_null_values, ComplexType, JsonType, JsonTypeInfo};
|
||||
|
||||
use std::default::Default;
|
||||
use std::str::FromStr;
|
||||
@@ -61,9 +60,11 @@ impl<'n, 'a> Engine<'n, 'a> {
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
err.issues.push(CLIError::UnknownParameter(key.to_string(),
|
||||
Vec::new() + &self.gp + &[]
|
||||
));
|
||||
err.issues.push(CLIError::UnknownParameter(key.to_string(),
|
||||
{let mut v = Vec::new();
|
||||
v.extend(self.gp.iter().map(|v|*v));
|
||||
v.extend([].iter().map(|v|*v));
|
||||
v } ));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -104,9 +105,11 @@ impl<'n, 'a> Engine<'n, 'a> {
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
err.issues.push(CLIError::UnknownParameter(key.to_string(),
|
||||
Vec::new() + &self.gp + &[]
|
||||
));
|
||||
err.issues.push(CLIError::UnknownParameter(key.to_string(),
|
||||
{let mut v = Vec::new();
|
||||
v.extend(self.gp.iter().map(|v|*v));
|
||||
v.extend([].iter().map(|v|*v));
|
||||
v } ));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -131,7 +134,7 @@ impl<'n, 'a> Engine<'n, 'a> {
|
||||
Ok((mut response, output_schema)) => {
|
||||
let mut value = json::value::to_value(&output_schema);
|
||||
remove_json_null_values(&mut value);
|
||||
serde::json::to_writer_pretty(&mut ostream, &value).unwrap();
|
||||
json::to_writer_pretty(&mut ostream, &value).unwrap();
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -141,8 +144,9 @@ impl<'n, 'a> Engine<'n, 'a> {
|
||||
fn _tasklists_insert(&self, opt: &ArgMatches<'n, 'a>, dry_run: bool, err: &mut InvalidOptionsError)
|
||||
-> Result<(), DoitError> {
|
||||
|
||||
let mut request = api::TaskList::default();
|
||||
let mut field_cursor = FieldCursor::default();
|
||||
let mut object = json::value::Value::Object(Default::default());
|
||||
|
||||
for kvarg in opt.values_of("kv").unwrap_or(Vec::new()).iter() {
|
||||
let last_errc = err.issues.len();
|
||||
let (key, value) = parse_kv_arg(&*kvarg, err, false);
|
||||
@@ -157,31 +161,26 @@ impl<'n, 'a> Engine<'n, 'a> {
|
||||
}
|
||||
continue;
|
||||
}
|
||||
match &temp_cursor.to_string()[..] {
|
||||
"kind" => {
|
||||
request.kind = Some(value.unwrap_or("").to_string());
|
||||
},
|
||||
"title" => {
|
||||
request.title = Some(value.unwrap_or("").to_string());
|
||||
},
|
||||
"updated" => {
|
||||
request.updated = Some(value.unwrap_or("").to_string());
|
||||
},
|
||||
"etag" => {
|
||||
request.etag = Some(value.unwrap_or("").to_string());
|
||||
},
|
||||
"id" => {
|
||||
request.id = Some(value.unwrap_or("").to_string());
|
||||
},
|
||||
"self-link" => {
|
||||
request.self_link = Some(value.unwrap_or("").to_string());
|
||||
},
|
||||
_ => {
|
||||
let suggestion = FieldCursor::did_you_mean(key, &vec!["etag", "id", "kind", "self-link", "title", "updated"]);
|
||||
err.issues.push(CLIError::Field(FieldError::Unknown(temp_cursor.to_string(), suggestion, value.map(|v| v.to_string()))));
|
||||
}
|
||||
|
||||
let type_info =
|
||||
match &temp_cursor.to_string()[..] {
|
||||
"kind" => Some(("kind", JsonTypeInfo { jtype: JsonType::String, ctype: ComplexType::Pod })),
|
||||
"title" => Some(("title", JsonTypeInfo { jtype: JsonType::String, ctype: ComplexType::Pod })),
|
||||
"updated" => Some(("updated", JsonTypeInfo { jtype: JsonType::String, ctype: ComplexType::Pod })),
|
||||
"etag" => Some(("etag", JsonTypeInfo { jtype: JsonType::String, ctype: ComplexType::Pod })),
|
||||
"id" => Some(("id", JsonTypeInfo { jtype: JsonType::String, ctype: ComplexType::Pod })),
|
||||
"self-link" => Some(("selfLink", JsonTypeInfo { jtype: JsonType::String, ctype: ComplexType::Pod })),
|
||||
_ => {
|
||||
let suggestion = FieldCursor::did_you_mean(key, &vec!["etag", "id", "kind", "self-link", "title", "updated"]);
|
||||
err.issues.push(CLIError::Field(FieldError::Unknown(temp_cursor.to_string(), suggestion, value.map(|v| v.to_string()))));
|
||||
None
|
||||
}
|
||||
};
|
||||
if let Some((field_cursor_str, type_info)) = type_info {
|
||||
FieldCursor::from(field_cursor_str).set_json_value(&mut object, value.unwrap(), type_info, err, &temp_cursor);
|
||||
}
|
||||
}
|
||||
let mut request: api::TaskList = json::value::from_value(object).unwrap();
|
||||
let mut call = self.hub.tasklists().insert(request);
|
||||
for parg in opt.values_of("v").unwrap_or(Vec::new()).iter() {
|
||||
let (key, value) = parse_kv_arg(&*parg, err, false);
|
||||
@@ -196,9 +195,11 @@ impl<'n, 'a> Engine<'n, 'a> {
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
err.issues.push(CLIError::UnknownParameter(key.to_string(),
|
||||
Vec::new() + &self.gp + &[]
|
||||
));
|
||||
err.issues.push(CLIError::UnknownParameter(key.to_string(),
|
||||
{let mut v = Vec::new();
|
||||
v.extend(self.gp.iter().map(|v|*v));
|
||||
v.extend([].iter().map(|v|*v));
|
||||
v } ));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -223,7 +224,7 @@ impl<'n, 'a> Engine<'n, 'a> {
|
||||
Ok((mut response, output_schema)) => {
|
||||
let mut value = json::value::to_value(&output_schema);
|
||||
remove_json_null_values(&mut value);
|
||||
serde::json::to_writer_pretty(&mut ostream, &value).unwrap();
|
||||
json::to_writer_pretty(&mut ostream, &value).unwrap();
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -252,9 +253,11 @@ impl<'n, 'a> Engine<'n, 'a> {
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
err.issues.push(CLIError::UnknownParameter(key.to_string(),
|
||||
Vec::new() + &self.gp + &["page-token", "max-results"]
|
||||
));
|
||||
err.issues.push(CLIError::UnknownParameter(key.to_string(),
|
||||
{let mut v = Vec::new();
|
||||
v.extend(self.gp.iter().map(|v|*v));
|
||||
v.extend(["page-token", "max-results"].iter().map(|v|*v));
|
||||
v } ));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -279,7 +282,7 @@ impl<'n, 'a> Engine<'n, 'a> {
|
||||
Ok((mut response, output_schema)) => {
|
||||
let mut value = json::value::to_value(&output_schema);
|
||||
remove_json_null_values(&mut value);
|
||||
serde::json::to_writer_pretty(&mut ostream, &value).unwrap();
|
||||
json::to_writer_pretty(&mut ostream, &value).unwrap();
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -289,8 +292,9 @@ impl<'n, 'a> Engine<'n, 'a> {
|
||||
fn _tasklists_patch(&self, opt: &ArgMatches<'n, 'a>, dry_run: bool, err: &mut InvalidOptionsError)
|
||||
-> Result<(), DoitError> {
|
||||
|
||||
let mut request = api::TaskList::default();
|
||||
let mut field_cursor = FieldCursor::default();
|
||||
let mut object = json::value::Value::Object(Default::default());
|
||||
|
||||
for kvarg in opt.values_of("kv").unwrap_or(Vec::new()).iter() {
|
||||
let last_errc = err.issues.len();
|
||||
let (key, value) = parse_kv_arg(&*kvarg, err, false);
|
||||
@@ -305,31 +309,26 @@ impl<'n, 'a> Engine<'n, 'a> {
|
||||
}
|
||||
continue;
|
||||
}
|
||||
match &temp_cursor.to_string()[..] {
|
||||
"kind" => {
|
||||
request.kind = Some(value.unwrap_or("").to_string());
|
||||
},
|
||||
"title" => {
|
||||
request.title = Some(value.unwrap_or("").to_string());
|
||||
},
|
||||
"updated" => {
|
||||
request.updated = Some(value.unwrap_or("").to_string());
|
||||
},
|
||||
"etag" => {
|
||||
request.etag = Some(value.unwrap_or("").to_string());
|
||||
},
|
||||
"id" => {
|
||||
request.id = Some(value.unwrap_or("").to_string());
|
||||
},
|
||||
"self-link" => {
|
||||
request.self_link = Some(value.unwrap_or("").to_string());
|
||||
},
|
||||
_ => {
|
||||
let suggestion = FieldCursor::did_you_mean(key, &vec!["etag", "id", "kind", "self-link", "title", "updated"]);
|
||||
err.issues.push(CLIError::Field(FieldError::Unknown(temp_cursor.to_string(), suggestion, value.map(|v| v.to_string()))));
|
||||
}
|
||||
|
||||
let type_info =
|
||||
match &temp_cursor.to_string()[..] {
|
||||
"kind" => Some(("kind", JsonTypeInfo { jtype: JsonType::String, ctype: ComplexType::Pod })),
|
||||
"title" => Some(("title", JsonTypeInfo { jtype: JsonType::String, ctype: ComplexType::Pod })),
|
||||
"updated" => Some(("updated", JsonTypeInfo { jtype: JsonType::String, ctype: ComplexType::Pod })),
|
||||
"etag" => Some(("etag", JsonTypeInfo { jtype: JsonType::String, ctype: ComplexType::Pod })),
|
||||
"id" => Some(("id", JsonTypeInfo { jtype: JsonType::String, ctype: ComplexType::Pod })),
|
||||
"self-link" => Some(("selfLink", JsonTypeInfo { jtype: JsonType::String, ctype: ComplexType::Pod })),
|
||||
_ => {
|
||||
let suggestion = FieldCursor::did_you_mean(key, &vec!["etag", "id", "kind", "self-link", "title", "updated"]);
|
||||
err.issues.push(CLIError::Field(FieldError::Unknown(temp_cursor.to_string(), suggestion, value.map(|v| v.to_string()))));
|
||||
None
|
||||
}
|
||||
};
|
||||
if let Some((field_cursor_str, type_info)) = type_info {
|
||||
FieldCursor::from(field_cursor_str).set_json_value(&mut object, value.unwrap(), type_info, err, &temp_cursor);
|
||||
}
|
||||
}
|
||||
let mut request: api::TaskList = json::value::from_value(object).unwrap();
|
||||
let mut call = self.hub.tasklists().patch(request, opt.value_of("tasklist").unwrap_or(""));
|
||||
for parg in opt.values_of("v").unwrap_or(Vec::new()).iter() {
|
||||
let (key, value) = parse_kv_arg(&*parg, err, false);
|
||||
@@ -344,9 +343,11 @@ impl<'n, 'a> Engine<'n, 'a> {
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
err.issues.push(CLIError::UnknownParameter(key.to_string(),
|
||||
Vec::new() + &self.gp + &[]
|
||||
));
|
||||
err.issues.push(CLIError::UnknownParameter(key.to_string(),
|
||||
{let mut v = Vec::new();
|
||||
v.extend(self.gp.iter().map(|v|*v));
|
||||
v.extend([].iter().map(|v|*v));
|
||||
v } ));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -371,7 +372,7 @@ impl<'n, 'a> Engine<'n, 'a> {
|
||||
Ok((mut response, output_schema)) => {
|
||||
let mut value = json::value::to_value(&output_schema);
|
||||
remove_json_null_values(&mut value);
|
||||
serde::json::to_writer_pretty(&mut ostream, &value).unwrap();
|
||||
json::to_writer_pretty(&mut ostream, &value).unwrap();
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -381,8 +382,9 @@ impl<'n, 'a> Engine<'n, 'a> {
|
||||
fn _tasklists_update(&self, opt: &ArgMatches<'n, 'a>, dry_run: bool, err: &mut InvalidOptionsError)
|
||||
-> Result<(), DoitError> {
|
||||
|
||||
let mut request = api::TaskList::default();
|
||||
let mut field_cursor = FieldCursor::default();
|
||||
let mut object = json::value::Value::Object(Default::default());
|
||||
|
||||
for kvarg in opt.values_of("kv").unwrap_or(Vec::new()).iter() {
|
||||
let last_errc = err.issues.len();
|
||||
let (key, value) = parse_kv_arg(&*kvarg, err, false);
|
||||
@@ -397,31 +399,26 @@ impl<'n, 'a> Engine<'n, 'a> {
|
||||
}
|
||||
continue;
|
||||
}
|
||||
match &temp_cursor.to_string()[..] {
|
||||
"kind" => {
|
||||
request.kind = Some(value.unwrap_or("").to_string());
|
||||
},
|
||||
"title" => {
|
||||
request.title = Some(value.unwrap_or("").to_string());
|
||||
},
|
||||
"updated" => {
|
||||
request.updated = Some(value.unwrap_or("").to_string());
|
||||
},
|
||||
"etag" => {
|
||||
request.etag = Some(value.unwrap_or("").to_string());
|
||||
},
|
||||
"id" => {
|
||||
request.id = Some(value.unwrap_or("").to_string());
|
||||
},
|
||||
"self-link" => {
|
||||
request.self_link = Some(value.unwrap_or("").to_string());
|
||||
},
|
||||
_ => {
|
||||
let suggestion = FieldCursor::did_you_mean(key, &vec!["etag", "id", "kind", "self-link", "title", "updated"]);
|
||||
err.issues.push(CLIError::Field(FieldError::Unknown(temp_cursor.to_string(), suggestion, value.map(|v| v.to_string()))));
|
||||
}
|
||||
|
||||
let type_info =
|
||||
match &temp_cursor.to_string()[..] {
|
||||
"kind" => Some(("kind", JsonTypeInfo { jtype: JsonType::String, ctype: ComplexType::Pod })),
|
||||
"title" => Some(("title", JsonTypeInfo { jtype: JsonType::String, ctype: ComplexType::Pod })),
|
||||
"updated" => Some(("updated", JsonTypeInfo { jtype: JsonType::String, ctype: ComplexType::Pod })),
|
||||
"etag" => Some(("etag", JsonTypeInfo { jtype: JsonType::String, ctype: ComplexType::Pod })),
|
||||
"id" => Some(("id", JsonTypeInfo { jtype: JsonType::String, ctype: ComplexType::Pod })),
|
||||
"self-link" => Some(("selfLink", JsonTypeInfo { jtype: JsonType::String, ctype: ComplexType::Pod })),
|
||||
_ => {
|
||||
let suggestion = FieldCursor::did_you_mean(key, &vec!["etag", "id", "kind", "self-link", "title", "updated"]);
|
||||
err.issues.push(CLIError::Field(FieldError::Unknown(temp_cursor.to_string(), suggestion, value.map(|v| v.to_string()))));
|
||||
None
|
||||
}
|
||||
};
|
||||
if let Some((field_cursor_str, type_info)) = type_info {
|
||||
FieldCursor::from(field_cursor_str).set_json_value(&mut object, value.unwrap(), type_info, err, &temp_cursor);
|
||||
}
|
||||
}
|
||||
let mut request: api::TaskList = json::value::from_value(object).unwrap();
|
||||
let mut call = self.hub.tasklists().update(request, opt.value_of("tasklist").unwrap_or(""));
|
||||
for parg in opt.values_of("v").unwrap_or(Vec::new()).iter() {
|
||||
let (key, value) = parse_kv_arg(&*parg, err, false);
|
||||
@@ -436,9 +433,11 @@ impl<'n, 'a> Engine<'n, 'a> {
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
err.issues.push(CLIError::UnknownParameter(key.to_string(),
|
||||
Vec::new() + &self.gp + &[]
|
||||
));
|
||||
err.issues.push(CLIError::UnknownParameter(key.to_string(),
|
||||
{let mut v = Vec::new();
|
||||
v.extend(self.gp.iter().map(|v|*v));
|
||||
v.extend([].iter().map(|v|*v));
|
||||
v } ));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -463,7 +462,7 @@ impl<'n, 'a> Engine<'n, 'a> {
|
||||
Ok((mut response, output_schema)) => {
|
||||
let mut value = json::value::to_value(&output_schema);
|
||||
remove_json_null_values(&mut value);
|
||||
serde::json::to_writer_pretty(&mut ostream, &value).unwrap();
|
||||
json::to_writer_pretty(&mut ostream, &value).unwrap();
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -486,9 +485,11 @@ impl<'n, 'a> Engine<'n, 'a> {
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
err.issues.push(CLIError::UnknownParameter(key.to_string(),
|
||||
Vec::new() + &self.gp + &[]
|
||||
));
|
||||
err.issues.push(CLIError::UnknownParameter(key.to_string(),
|
||||
{let mut v = Vec::new();
|
||||
v.extend(self.gp.iter().map(|v|*v));
|
||||
v.extend([].iter().map(|v|*v));
|
||||
v } ));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -529,9 +530,11 @@ impl<'n, 'a> Engine<'n, 'a> {
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
err.issues.push(CLIError::UnknownParameter(key.to_string(),
|
||||
Vec::new() + &self.gp + &[]
|
||||
));
|
||||
err.issues.push(CLIError::UnknownParameter(key.to_string(),
|
||||
{let mut v = Vec::new();
|
||||
v.extend(self.gp.iter().map(|v|*v));
|
||||
v.extend([].iter().map(|v|*v));
|
||||
v } ));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -572,9 +575,11 @@ impl<'n, 'a> Engine<'n, 'a> {
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
err.issues.push(CLIError::UnknownParameter(key.to_string(),
|
||||
Vec::new() + &self.gp + &[]
|
||||
));
|
||||
err.issues.push(CLIError::UnknownParameter(key.to_string(),
|
||||
{let mut v = Vec::new();
|
||||
v.extend(self.gp.iter().map(|v|*v));
|
||||
v.extend([].iter().map(|v|*v));
|
||||
v } ));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -599,7 +604,7 @@ impl<'n, 'a> Engine<'n, 'a> {
|
||||
Ok((mut response, output_schema)) => {
|
||||
let mut value = json::value::to_value(&output_schema);
|
||||
remove_json_null_values(&mut value);
|
||||
serde::json::to_writer_pretty(&mut ostream, &value).unwrap();
|
||||
json::to_writer_pretty(&mut ostream, &value).unwrap();
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -609,8 +614,9 @@ impl<'n, 'a> Engine<'n, 'a> {
|
||||
fn _tasks_insert(&self, opt: &ArgMatches<'n, 'a>, dry_run: bool, err: &mut InvalidOptionsError)
|
||||
-> Result<(), DoitError> {
|
||||
|
||||
let mut request = api::Task::default();
|
||||
let mut field_cursor = FieldCursor::default();
|
||||
let mut object = json::value::Value::Object(Default::default());
|
||||
|
||||
for kvarg in opt.values_of("kv").unwrap_or(Vec::new()).iter() {
|
||||
let last_errc = err.issues.len();
|
||||
let (key, value) = parse_kv_arg(&*kvarg, err, false);
|
||||
@@ -625,55 +631,34 @@ impl<'n, 'a> Engine<'n, 'a> {
|
||||
}
|
||||
continue;
|
||||
}
|
||||
match &temp_cursor.to_string()[..] {
|
||||
"status" => {
|
||||
request.status = Some(value.unwrap_or("").to_string());
|
||||
},
|
||||
"kind" => {
|
||||
request.kind = Some(value.unwrap_or("").to_string());
|
||||
},
|
||||
"parent" => {
|
||||
request.parent = Some(value.unwrap_or("").to_string());
|
||||
},
|
||||
"title" => {
|
||||
request.title = Some(value.unwrap_or("").to_string());
|
||||
},
|
||||
"deleted" => {
|
||||
request.deleted = Some(arg_from_str(value.unwrap_or("false"), err, "deleted", "boolean"));
|
||||
},
|
||||
"completed" => {
|
||||
request.completed = Some(value.unwrap_or("").to_string());
|
||||
},
|
||||
"updated" => {
|
||||
request.updated = Some(value.unwrap_or("").to_string());
|
||||
},
|
||||
"due" => {
|
||||
request.due = Some(value.unwrap_or("").to_string());
|
||||
},
|
||||
"etag" => {
|
||||
request.etag = Some(value.unwrap_or("").to_string());
|
||||
},
|
||||
"notes" => {
|
||||
request.notes = Some(value.unwrap_or("").to_string());
|
||||
},
|
||||
"position" => {
|
||||
request.position = Some(value.unwrap_or("").to_string());
|
||||
},
|
||||
"hidden" => {
|
||||
request.hidden = Some(arg_from_str(value.unwrap_or("false"), err, "hidden", "boolean"));
|
||||
},
|
||||
"id" => {
|
||||
request.id = Some(value.unwrap_or("").to_string());
|
||||
},
|
||||
"self-link" => {
|
||||
request.self_link = Some(value.unwrap_or("").to_string());
|
||||
},
|
||||
_ => {
|
||||
let suggestion = FieldCursor::did_you_mean(key, &vec!["completed", "deleted", "due", "etag", "hidden", "id", "kind", "notes", "parent", "position", "self-link", "status", "title", "updated"]);
|
||||
err.issues.push(CLIError::Field(FieldError::Unknown(temp_cursor.to_string(), suggestion, value.map(|v| v.to_string()))));
|
||||
}
|
||||
|
||||
let type_info =
|
||||
match &temp_cursor.to_string()[..] {
|
||||
"status" => Some(("status", JsonTypeInfo { jtype: JsonType::String, ctype: ComplexType::Pod })),
|
||||
"kind" => Some(("kind", JsonTypeInfo { jtype: JsonType::String, ctype: ComplexType::Pod })),
|
||||
"parent" => Some(("parent", JsonTypeInfo { jtype: JsonType::String, ctype: ComplexType::Pod })),
|
||||
"title" => Some(("title", JsonTypeInfo { jtype: JsonType::String, ctype: ComplexType::Pod })),
|
||||
"deleted" => Some(("deleted", JsonTypeInfo { jtype: JsonType::Boolean, ctype: ComplexType::Pod })),
|
||||
"completed" => Some(("completed", JsonTypeInfo { jtype: JsonType::String, ctype: ComplexType::Pod })),
|
||||
"updated" => Some(("updated", JsonTypeInfo { jtype: JsonType::String, ctype: ComplexType::Pod })),
|
||||
"due" => Some(("due", JsonTypeInfo { jtype: JsonType::String, ctype: ComplexType::Pod })),
|
||||
"etag" => Some(("etag", JsonTypeInfo { jtype: JsonType::String, ctype: ComplexType::Pod })),
|
||||
"notes" => Some(("notes", JsonTypeInfo { jtype: JsonType::String, ctype: ComplexType::Pod })),
|
||||
"position" => Some(("position", JsonTypeInfo { jtype: JsonType::String, ctype: ComplexType::Pod })),
|
||||
"hidden" => Some(("hidden", JsonTypeInfo { jtype: JsonType::Boolean, ctype: ComplexType::Pod })),
|
||||
"id" => Some(("id", JsonTypeInfo { jtype: JsonType::String, ctype: ComplexType::Pod })),
|
||||
"self-link" => Some(("selfLink", JsonTypeInfo { jtype: JsonType::String, ctype: ComplexType::Pod })),
|
||||
_ => {
|
||||
let suggestion = FieldCursor::did_you_mean(key, &vec!["completed", "deleted", "due", "etag", "hidden", "id", "kind", "notes", "parent", "position", "self-link", "status", "title", "updated"]);
|
||||
err.issues.push(CLIError::Field(FieldError::Unknown(temp_cursor.to_string(), suggestion, value.map(|v| v.to_string()))));
|
||||
None
|
||||
}
|
||||
};
|
||||
if let Some((field_cursor_str, type_info)) = type_info {
|
||||
FieldCursor::from(field_cursor_str).set_json_value(&mut object, value.unwrap(), type_info, err, &temp_cursor);
|
||||
}
|
||||
}
|
||||
let mut request: api::Task = json::value::from_value(object).unwrap();
|
||||
let mut call = self.hub.tasks().insert(request, opt.value_of("tasklist").unwrap_or(""));
|
||||
for parg in opt.values_of("v").unwrap_or(Vec::new()).iter() {
|
||||
let (key, value) = parse_kv_arg(&*parg, err, false);
|
||||
@@ -694,9 +679,11 @@ impl<'n, 'a> Engine<'n, 'a> {
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
err.issues.push(CLIError::UnknownParameter(key.to_string(),
|
||||
Vec::new() + &self.gp + &["parent", "previous"]
|
||||
));
|
||||
err.issues.push(CLIError::UnknownParameter(key.to_string(),
|
||||
{let mut v = Vec::new();
|
||||
v.extend(self.gp.iter().map(|v|*v));
|
||||
v.extend(["parent", "previous"].iter().map(|v|*v));
|
||||
v } ));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -721,7 +708,7 @@ impl<'n, 'a> Engine<'n, 'a> {
|
||||
Ok((mut response, output_schema)) => {
|
||||
let mut value = json::value::to_value(&output_schema);
|
||||
remove_json_null_values(&mut value);
|
||||
serde::json::to_writer_pretty(&mut ostream, &value).unwrap();
|
||||
json::to_writer_pretty(&mut ostream, &value).unwrap();
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -774,9 +761,11 @@ impl<'n, 'a> Engine<'n, 'a> {
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
err.issues.push(CLIError::UnknownParameter(key.to_string(),
|
||||
Vec::new() + &self.gp + &["due-max", "show-deleted", "updated-min", "completed-min", "max-results", "show-completed", "page-token", "completed-max", "show-hidden", "due-min"]
|
||||
));
|
||||
err.issues.push(CLIError::UnknownParameter(key.to_string(),
|
||||
{let mut v = Vec::new();
|
||||
v.extend(self.gp.iter().map(|v|*v));
|
||||
v.extend(["due-max", "show-deleted", "updated-min", "completed-min", "max-results", "show-completed", "page-token", "completed-max", "show-hidden", "due-min"].iter().map(|v|*v));
|
||||
v } ));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -801,7 +790,7 @@ impl<'n, 'a> Engine<'n, 'a> {
|
||||
Ok((mut response, output_schema)) => {
|
||||
let mut value = json::value::to_value(&output_schema);
|
||||
remove_json_null_values(&mut value);
|
||||
serde::json::to_writer_pretty(&mut ostream, &value).unwrap();
|
||||
json::to_writer_pretty(&mut ostream, &value).unwrap();
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -830,9 +819,11 @@ impl<'n, 'a> Engine<'n, 'a> {
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
err.issues.push(CLIError::UnknownParameter(key.to_string(),
|
||||
Vec::new() + &self.gp + &["parent", "previous"]
|
||||
));
|
||||
err.issues.push(CLIError::UnknownParameter(key.to_string(),
|
||||
{let mut v = Vec::new();
|
||||
v.extend(self.gp.iter().map(|v|*v));
|
||||
v.extend(["parent", "previous"].iter().map(|v|*v));
|
||||
v } ));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -857,7 +848,7 @@ impl<'n, 'a> Engine<'n, 'a> {
|
||||
Ok((mut response, output_schema)) => {
|
||||
let mut value = json::value::to_value(&output_schema);
|
||||
remove_json_null_values(&mut value);
|
||||
serde::json::to_writer_pretty(&mut ostream, &value).unwrap();
|
||||
json::to_writer_pretty(&mut ostream, &value).unwrap();
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -867,8 +858,9 @@ impl<'n, 'a> Engine<'n, 'a> {
|
||||
fn _tasks_patch(&self, opt: &ArgMatches<'n, 'a>, dry_run: bool, err: &mut InvalidOptionsError)
|
||||
-> Result<(), DoitError> {
|
||||
|
||||
let mut request = api::Task::default();
|
||||
let mut field_cursor = FieldCursor::default();
|
||||
let mut object = json::value::Value::Object(Default::default());
|
||||
|
||||
for kvarg in opt.values_of("kv").unwrap_or(Vec::new()).iter() {
|
||||
let last_errc = err.issues.len();
|
||||
let (key, value) = parse_kv_arg(&*kvarg, err, false);
|
||||
@@ -883,55 +875,34 @@ impl<'n, 'a> Engine<'n, 'a> {
|
||||
}
|
||||
continue;
|
||||
}
|
||||
match &temp_cursor.to_string()[..] {
|
||||
"status" => {
|
||||
request.status = Some(value.unwrap_or("").to_string());
|
||||
},
|
||||
"kind" => {
|
||||
request.kind = Some(value.unwrap_or("").to_string());
|
||||
},
|
||||
"parent" => {
|
||||
request.parent = Some(value.unwrap_or("").to_string());
|
||||
},
|
||||
"title" => {
|
||||
request.title = Some(value.unwrap_or("").to_string());
|
||||
},
|
||||
"deleted" => {
|
||||
request.deleted = Some(arg_from_str(value.unwrap_or("false"), err, "deleted", "boolean"));
|
||||
},
|
||||
"completed" => {
|
||||
request.completed = Some(value.unwrap_or("").to_string());
|
||||
},
|
||||
"updated" => {
|
||||
request.updated = Some(value.unwrap_or("").to_string());
|
||||
},
|
||||
"due" => {
|
||||
request.due = Some(value.unwrap_or("").to_string());
|
||||
},
|
||||
"etag" => {
|
||||
request.etag = Some(value.unwrap_or("").to_string());
|
||||
},
|
||||
"notes" => {
|
||||
request.notes = Some(value.unwrap_or("").to_string());
|
||||
},
|
||||
"position" => {
|
||||
request.position = Some(value.unwrap_or("").to_string());
|
||||
},
|
||||
"hidden" => {
|
||||
request.hidden = Some(arg_from_str(value.unwrap_or("false"), err, "hidden", "boolean"));
|
||||
},
|
||||
"id" => {
|
||||
request.id = Some(value.unwrap_or("").to_string());
|
||||
},
|
||||
"self-link" => {
|
||||
request.self_link = Some(value.unwrap_or("").to_string());
|
||||
},
|
||||
_ => {
|
||||
let suggestion = FieldCursor::did_you_mean(key, &vec!["completed", "deleted", "due", "etag", "hidden", "id", "kind", "notes", "parent", "position", "self-link", "status", "title", "updated"]);
|
||||
err.issues.push(CLIError::Field(FieldError::Unknown(temp_cursor.to_string(), suggestion, value.map(|v| v.to_string()))));
|
||||
}
|
||||
|
||||
let type_info =
|
||||
match &temp_cursor.to_string()[..] {
|
||||
"status" => Some(("status", JsonTypeInfo { jtype: JsonType::String, ctype: ComplexType::Pod })),
|
||||
"kind" => Some(("kind", JsonTypeInfo { jtype: JsonType::String, ctype: ComplexType::Pod })),
|
||||
"parent" => Some(("parent", JsonTypeInfo { jtype: JsonType::String, ctype: ComplexType::Pod })),
|
||||
"title" => Some(("title", JsonTypeInfo { jtype: JsonType::String, ctype: ComplexType::Pod })),
|
||||
"deleted" => Some(("deleted", JsonTypeInfo { jtype: JsonType::Boolean, ctype: ComplexType::Pod })),
|
||||
"completed" => Some(("completed", JsonTypeInfo { jtype: JsonType::String, ctype: ComplexType::Pod })),
|
||||
"updated" => Some(("updated", JsonTypeInfo { jtype: JsonType::String, ctype: ComplexType::Pod })),
|
||||
"due" => Some(("due", JsonTypeInfo { jtype: JsonType::String, ctype: ComplexType::Pod })),
|
||||
"etag" => Some(("etag", JsonTypeInfo { jtype: JsonType::String, ctype: ComplexType::Pod })),
|
||||
"notes" => Some(("notes", JsonTypeInfo { jtype: JsonType::String, ctype: ComplexType::Pod })),
|
||||
"position" => Some(("position", JsonTypeInfo { jtype: JsonType::String, ctype: ComplexType::Pod })),
|
||||
"hidden" => Some(("hidden", JsonTypeInfo { jtype: JsonType::Boolean, ctype: ComplexType::Pod })),
|
||||
"id" => Some(("id", JsonTypeInfo { jtype: JsonType::String, ctype: ComplexType::Pod })),
|
||||
"self-link" => Some(("selfLink", JsonTypeInfo { jtype: JsonType::String, ctype: ComplexType::Pod })),
|
||||
_ => {
|
||||
let suggestion = FieldCursor::did_you_mean(key, &vec!["completed", "deleted", "due", "etag", "hidden", "id", "kind", "notes", "parent", "position", "self-link", "status", "title", "updated"]);
|
||||
err.issues.push(CLIError::Field(FieldError::Unknown(temp_cursor.to_string(), suggestion, value.map(|v| v.to_string()))));
|
||||
None
|
||||
}
|
||||
};
|
||||
if let Some((field_cursor_str, type_info)) = type_info {
|
||||
FieldCursor::from(field_cursor_str).set_json_value(&mut object, value.unwrap(), type_info, err, &temp_cursor);
|
||||
}
|
||||
}
|
||||
let mut request: api::Task = json::value::from_value(object).unwrap();
|
||||
let mut call = self.hub.tasks().patch(request, opt.value_of("tasklist").unwrap_or(""), opt.value_of("task").unwrap_or(""));
|
||||
for parg in opt.values_of("v").unwrap_or(Vec::new()).iter() {
|
||||
let (key, value) = parse_kv_arg(&*parg, err, false);
|
||||
@@ -946,9 +917,11 @@ impl<'n, 'a> Engine<'n, 'a> {
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
err.issues.push(CLIError::UnknownParameter(key.to_string(),
|
||||
Vec::new() + &self.gp + &[]
|
||||
));
|
||||
err.issues.push(CLIError::UnknownParameter(key.to_string(),
|
||||
{let mut v = Vec::new();
|
||||
v.extend(self.gp.iter().map(|v|*v));
|
||||
v.extend([].iter().map(|v|*v));
|
||||
v } ));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -973,7 +946,7 @@ impl<'n, 'a> Engine<'n, 'a> {
|
||||
Ok((mut response, output_schema)) => {
|
||||
let mut value = json::value::to_value(&output_schema);
|
||||
remove_json_null_values(&mut value);
|
||||
serde::json::to_writer_pretty(&mut ostream, &value).unwrap();
|
||||
json::to_writer_pretty(&mut ostream, &value).unwrap();
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -983,8 +956,9 @@ impl<'n, 'a> Engine<'n, 'a> {
|
||||
fn _tasks_update(&self, opt: &ArgMatches<'n, 'a>, dry_run: bool, err: &mut InvalidOptionsError)
|
||||
-> Result<(), DoitError> {
|
||||
|
||||
let mut request = api::Task::default();
|
||||
let mut field_cursor = FieldCursor::default();
|
||||
let mut object = json::value::Value::Object(Default::default());
|
||||
|
||||
for kvarg in opt.values_of("kv").unwrap_or(Vec::new()).iter() {
|
||||
let last_errc = err.issues.len();
|
||||
let (key, value) = parse_kv_arg(&*kvarg, err, false);
|
||||
@@ -999,55 +973,34 @@ impl<'n, 'a> Engine<'n, 'a> {
|
||||
}
|
||||
continue;
|
||||
}
|
||||
match &temp_cursor.to_string()[..] {
|
||||
"status" => {
|
||||
request.status = Some(value.unwrap_or("").to_string());
|
||||
},
|
||||
"kind" => {
|
||||
request.kind = Some(value.unwrap_or("").to_string());
|
||||
},
|
||||
"parent" => {
|
||||
request.parent = Some(value.unwrap_or("").to_string());
|
||||
},
|
||||
"title" => {
|
||||
request.title = Some(value.unwrap_or("").to_string());
|
||||
},
|
||||
"deleted" => {
|
||||
request.deleted = Some(arg_from_str(value.unwrap_or("false"), err, "deleted", "boolean"));
|
||||
},
|
||||
"completed" => {
|
||||
request.completed = Some(value.unwrap_or("").to_string());
|
||||
},
|
||||
"updated" => {
|
||||
request.updated = Some(value.unwrap_or("").to_string());
|
||||
},
|
||||
"due" => {
|
||||
request.due = Some(value.unwrap_or("").to_string());
|
||||
},
|
||||
"etag" => {
|
||||
request.etag = Some(value.unwrap_or("").to_string());
|
||||
},
|
||||
"notes" => {
|
||||
request.notes = Some(value.unwrap_or("").to_string());
|
||||
},
|
||||
"position" => {
|
||||
request.position = Some(value.unwrap_or("").to_string());
|
||||
},
|
||||
"hidden" => {
|
||||
request.hidden = Some(arg_from_str(value.unwrap_or("false"), err, "hidden", "boolean"));
|
||||
},
|
||||
"id" => {
|
||||
request.id = Some(value.unwrap_or("").to_string());
|
||||
},
|
||||
"self-link" => {
|
||||
request.self_link = Some(value.unwrap_or("").to_string());
|
||||
},
|
||||
_ => {
|
||||
let suggestion = FieldCursor::did_you_mean(key, &vec!["completed", "deleted", "due", "etag", "hidden", "id", "kind", "notes", "parent", "position", "self-link", "status", "title", "updated"]);
|
||||
err.issues.push(CLIError::Field(FieldError::Unknown(temp_cursor.to_string(), suggestion, value.map(|v| v.to_string()))));
|
||||
}
|
||||
|
||||
let type_info =
|
||||
match &temp_cursor.to_string()[..] {
|
||||
"status" => Some(("status", JsonTypeInfo { jtype: JsonType::String, ctype: ComplexType::Pod })),
|
||||
"kind" => Some(("kind", JsonTypeInfo { jtype: JsonType::String, ctype: ComplexType::Pod })),
|
||||
"parent" => Some(("parent", JsonTypeInfo { jtype: JsonType::String, ctype: ComplexType::Pod })),
|
||||
"title" => Some(("title", JsonTypeInfo { jtype: JsonType::String, ctype: ComplexType::Pod })),
|
||||
"deleted" => Some(("deleted", JsonTypeInfo { jtype: JsonType::Boolean, ctype: ComplexType::Pod })),
|
||||
"completed" => Some(("completed", JsonTypeInfo { jtype: JsonType::String, ctype: ComplexType::Pod })),
|
||||
"updated" => Some(("updated", JsonTypeInfo { jtype: JsonType::String, ctype: ComplexType::Pod })),
|
||||
"due" => Some(("due", JsonTypeInfo { jtype: JsonType::String, ctype: ComplexType::Pod })),
|
||||
"etag" => Some(("etag", JsonTypeInfo { jtype: JsonType::String, ctype: ComplexType::Pod })),
|
||||
"notes" => Some(("notes", JsonTypeInfo { jtype: JsonType::String, ctype: ComplexType::Pod })),
|
||||
"position" => Some(("position", JsonTypeInfo { jtype: JsonType::String, ctype: ComplexType::Pod })),
|
||||
"hidden" => Some(("hidden", JsonTypeInfo { jtype: JsonType::Boolean, ctype: ComplexType::Pod })),
|
||||
"id" => Some(("id", JsonTypeInfo { jtype: JsonType::String, ctype: ComplexType::Pod })),
|
||||
"self-link" => Some(("selfLink", JsonTypeInfo { jtype: JsonType::String, ctype: ComplexType::Pod })),
|
||||
_ => {
|
||||
let suggestion = FieldCursor::did_you_mean(key, &vec!["completed", "deleted", "due", "etag", "hidden", "id", "kind", "notes", "parent", "position", "self-link", "status", "title", "updated"]);
|
||||
err.issues.push(CLIError::Field(FieldError::Unknown(temp_cursor.to_string(), suggestion, value.map(|v| v.to_string()))));
|
||||
None
|
||||
}
|
||||
};
|
||||
if let Some((field_cursor_str, type_info)) = type_info {
|
||||
FieldCursor::from(field_cursor_str).set_json_value(&mut object, value.unwrap(), type_info, err, &temp_cursor);
|
||||
}
|
||||
}
|
||||
let mut request: api::Task = json::value::from_value(object).unwrap();
|
||||
let mut call = self.hub.tasks().update(request, opt.value_of("tasklist").unwrap_or(""), opt.value_of("task").unwrap_or(""));
|
||||
for parg in opt.values_of("v").unwrap_or(Vec::new()).iter() {
|
||||
let (key, value) = parse_kv_arg(&*parg, err, false);
|
||||
@@ -1062,9 +1015,11 @@ impl<'n, 'a> Engine<'n, 'a> {
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
err.issues.push(CLIError::UnknownParameter(key.to_string(),
|
||||
Vec::new() + &self.gp + &[]
|
||||
));
|
||||
err.issues.push(CLIError::UnknownParameter(key.to_string(),
|
||||
{let mut v = Vec::new();
|
||||
v.extend(self.gp.iter().map(|v|*v));
|
||||
v.extend([].iter().map(|v|*v));
|
||||
v } ));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1089,7 +1044,7 @@ impl<'n, 'a> Engine<'n, 'a> {
|
||||
Ok((mut response, output_schema)) => {
|
||||
let mut value = json::value::to_value(&output_schema);
|
||||
remove_json_null_values(&mut value);
|
||||
serde::json::to_writer_pretty(&mut ostream, &value).unwrap();
|
||||
json::to_writer_pretty(&mut ostream, &value).unwrap();
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -1239,6 +1194,7 @@ impl<'n, 'a> Engine<'n, 'a> {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut exit_status = 0i32;
|
||||
let arg_data = [
|
||||
("tasklists", "methods: 'delete', 'get', 'insert', 'list', 'patch' and 'update'", vec![
|
||||
("delete",
|
||||
@@ -1594,7 +1550,7 @@ fn main() {
|
||||
|
||||
let mut app = App::new("tasks1")
|
||||
.author("Sebastian Thiel <byronimo@gmail.com>")
|
||||
.version("0.2.0+20141121")
|
||||
.version("0.3.0+20141121")
|
||||
.about("Lets you manage your tasks and task lists.")
|
||||
.after_help("All documentation details can be found at http://byron.github.io/google-apis-rs/google_tasks1_cli")
|
||||
.arg(Arg::with_name("url")
|
||||
@@ -1635,7 +1591,8 @@ fn main() {
|
||||
(_ , &Some(f)) => f,
|
||||
_ => unreachable!(),
|
||||
};
|
||||
let mut arg = Arg::with_name(arg_name_str);
|
||||
let mut arg = Arg::with_name(arg_name_str)
|
||||
.empty_values(false);
|
||||
if let &Some(short_flag) = flag {
|
||||
arg = arg.short(short_flag);
|
||||
}
|
||||
@@ -1663,12 +1620,12 @@ fn main() {
|
||||
let debug = matches.is_present("debug");
|
||||
match Engine::new(matches) {
|
||||
Err(err) => {
|
||||
env::set_exit_status(err.exit_code);
|
||||
exit_status = err.exit_code;
|
||||
writeln!(io::stderr(), "{}", err).ok();
|
||||
},
|
||||
Ok(engine) => {
|
||||
if let Err(doit_err) = engine.doit() {
|
||||
env::set_exit_status(1);
|
||||
exit_status = 1;
|
||||
match doit_err {
|
||||
DoitError::IoError(path, err) => {
|
||||
writeln!(io::stderr(), "Failed to open output file '{}': {}", path, err).ok();
|
||||
@@ -1684,4 +1641,6 @@ fn main() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::process::exit(exit_status);
|
||||
}
|
||||
Reference in New Issue
Block a user