Regen all APIs from new JSON

This commit is contained in:
Guy Taylor
2019-04-04 18:16:26 +01:00
committed by Sebastian Thiel
parent 86a884c48b
commit 2ad9f3781d
1212 changed files with 440610 additions and 142417 deletions

View File

@@ -79,6 +79,9 @@ impl<'n> Engine<'n> {
Ok(())
} else {
assert!(err.issues.len() == 0);
for scope in self.opt.values_of("url").map(|i|i.collect()).unwrap_or(Vec::new()).iter() {
call = call.add_scope(scope);
}
let mut ostream = match writer_from_opts(opt.value_of("out")) {
Ok(mut f) => f,
Err(io_err) => return Err(DoitError::IoError(opt.value_of("out").unwrap_or("-").to_string(), io_err)),
@@ -170,6 +173,9 @@ impl<'n> Engine<'n> {
Ok(())
} else {
assert!(err.issues.len() == 0);
for scope in self.opt.values_of("url").map(|i|i.collect()).unwrap_or(Vec::new()).iter() {
call = call.add_scope(scope);
}
let mut ostream = match writer_from_opts(opt.value_of("out")) {
Ok(mut f) => f,
Err(io_err) => return Err(DoitError::IoError(opt.value_of("out").unwrap_or("-").to_string(), io_err)),
@@ -196,6 +202,9 @@ impl<'n> Engine<'n> {
for parg in opt.values_of("v").map(|i|i.collect()).unwrap_or(Vec::new()).iter() {
let (key, value) = parse_kv_arg(&*parg, err, false);
match key {
"filter" => {
call = call.filter(value.unwrap_or(""));
},
"customer-id" => {
call = call.customer_id(value.unwrap_or(""));
},
@@ -212,7 +221,7 @@ impl<'n> Engine<'n> {
err.issues.push(CLIError::UnknownParameter(key.to_string(),
{let mut v = Vec::new();
v.extend(self.gp.iter().map(|v|*v));
v.extend(["customer-id"].iter().map(|v|*v));
v.extend(["filter", "customer-id"].iter().map(|v|*v));
v } ));
}
}
@@ -223,6 +232,9 @@ impl<'n> Engine<'n> {
Ok(())
} else {
assert!(err.issues.len() == 0);
for scope in self.opt.values_of("url").map(|i|i.collect()).unwrap_or(Vec::new()).iter() {
call = call.add_scope(scope);
}
let mut ostream = match writer_from_opts(opt.value_of("out")) {
Ok(mut f) => f,
Err(io_err) => return Err(DoitError::IoError(opt.value_of("out").unwrap_or("-").to_string(), io_err)),
@@ -276,6 +288,9 @@ impl<'n> Engine<'n> {
Ok(())
} else {
assert!(err.issues.len() == 0);
for scope in self.opt.values_of("url").map(|i|i.collect()).unwrap_or(Vec::new()).iter() {
call = call.add_scope(scope);
}
let mut ostream = match writer_from_opts(opt.value_of("out")) {
Ok(mut f) => f,
Err(io_err) => return Err(DoitError::IoError(opt.value_of("out").unwrap_or("-").to_string(), io_err)),
@@ -341,6 +356,238 @@ impl<'n> Engine<'n> {
Ok(())
} else {
assert!(err.issues.len() == 0);
for scope in self.opt.values_of("url").map(|i|i.collect()).unwrap_or(Vec::new()).iter() {
call = call.add_scope(scope);
}
let mut ostream = match writer_from_opts(opt.value_of("out")) {
Ok(mut f) => f,
Err(io_err) => return Err(DoitError::IoError(opt.value_of("out").unwrap_or("-").to_string(), io_err)),
};
match match protocol {
CallType::Standard => call.doit(),
_ => unreachable!()
} {
Err(api_err) => Err(DoitError::ApiError(api_err)),
Ok((mut response, output_schema)) => {
let mut value = json::value::to_value(&output_schema).expect("serde to work");
remove_json_null_values(&mut value);
json::to_writer_pretty(&mut ostream, &value).unwrap();
ostream.flush().unwrap();
Ok(())
}
}
}
}
fn _alerts_undelete(&self, opt: &ArgMatches<'n>, dry_run: bool, err: &mut InvalidOptionsError)
-> Result<(), DoitError> {
let mut field_cursor = FieldCursor::default();
let mut object = json::value::Value::Object(Default::default());
for kvarg in opt.values_of("kv").map(|i|i.collect()).unwrap_or(Vec::new()).iter() {
let last_errc = err.issues.len();
let (key, value) = parse_kv_arg(&*kvarg, err, false);
let mut temp_cursor = field_cursor.clone();
if let Err(field_err) = temp_cursor.set(&*key) {
err.issues.push(field_err);
}
if value.is_none() {
field_cursor = temp_cursor.clone();
if err.issues.len() > last_errc {
err.issues.remove(last_errc);
}
continue;
}
let type_info: Option<(&'static str, JsonTypeInfo)> =
match &temp_cursor.to_string()[..] {
"customer-id" => Some(("customerId", JsonTypeInfo { jtype: JsonType::String, ctype: ComplexType::Pod })),
_ => {
let suggestion = FieldCursor::did_you_mean(key, &vec!["customer-id"]);
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::UndeleteAlertRequest = json::value::from_value(object).unwrap();
let mut call = self.hub.alerts().undelete(request, opt.value_of("alert-id").unwrap_or(""));
for parg in opt.values_of("v").map(|i|i.collect()).unwrap_or(Vec::new()).iter() {
let (key, value) = parse_kv_arg(&*parg, err, false);
match key {
_ => {
let mut found = false;
for param in &self.gp {
if key == *param {
found = true;
call = call.param(self.gpm.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset"));
break;
}
}
if !found {
err.issues.push(CLIError::UnknownParameter(key.to_string(),
{let mut v = Vec::new();
v.extend(self.gp.iter().map(|v|*v));
v } ));
}
}
}
}
let protocol = CallType::Standard;
if dry_run {
Ok(())
} else {
assert!(err.issues.len() == 0);
for scope in self.opt.values_of("url").map(|i|i.collect()).unwrap_or(Vec::new()).iter() {
call = call.add_scope(scope);
}
let mut ostream = match writer_from_opts(opt.value_of("out")) {
Ok(mut f) => f,
Err(io_err) => return Err(DoitError::IoError(opt.value_of("out").unwrap_or("-").to_string(), io_err)),
};
match match protocol {
CallType::Standard => call.doit(),
_ => unreachable!()
} {
Err(api_err) => Err(DoitError::ApiError(api_err)),
Ok((mut response, output_schema)) => {
let mut value = json::value::to_value(&output_schema).expect("serde to work");
remove_json_null_values(&mut value);
json::to_writer_pretty(&mut ostream, &value).unwrap();
ostream.flush().unwrap();
Ok(())
}
}
}
}
fn _methods_get_settings(&self, opt: &ArgMatches<'n>, dry_run: bool, err: &mut InvalidOptionsError)
-> Result<(), DoitError> {
let mut call = self.hub.methods().get_settings();
for parg in opt.values_of("v").map(|i|i.collect()).unwrap_or(Vec::new()).iter() {
let (key, value) = parse_kv_arg(&*parg, err, false);
match key {
"customer-id" => {
call = call.customer_id(value.unwrap_or(""));
},
_ => {
let mut found = false;
for param in &self.gp {
if key == *param {
found = true;
call = call.param(self.gpm.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset"));
break;
}
}
if !found {
err.issues.push(CLIError::UnknownParameter(key.to_string(),
{let mut v = Vec::new();
v.extend(self.gp.iter().map(|v|*v));
v.extend(["customer-id"].iter().map(|v|*v));
v } ));
}
}
}
}
let protocol = CallType::Standard;
if dry_run {
Ok(())
} else {
assert!(err.issues.len() == 0);
for scope in self.opt.values_of("url").map(|i|i.collect()).unwrap_or(Vec::new()).iter() {
call = call.add_scope(scope);
}
let mut ostream = match writer_from_opts(opt.value_of("out")) {
Ok(mut f) => f,
Err(io_err) => return Err(DoitError::IoError(opt.value_of("out").unwrap_or("-").to_string(), io_err)),
};
match match protocol {
CallType::Standard => call.doit(),
_ => unreachable!()
} {
Err(api_err) => Err(DoitError::ApiError(api_err)),
Ok((mut response, output_schema)) => {
let mut value = json::value::to_value(&output_schema).expect("serde to work");
remove_json_null_values(&mut value);
json::to_writer_pretty(&mut ostream, &value).unwrap();
ostream.flush().unwrap();
Ok(())
}
}
}
}
fn _methods_update_settings(&self, opt: &ArgMatches<'n>, dry_run: bool, err: &mut InvalidOptionsError)
-> Result<(), DoitError> {
let mut field_cursor = FieldCursor::default();
let mut object = json::value::Value::Object(Default::default());
for kvarg in opt.values_of("kv").map(|i|i.collect()).unwrap_or(Vec::new()).iter() {
let last_errc = err.issues.len();
let (key, value) = parse_kv_arg(&*kvarg, err, false);
let mut temp_cursor = field_cursor.clone();
if let Err(field_err) = temp_cursor.set(&*key) {
err.issues.push(field_err);
}
if value.is_none() {
field_cursor = temp_cursor.clone();
if err.issues.len() > last_errc {
err.issues.remove(last_errc);
}
continue;
}
let type_info: Option<(&'static str, JsonTypeInfo)> =
match &temp_cursor.to_string()[..] {
_ => {
let suggestion = FieldCursor::did_you_mean(key, &vec![]);
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::Settings = json::value::from_value(object).unwrap();
let mut call = self.hub.methods().update_settings(request);
for parg in opt.values_of("v").map(|i|i.collect()).unwrap_or(Vec::new()).iter() {
let (key, value) = parse_kv_arg(&*parg, err, false);
match key {
"customer-id" => {
call = call.customer_id(value.unwrap_or(""));
},
_ => {
let mut found = false;
for param in &self.gp {
if key == *param {
found = true;
call = call.param(self.gpm.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset"));
break;
}
}
if !found {
err.issues.push(CLIError::UnknownParameter(key.to_string(),
{let mut v = Vec::new();
v.extend(self.gp.iter().map(|v|*v));
v.extend(["customer-id"].iter().map(|v|*v));
v } ));
}
}
}
}
let protocol = CallType::Standard;
if dry_run {
Ok(())
} else {
assert!(err.issues.len() == 0);
for scope in self.opt.values_of("url").map(|i|i.collect()).unwrap_or(Vec::new()).iter() {
call = call.add_scope(scope);
}
let mut ostream = match writer_from_opts(opt.value_of("out")) {
Ok(mut f) => f,
Err(io_err) => return Err(DoitError::IoError(opt.value_of("out").unwrap_or("-").to_string(), io_err)),
@@ -383,12 +630,29 @@ impl<'n> Engine<'n> {
("list", Some(opt)) => {
call_result = self._alerts_list(opt, dry_run, &mut err);
},
("undelete", Some(opt)) => {
call_result = self._alerts_undelete(opt, dry_run, &mut err);
},
_ => {
err.issues.push(CLIError::MissingMethodError("alerts".to_string()));
writeln!(io::stderr(), "{}\n", opt.usage()).ok();
}
}
},
("methods", Some(opt)) => {
match opt.subcommand() {
("get-settings", Some(opt)) => {
call_result = self._methods_get_settings(opt, dry_run, &mut err);
},
("update-settings", Some(opt)) => {
call_result = self._methods_update_settings(opt, dry_run, &mut err);
},
_ => {
err.issues.push(CLIError::MissingMethodError("methods".to_string()));
writeln!(io::stderr(), "{}\n", opt.usage()).ok();
}
}
},
_ => {
err.issues.push(CLIError::MissingCommandError);
writeln!(io::stderr(), "{}\n", self.opt.usage()).ok();
@@ -474,14 +738,13 @@ impl<'n> Engine<'n> {
fn main() {
let mut exit_status = 0i32;
let arg_data = [
("alerts", "methods: 'delete', 'feedback-create', 'feedback-list', 'get' and 'list'", vec![
("alerts", "methods: 'delete', 'feedback-create', 'feedback-list', 'get', 'list' and 'undelete'", vec![
("delete",
Some(r##"Marks the specified alert for deletion. An alert that has been marked for
deletion will be excluded from the results of a List operation by default,
and will be removed from the Alert Center after 30 days.
Marking an alert for deletion will have no effect on an alert which has
deletion is removed from Alert Center after 30 days.
Marking an alert for deletion has no effect on an alert which has
already been marked for deletion. Attempting to mark a nonexistent alert
for deletion will return NOT_FOUND."##),
for deletion results in a `NOT_FOUND` error."##),
"Details at http://byron.github.io/google-apis-rs/google_alertcenter1_beta1_cli/alerts_delete",
vec![
(Some(r##"alert-id"##),
@@ -503,13 +766,13 @@ fn main() {
Some(false)),
]),
("feedback-create",
Some(r##"Creates a new alert feedback."##),
Some(r##"Creates new feedback for an alert. Attempting to create a feedback for
a non-existent alert returns `NOT_FOUND` error."##),
"Details at http://byron.github.io/google-apis-rs/google_alertcenter1_beta1_cli/alerts_feedback-create",
vec![
(Some(r##"alert-id"##),
None,
Some(r##"Required. The identifier of the alert this feedback belongs to.
Returns a NOT_FOUND error if no such alert."##),
Some(r##"Required. The identifier of the alert this feedback belongs to."##),
Some(true),
Some(false)),
@@ -532,13 +795,14 @@ fn main() {
Some(false)),
]),
("feedback-list",
Some(r##"Lists all the feedback for an alert."##),
Some(r##"Lists all the feedback for an alert. Attempting to list feedbacks for
a non-existent alert returns `NOT_FOUND` error."##),
"Details at http://byron.github.io/google-apis-rs/google_alertcenter1_beta1_cli/alerts_feedback-list",
vec![
(Some(r##"alert-id"##),
None,
Some(r##"Required. The alert identifier.
If the alert does not exist returns a NOT_FOUND error."##),
The "-" wildcard could be used to represent all alerts."##),
Some(true),
Some(false)),
@@ -555,7 +819,8 @@ fn main() {
Some(false)),
]),
("get",
Some(r##"Gets the specified alert."##),
Some(r##"Gets the specified alert. Attempting to get a nonexistent alert returns
`NOT_FOUND` error."##),
"Details at http://byron.github.io/google-apis-rs/google_alertcenter1_beta1_cli/alerts_get",
vec![
(Some(r##"alert-id"##),
@@ -577,7 +842,7 @@ fn main() {
Some(false)),
]),
("list",
Some(r##"Lists all the alerts for the current user and application."##),
Some(r##"Lists the alerts."##),
"Details at http://byron.github.io/google-apis-rs/google_alertcenter1_beta1_cli/alerts_list",
vec![
(Some(r##"v"##),
@@ -586,6 +851,79 @@ fn main() {
Some(false),
Some(true)),
(Some(r##"out"##),
Some(r##"o"##),
Some(r##"Specify the file into which to write the program's output"##),
Some(false),
Some(false)),
]),
("undelete",
Some(r##"Restores, or "undeletes", an alert that was marked for deletion within the
past 30 days. Attempting to undelete an alert which was marked for deletion
over 30 days ago (which has been removed from the Alert Center database) or
a nonexistent alert returns a `NOT_FOUND` error. Attempting to
undelete an alert which has not been marked for deletion has no effect."##),
"Details at http://byron.github.io/google-apis-rs/google_alertcenter1_beta1_cli/alerts_undelete",
vec![
(Some(r##"alert-id"##),
None,
Some(r##"Required. The identifier of the alert to undelete."##),
Some(true),
Some(false)),
(Some(r##"kv"##),
Some(r##"r"##),
Some(r##"Set various fields of the request structure, matching the key=value form"##),
Some(true),
Some(true)),
(Some(r##"v"##),
Some(r##"p"##),
Some(r##"Set various optional parameters, matching the key=value form"##),
Some(false),
Some(true)),
(Some(r##"out"##),
Some(r##"o"##),
Some(r##"Specify the file into which to write the program's output"##),
Some(false),
Some(false)),
]),
]),
("methods", "methods: 'get-settings' and 'update-settings'", vec![
("get-settings",
Some(r##"Returns customer-level settings."##),
"Details at http://byron.github.io/google-apis-rs/google_alertcenter1_beta1_cli/methods_get-settings",
vec![
(Some(r##"v"##),
Some(r##"p"##),
Some(r##"Set various optional parameters, matching the key=value form"##),
Some(false),
Some(true)),
(Some(r##"out"##),
Some(r##"o"##),
Some(r##"Specify the file into which to write the program's output"##),
Some(false),
Some(false)),
]),
("update-settings",
Some(r##"Updates the customer-level settings."##),
"Details at http://byron.github.io/google-apis-rs/google_alertcenter1_beta1_cli/methods_update-settings",
vec![
(Some(r##"kv"##),
Some(r##"r"##),
Some(r##"Set various fields of the request structure, matching the key=value form"##),
Some(true),
Some(true)),
(Some(r##"v"##),
Some(r##"p"##),
Some(r##"Set various optional parameters, matching the key=value form"##),
Some(false),
Some(true)),
(Some(r##"out"##),
Some(r##"o"##),
Some(r##"Specify the file into which to write the program's output"##),
@@ -598,9 +936,14 @@ fn main() {
let mut app = App::new("alertcenter1-beta1")
.author("Sebastian Thiel <byronimo@gmail.com>")
.version("1.0.8+20181011")
.about("G Suite Alert Center API to view and manage alerts on issues affecting your domain.")
.version("1.0.8+20190329")
.about("Manages alerts on issues affecting your domain.")
.after_help("All documentation details can be found at http://byron.github.io/google-apis-rs/google_alertcenter1_beta1_cli")
.arg(Arg::with_name("url")
.long("scope")
.help("Specify the authentication a method should be executed in. Each scope requires the user to grant this application permission to use it.If unset, it defaults to the shortest scope url for a particular method.")
.multiple(true)
.takes_value(true))
.arg(Arg::with_name("folder")
.long("config-dir")
.help("A directory into which we will store our persistent data. Defaults to a user-writable directory that we will create during the first invocation.[default: ~/.google-service-cli")