From a3289420337c7f607f4393fcf0832167267cc473 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sat, 25 Apr 2015 09:49:18 +0200 Subject: [PATCH] feat(API): improved error handling We are now able to decode detailed errors and pass them on. This allows the CLI to provide more useful error responses. Additionally, the CLI will only print debug responses in --debug mode. Fixes #82 --- gen/admin1_directory-cli/Cargo.toml | 31 + gen/admin1_directory-cli/LICENSE.md | 30 + gen/admin1_directory-cli/README.md | 4 + gen/admin1_directory-cli/mkdocs.yml | 83 + gen/admin1_directory-cli/src/cmn.rs | 454 ++ gen/admin1_directory-cli/src/main.rs | 4775 +++++++++++++++ gen/admin1_reports-cli/Cargo.toml | 31 + gen/admin1_reports-cli/LICENSE.md | 30 + gen/admin1_reports-cli/README.md | 4 + gen/admin1_reports-cli/mkdocs.yml | 21 + gen/admin1_reports-cli/src/cmn.rs | 454 ++ gen/admin1_reports-cli/src/main.rs | 561 ++ gen/admin2_email_migration-cli/Cargo.toml | 31 + gen/admin2_email_migration-cli/LICENSE.md | 30 + gen/admin2_email_migration-cli/README.md | 4 + gen/admin2_email_migration-cli/mkdocs.yml | 17 + gen/admin2_email_migration-cli/src/cmn.rs | 454 ++ gen/admin2_email_migration-cli/src/main.rs | 248 + gen/adsensehost4d1-cli/Cargo.toml | 31 + gen/adsensehost4d1-cli/LICENSE.md | 30 + gen/adsensehost4d1-cli/README.md | 4 + gen/adsensehost4d1-cli/mkdocs.yml | 42 + gen/adsensehost4d1-cli/src/cmn.rs | 454 ++ gen/adsensehost4d1-cli/src/main.rs | 1979 ++++++ gen/audit1-cli/Cargo.toml | 31 + gen/audit1-cli/LICENSE.md | 30 + gen/audit1-cli/README.md | 4 + gen/audit1-cli/mkdocs.yml | 17 + gen/audit1-cli/src/cmn.rs | 454 ++ gen/audit1-cli/src/main.rs | 219 + gen/coordinate1-cli/Cargo.toml | 31 + gen/coordinate1-cli/LICENSE.md | 30 + gen/coordinate1-cli/README.md | 4 + gen/coordinate1-cli/mkdocs.yml | 28 + gen/coordinate1-cli/src/cmn.rs | 454 ++ gen/coordinate1-cli/src/main.rs | 1192 ++++ gen/customsearch1-cli/Cargo.toml | 31 + gen/customsearch1-cli/LICENSE.md | 30 + gen/customsearch1-cli/README.md | 4 + gen/customsearch1-cli/mkdocs.yml | 17 + gen/customsearch1-cli/src/cmn.rs | 454 ++ gen/customsearch1-cli/src/main.rs | 285 + gen/drive2-cli/Cargo.toml | 31 + gen/drive2-cli/LICENSE.md | 30 + gen/drive2-cli/README.md | 4 + gen/drive2-cli/mkdocs.yml | 75 + gen/drive2-cli/src/cmn.rs | 454 ++ gen/drive2-cli/src/main.rs | 6468 ++++++++++++++++++++ gen/games1-cli/Cargo.toml | 31 + gen/games1-cli/LICENSE.md | 30 + gen/games1-cli/README.md | 4 + gen/games1-cli/mkdocs.yml | 68 + gen/games1-cli/src/cmn.rs | 454 ++ gen/games1-cli/src/main.rs | 3364 ++++++++++ gen/identitytoolkit3-cli/Cargo.toml | 31 + gen/identitytoolkit3-cli/LICENSE.md | 30 + gen/identitytoolkit3-cli/README.md | 4 + gen/identitytoolkit3-cli/mkdocs.yml | 28 + gen/identitytoolkit3-cli/src/cmn.rs | 454 ++ gen/identitytoolkit3-cli/src/main.rs | 1006 +++ gen/logging1_beta3-cli/Cargo.toml | 30 + gen/logging1_beta3-cli/LICENSE.md | 30 + gen/logging1_beta3-cli/README.md | 4 + gen/logging1_beta3-cli/mkdocs.yml | 31 + gen/logging1_beta3-cli/src/cmn.rs | 454 ++ gen/logging1_beta3-cli/src/main.rs | 1067 ++++ gen/reseller1_sandbox-cli/Cargo.toml | 31 + gen/reseller1_sandbox-cli/LICENSE.md | 30 + gen/reseller1_sandbox-cli/README.md | 4 + gen/reseller1_sandbox-cli/mkdocs.yml | 30 + gen/reseller1_sandbox-cli/src/cmn.rs | 454 ++ gen/reseller1_sandbox-cli/src/main.rs | 1290 ++++ gen/tagmanager1-cli/Cargo.toml | 31 + gen/tagmanager1-cli/LICENSE.md | 30 + gen/tagmanager1-cli/README.md | 4 + gen/tagmanager1-cli/mkdocs.yml | 62 + gen/tagmanager1-cli/src/cmn.rs | 454 ++ gen/tagmanager1-cli/src/main.rs | 3484 +++++++++++ gen/taskqueue1_beta2-cli/Cargo.toml | 31 + gen/taskqueue1_beta2-cli/LICENSE.md | 30 + gen/taskqueue1_beta2-cli/README.md | 4 + gen/taskqueue1_beta2-cli/mkdocs.yml | 24 + gen/taskqueue1_beta2-cli/src/cmn.rs | 454 ++ gen/taskqueue1_beta2-cli/src/main.rs | 648 ++ gen/webfonts1-cli/Cargo.toml | 31 + gen/webfonts1-cli/LICENSE.md | 30 + gen/webfonts1-cli/README.md | 4 + gen/webfonts1-cli/mkdocs.yml | 17 + gen/webfonts1-cli/src/cmn.rs | 454 ++ gen/webfonts1-cli/src/main.rs | 195 + src/mako/api/lib.rs.mako | 2 +- src/mako/api/lib/mbuild.mako | 16 +- src/mako/cli/main.rs.mako | 8 +- src/rust/api/cmn.rs | 48 +- 94 files changed, 35183 insertions(+), 16 deletions(-) create mode 100644 gen/admin1_directory-cli/Cargo.toml create mode 100644 gen/admin1_directory-cli/LICENSE.md create mode 100644 gen/admin1_directory-cli/README.md create mode 100644 gen/admin1_directory-cli/mkdocs.yml create mode 100644 gen/admin1_directory-cli/src/cmn.rs create mode 100644 gen/admin1_directory-cli/src/main.rs create mode 100644 gen/admin1_reports-cli/Cargo.toml create mode 100644 gen/admin1_reports-cli/LICENSE.md create mode 100644 gen/admin1_reports-cli/README.md create mode 100644 gen/admin1_reports-cli/mkdocs.yml create mode 100644 gen/admin1_reports-cli/src/cmn.rs create mode 100644 gen/admin1_reports-cli/src/main.rs create mode 100644 gen/admin2_email_migration-cli/Cargo.toml create mode 100644 gen/admin2_email_migration-cli/LICENSE.md create mode 100644 gen/admin2_email_migration-cli/README.md create mode 100644 gen/admin2_email_migration-cli/mkdocs.yml create mode 100644 gen/admin2_email_migration-cli/src/cmn.rs create mode 100644 gen/admin2_email_migration-cli/src/main.rs create mode 100644 gen/adsensehost4d1-cli/Cargo.toml create mode 100644 gen/adsensehost4d1-cli/LICENSE.md create mode 100644 gen/adsensehost4d1-cli/README.md create mode 100644 gen/adsensehost4d1-cli/mkdocs.yml create mode 100644 gen/adsensehost4d1-cli/src/cmn.rs create mode 100644 gen/adsensehost4d1-cli/src/main.rs create mode 100644 gen/audit1-cli/Cargo.toml create mode 100644 gen/audit1-cli/LICENSE.md create mode 100644 gen/audit1-cli/README.md create mode 100644 gen/audit1-cli/mkdocs.yml create mode 100644 gen/audit1-cli/src/cmn.rs create mode 100644 gen/audit1-cli/src/main.rs create mode 100644 gen/coordinate1-cli/Cargo.toml create mode 100644 gen/coordinate1-cli/LICENSE.md create mode 100644 gen/coordinate1-cli/README.md create mode 100644 gen/coordinate1-cli/mkdocs.yml create mode 100644 gen/coordinate1-cli/src/cmn.rs create mode 100644 gen/coordinate1-cli/src/main.rs create mode 100644 gen/customsearch1-cli/Cargo.toml create mode 100644 gen/customsearch1-cli/LICENSE.md create mode 100644 gen/customsearch1-cli/README.md create mode 100644 gen/customsearch1-cli/mkdocs.yml create mode 100644 gen/customsearch1-cli/src/cmn.rs create mode 100644 gen/customsearch1-cli/src/main.rs create mode 100644 gen/drive2-cli/Cargo.toml create mode 100644 gen/drive2-cli/LICENSE.md create mode 100644 gen/drive2-cli/README.md create mode 100644 gen/drive2-cli/mkdocs.yml create mode 100644 gen/drive2-cli/src/cmn.rs create mode 100644 gen/drive2-cli/src/main.rs create mode 100644 gen/games1-cli/Cargo.toml create mode 100644 gen/games1-cli/LICENSE.md create mode 100644 gen/games1-cli/README.md create mode 100644 gen/games1-cli/mkdocs.yml create mode 100644 gen/games1-cli/src/cmn.rs create mode 100644 gen/games1-cli/src/main.rs create mode 100644 gen/identitytoolkit3-cli/Cargo.toml create mode 100644 gen/identitytoolkit3-cli/LICENSE.md create mode 100644 gen/identitytoolkit3-cli/README.md create mode 100644 gen/identitytoolkit3-cli/mkdocs.yml create mode 100644 gen/identitytoolkit3-cli/src/cmn.rs create mode 100644 gen/identitytoolkit3-cli/src/main.rs create mode 100644 gen/logging1_beta3-cli/Cargo.toml create mode 100644 gen/logging1_beta3-cli/LICENSE.md create mode 100644 gen/logging1_beta3-cli/README.md create mode 100644 gen/logging1_beta3-cli/mkdocs.yml create mode 100644 gen/logging1_beta3-cli/src/cmn.rs create mode 100644 gen/logging1_beta3-cli/src/main.rs create mode 100644 gen/reseller1_sandbox-cli/Cargo.toml create mode 100644 gen/reseller1_sandbox-cli/LICENSE.md create mode 100644 gen/reseller1_sandbox-cli/README.md create mode 100644 gen/reseller1_sandbox-cli/mkdocs.yml create mode 100644 gen/reseller1_sandbox-cli/src/cmn.rs create mode 100644 gen/reseller1_sandbox-cli/src/main.rs create mode 100644 gen/tagmanager1-cli/Cargo.toml create mode 100644 gen/tagmanager1-cli/LICENSE.md create mode 100644 gen/tagmanager1-cli/README.md create mode 100644 gen/tagmanager1-cli/mkdocs.yml create mode 100644 gen/tagmanager1-cli/src/cmn.rs create mode 100644 gen/tagmanager1-cli/src/main.rs create mode 100644 gen/taskqueue1_beta2-cli/Cargo.toml create mode 100644 gen/taskqueue1_beta2-cli/LICENSE.md create mode 100644 gen/taskqueue1_beta2-cli/README.md create mode 100644 gen/taskqueue1_beta2-cli/mkdocs.yml create mode 100644 gen/taskqueue1_beta2-cli/src/cmn.rs create mode 100644 gen/taskqueue1_beta2-cli/src/main.rs create mode 100644 gen/webfonts1-cli/Cargo.toml create mode 100644 gen/webfonts1-cli/LICENSE.md create mode 100644 gen/webfonts1-cli/README.md create mode 100644 gen/webfonts1-cli/mkdocs.yml create mode 100644 gen/webfonts1-cli/src/cmn.rs create mode 100644 gen/webfonts1-cli/src/main.rs diff --git a/gen/admin1_directory-cli/Cargo.toml b/gen/admin1_directory-cli/Cargo.toml new file mode 100644 index 0000000000..57cc1748f2 --- /dev/null +++ b/gen/admin1_directory-cli/Cargo.toml @@ -0,0 +1,31 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-admin1_directory-cli" +version = "0.0.1+20150314" +authors = ["Sebastian Thiel "] +description = "A complete library to interact with directory (protocol directory_v1)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/admin1_directory-cli" +homepage = "https://developers.google.com/admin-sdk/directory/" +documentation = "http://byron.github.io/google-apis-rs/google_admin1_directory_cli" +license = "MIT" +keywords = ["admin", "google", "cli"] + +[[bin]] +name = "admin1-directory" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "*" +docopt_macros = "*" +rustc-serialize = "*" +yup-hyper-mock = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-admin1_directory] +path = "../admin1_directory" diff --git a/gen/admin1_directory-cli/LICENSE.md b/gen/admin1_directory-cli/LICENSE.md new file mode 100644 index 0000000000..ae22e6ec52 --- /dev/null +++ b/gen/admin1_directory-cli/LICENSE.md @@ -0,0 +1,30 @@ + +The MIT License (MIT) +===================== + +Copyright © `2015` `Sebastian Thiel` + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the “Software”), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. diff --git a/gen/admin1_directory-cli/README.md b/gen/admin1_directory-cli/README.md new file mode 100644 index 0000000000..ee5759b0f6 --- /dev/null +++ b/gen/admin1_directory-cli/README.md @@ -0,0 +1,4 @@ +# HELLO ADMIN:DIRECTORY_V1 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/admin1_directory-cli/mkdocs.yml b/gen/admin1_directory-cli/mkdocs.yml new file mode 100644 index 0000000000..c4580b01e3 --- /dev/null +++ b/gen/admin1_directory-cli/mkdocs.yml @@ -0,0 +1,83 @@ +site_name: directory v0.0.1+20150314 +site_url: http://byron.github.io/google-apis-rs/google-admin1_directory-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/admin1_directory-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['asps_delete.md', 'Asps', 'Delete'] +- ['asps_get.md', 'Asps', 'Get'] +- ['asps_list.md', 'Asps', 'List'] +- ['channels_stop.md', 'Channels', 'Stop'] +- ['chromeosdevices_get.md', 'Chromeosdevices', 'Get'] +- ['chromeosdevices_list.md', 'Chromeosdevices', 'List'] +- ['chromeosdevices_patch.md', 'Chromeosdevices', 'Patch'] +- ['chromeosdevices_update.md', 'Chromeosdevices', 'Update'] +- ['groups_aliases-delete.md', 'Groups', 'Aliases Delete'] +- ['groups_aliases-insert.md', 'Groups', 'Aliases Insert'] +- ['groups_aliases-list.md', 'Groups', 'Aliases List'] +- ['groups_delete.md', 'Groups', 'Delete'] +- ['groups_get.md', 'Groups', 'Get'] +- ['groups_insert.md', 'Groups', 'Insert'] +- ['groups_list.md', 'Groups', 'List'] +- ['groups_patch.md', 'Groups', 'Patch'] +- ['groups_update.md', 'Groups', 'Update'] +- ['members_delete.md', 'Members', 'Delete'] +- ['members_get.md', 'Members', 'Get'] +- ['members_insert.md', 'Members', 'Insert'] +- ['members_list.md', 'Members', 'List'] +- ['members_patch.md', 'Members', 'Patch'] +- ['members_update.md', 'Members', 'Update'] +- ['mobiledevices_action.md', 'Mobiledevices', 'Action'] +- ['mobiledevices_delete.md', 'Mobiledevices', 'Delete'] +- ['mobiledevices_get.md', 'Mobiledevices', 'Get'] +- ['mobiledevices_list.md', 'Mobiledevices', 'List'] +- ['notifications_delete.md', 'Notifications', 'Delete'] +- ['notifications_get.md', 'Notifications', 'Get'] +- ['notifications_list.md', 'Notifications', 'List'] +- ['notifications_patch.md', 'Notifications', 'Patch'] +- ['notifications_update.md', 'Notifications', 'Update'] +- ['orgunits_delete.md', 'Orgunits', 'Delete'] +- ['orgunits_get.md', 'Orgunits', 'Get'] +- ['orgunits_insert.md', 'Orgunits', 'Insert'] +- ['orgunits_list.md', 'Orgunits', 'List'] +- ['orgunits_patch.md', 'Orgunits', 'Patch'] +- ['orgunits_update.md', 'Orgunits', 'Update'] +- ['schemas_delete.md', 'Schemas', 'Delete'] +- ['schemas_get.md', 'Schemas', 'Get'] +- ['schemas_insert.md', 'Schemas', 'Insert'] +- ['schemas_list.md', 'Schemas', 'List'] +- ['schemas_patch.md', 'Schemas', 'Patch'] +- ['schemas_update.md', 'Schemas', 'Update'] +- ['tokens_delete.md', 'Tokens', 'Delete'] +- ['tokens_get.md', 'Tokens', 'Get'] +- ['tokens_list.md', 'Tokens', 'List'] +- ['users_aliases-delete.md', 'Users', 'Aliases Delete'] +- ['users_aliases-insert.md', 'Users', 'Aliases Insert'] +- ['users_aliases-list.md', 'Users', 'Aliases List'] +- ['users_aliases-watch.md', 'Users', 'Aliases Watch'] +- ['users_delete.md', 'Users', 'Delete'] +- ['users_get.md', 'Users', 'Get'] +- ['users_insert.md', 'Users', 'Insert'] +- ['users_list.md', 'Users', 'List'] +- ['users_make-admin.md', 'Users', 'Make Admin'] +- ['users_patch.md', 'Users', 'Patch'] +- ['users_photos-delete.md', 'Users', 'Photos Delete'] +- ['users_photos-get.md', 'Users', 'Photos Get'] +- ['users_photos-patch.md', 'Users', 'Photos Patch'] +- ['users_photos-update.md', 'Users', 'Photos Update'] +- ['users_undelete.md', 'Users', 'Undelete'] +- ['users_update.md', 'Users', 'Update'] +- ['users_watch.md', 'Users', 'Watch'] +- ['verification-codes_generate.md', 'Verification Codes', 'Generate'] +- ['verification-codes_invalidate.md', 'Verification Codes', 'Invalidate'] +- ['verification-codes_list.md', 'Verification Codes', 'List'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/admin1_directory-cli/src/cmn.rs b/gen/admin1_directory-cli/src/cmn.rs new file mode 100644 index 0000000000..a8d3f46368 --- /dev/null +++ b/gen/admin1_directory-cli/src/cmn.rs @@ -0,0 +1,454 @@ +// COPY OF 'src/rust/cli/cmn.rs' +// DO NOT EDIT +use oauth2::{ApplicationSecret, ConsoleApplicationSecret, TokenStorage, Token}; +use rustc_serialize::json; +use mime::Mime; + +use std::fs; +use std::env; +use std::io; +use std::fmt; +use std::path::{Path, PathBuf}; +use std::str::FromStr; +use std::string::ToString; +use std::io::{Write, Read, stdout}; + +use std::default::Default; + +const FIELD_SEP: char = '.'; + +#[derive(Clone, Default)] +pub struct FieldCursor(Vec); + +impl ToString for FieldCursor { + fn to_string(&self) -> String { + self.0.connect(".") + } +} + +impl FieldCursor { + pub fn set(&mut self, value: &str) -> Result<(), CLIError> { + if value.len() == 0 { + return Err(CLIError::Field(FieldError::Empty)) + } + + let mut first_is_field_sep = false; + let mut char_count: usize = 0; + let mut last_c = FIELD_SEP; + let mut num_conscutive_field_seps = 0; + + let mut field = String::new(); + let mut fields = self.0.clone(); + + let push_field = |fs: &mut Vec, f: &mut String| { + if f.len() > 0 { + fs.push(f.clone()); + f.truncate(0); + } + }; + + for (cid, c) in value.chars().enumerate() { + char_count += 1; + + if c == FIELD_SEP { + if cid == 0 { + first_is_field_sep = true; + } + num_conscutive_field_seps += 1; + if cid > 0 && last_c == FIELD_SEP { + if fields.pop().is_none() { + return Err(CLIError::Field(FieldError::PopOnEmpty(value.to_string()))) + } + } else { + push_field(&mut fields, &mut field); + } + } else { + num_conscutive_field_seps = 0; + if cid == 1 { + if first_is_field_sep { + fields.truncate(0); + } + } + field.push(c); + } + + last_c = c; + } + + push_field(&mut fields, &mut field); + + if char_count == 1 && first_is_field_sep { + fields.truncate(0); + } + if char_count > 1 && num_conscutive_field_seps == 1 { + return Err(CLIError::Field(FieldError::TrailingFieldSep(value.to_string()))) + } + + self.0 = fields; + Ok(()) + } + + pub fn num_fields(&self) -> usize { + self.0.len() + } +} + +pub fn parse_kv_arg<'a>(kv: &'a str, err: &mut InvalidOptionsError, for_hashmap: bool) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string(),for_hashmap)); + match kv.find('=') { + None => { + add_err(); + return (kv, None) + }, + Some(pos) => { + let key = &kv[..pos]; + if kv.len() <= pos + 1 { + add_err(); + return (key, None) + } + (key, Some(&kv[pos+1..])) + } + } +} + +pub fn input_file_from_opts(file_path: &str, err: &mut InvalidOptionsError) -> Option { + match fs::File::open(file_path) { + Ok(f) => Some(f), + Err(io_err) => { + err.issues.push(CLIError::Input(InputError::IOError((file_path.to_string(), io_err)))); + None + } + } +} + +pub fn input_mime_from_opts(mime: &str, err: &mut InvalidOptionsError) -> Option { + match mime.parse() { + Ok(m) => Some(m), + Err(_) => { + err.issues.push(CLIError::Input(InputError::Mime(mime.to_string()))); + None + } + } +} + +// May panic if we can't open the file - this is anticipated, we can't currently communicate this +// kind of error: TODO: fix this architecture :) +pub fn writer_from_opts(flag: bool, arg: &str) -> Box { + if !flag || arg == "-" { + Box::new(stdout()) + } else { + Box::new(fs::OpenOptions::new().create(true).write(true).open(arg).unwrap()) + } +} + + +pub fn arg_from_str(arg: &str, err: &mut InvalidOptionsError, + arg_name: &'static str, + arg_type: &'static str) -> T + where T: FromStr + Default, + ::Err: fmt::Display { + match FromStr::from_str(arg) { + Err(perr) => { + err.issues.push( + CLIError::ParseError((arg_name, arg_type, arg.to_string(), format!("{}", perr))) + ); + Default::default() + }, + Ok(v) => v, + } +} + +pub struct JsonTokenStorage { + pub program_name: &'static str, + pub db_dir: String, +} + +impl JsonTokenStorage { + fn path(&self, scope_hash: u64) -> PathBuf { + Path::new(&self.db_dir).join(&format!("{}-token-{}.json", self.program_name, scope_hash)) + } +} + +impl TokenStorage for JsonTokenStorage { + type Error = io::Error; + + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, _: &Vec<&str>, token: Option) -> Option { + match token { + None => { + match fs::remove_file(self.path(scope_hash)) { + Err(err) => + match err.kind() { + io::ErrorKind::NotFound => None, + _ => Some(err) + }, + Ok(_) => None + } + } + Some(token) => { + let json_token = json::encode(&token).unwrap(); + match fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)) { + Ok(mut f) => { + match f.write(json_token.as_bytes()) { + Ok(_) => None, + Err(io_err) => Some(io_err), + } + }, + Err(io_err) => Some(io_err) + } + } + } + } + + fn get(&self, scope_hash: u64, _: &Vec<&str>) -> Result, io::Error> { + match fs::File::open(&self.path(scope_hash)) { + Ok(mut f) => { + let mut json_string = String::new(); + match f.read_to_string(&mut json_string) { + Ok(_) => Ok(Some(json::decode::(&json_string).unwrap())), + Err(io_err) => Err(io_err), + } + }, + Err(io_err) => { + match io_err.kind() { + io::ErrorKind::NotFound => Ok(None), + _ => Err(io_err) + } + } + } + } +} + + +#[derive(Debug)] +pub enum ApplicationSecretError { + DecoderError((String, json::DecoderError)), + FormatError(String), +} + +impl fmt::Display for ApplicationSecretError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + match *self { + ApplicationSecretError::DecoderError((ref path, ref err)) + => writeln!(f, "Could not decode file at '{}' with error: {}", + path, err), + ApplicationSecretError::FormatError(ref path) + => writeln!(f, "'installed' field is unset in secret file at '{}'", + path), + } + } +} + +#[derive(Debug)] +pub enum ConfigurationError { + DirectoryCreationFailed((String, io::Error)), + DirectoryUnset, + HomeExpansionFailed(String), + Secret(ApplicationSecretError), + IOError((String, io::Error)), +} + +impl fmt::Display for ConfigurationError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + match *self { + ConfigurationError::DirectoryCreationFailed((ref dir, ref err)) + => writeln!(f, "Directory '{}' could not be created with error: {}", dir, err), + ConfigurationError::DirectoryUnset + => writeln!(f, "--config-dir was unset or empty"), + ConfigurationError::HomeExpansionFailed(ref dir) + => writeln!(f, "Couldn't find HOME directory of current user, failed to expand '{}'", dir), + ConfigurationError::Secret(ref err) + => writeln!(f, "Secret -> {}", err), + ConfigurationError::IOError((ref path, ref err)) + => writeln!(f, "IO operation failed on path '{}' with error: {}", path, err), + } + } +} + +#[derive(Debug)] +pub enum InputError { + IOError((String, io::Error)), + Mime(String), +} + +impl fmt::Display for InputError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + match *self { + InputError::IOError((ref file_path, ref io_err)) + => writeln!(f, "Failed to open '{}' for reading with error: {}", file_path, io_err), + InputError::Mime(ref mime) + => writeln!(f, "'{}' is not a known mime-type", mime), + } + } +} + +#[derive(Debug)] +pub enum FieldError { + PopOnEmpty(String), + TrailingFieldSep(String), + Unknown(String), + Empty, +} + + +impl fmt::Display for FieldError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + match *self { + FieldError::PopOnEmpty(ref field) + => writeln!(f, "'{}': Cannot move up on empty field cursor", field), + FieldError::TrailingFieldSep(ref field) + => writeln!(f, "'{}': Single field separator may not be last character", field), + FieldError::Unknown(ref field) + => writeln!(f, "Field '{}' does not exist", field), + FieldError::Empty + => writeln!(f, "Field names must not be empty"), + } + } +} + + +#[derive(Debug)] +pub enum CLIError { + Configuration(ConfigurationError), + ParseError((&'static str, &'static str, String, String)), + UnknownParameter(String), + InvalidKeyValueSyntax(String, bool), + Input(InputError), + Field(FieldError), +} + +impl fmt::Display for CLIError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + match *self { + CLIError::Configuration(ref err) => write!(f, "Configuration -> {}", err), + CLIError::Input(ref err) => write!(f, "Input -> {}", err), + CLIError::Field(ref err) => write!(f, "Field -> {}", err), + CLIError::ParseError((arg_name, 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) + => writeln!(f, "Parameter '{}' is unknown.", param_name), + CLIError::InvalidKeyValueSyntax(ref kv, is_hashmap) => { + let hashmap_info = if is_hashmap { "hashmap " } else { "" }; + writeln!(f, "'{}' does not match {}pattern =", kv, hashmap_info) + }, + } + } +} + +#[derive(Debug)] +pub struct InvalidOptionsError { + pub issues: Vec, + pub exit_code: i32, +} + +impl fmt::Display for InvalidOptionsError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + for issue in &self.issues { + try!(issue.fmt(f)); + } + Ok(()) + } +} + +impl InvalidOptionsError { + pub fn single(err: CLIError, exit_code: i32) -> InvalidOptionsError { + InvalidOptionsError { + issues: vec![err], + exit_code: exit_code, + } + } + + pub fn new() -> InvalidOptionsError { + InvalidOptionsError { + issues: Vec::new(), + exit_code: 1, + } + } +} + +pub fn assure_config_dir_exists(dir: &str) -> Result { + let trdir = dir.trim(); + if trdir.len() == 0 { + return Err(CLIError::Configuration(ConfigurationError::DirectoryUnset)) + } + + let expanded_config_dir = + if trdir.as_bytes()[0] == b'~' { + match env::var("HOME").ok().or(env::var("UserProfile").ok()) { + None => return Err(CLIError::Configuration(ConfigurationError::HomeExpansionFailed(trdir.to_string()))), + Some(mut user) => { + user.push_str(&trdir[1..]); + user + } + } + } else { + trdir.to_string() + }; + + if let Err(err) = fs::create_dir(&expanded_config_dir) { + if err.kind() != io::ErrorKind::AlreadyExists { + return Err(CLIError::Configuration( + ConfigurationError::DirectoryCreationFailed((expanded_config_dir, err)))) + } + } + + Ok(expanded_config_dir) +} + +pub fn application_secret_from_directory(dir: &str, + secret_basename: &str, + json_app_secret: &str) + -> Result { + let secret_path = Path::new(dir).join(secret_basename); + let secret_str = || secret_path.as_path().to_str().unwrap().to_string(); + let secret_io_error = |io_err: io::Error| { + Err(CLIError::Configuration(ConfigurationError::IOError( + (secret_str(), io_err) + ))) + }; + + for _ in 0..2 { + match fs::File::open(&secret_path) { + Err(mut err) => { + if err.kind() == io::ErrorKind::NotFound { + // Write our built-in one - user may adjust the written file at will + + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_app_secret.as_bytes()) { + Err(io_err) => io_err, + Ok(_) => continue, + } + } + }; + // fall through to IO error handling + } + return secret_io_error(err) + }, + Ok(mut f) => { + let mut json_encoded_secret = String::new(); + if let Err(io_err) = f.read_to_string(&mut json_encoded_secret) { + return secret_io_error(io_err) + } + match json::decode::(&json_encoded_secret) { + Err(json_decode_error) => return Err(CLIError::Configuration( + ConfigurationError::Secret(ApplicationSecretError::DecoderError( + (secret_str(), json_decode_error) + )))), + Ok(console_secret) => match console_secret.installed { + Some(secret) => return Ok(secret), + None => return Err( + CLIError::Configuration( + ConfigurationError::Secret( + ApplicationSecretError::FormatError(secret_str()) + ))) + }, + } + } + } + } + unreachable!(); +} \ No newline at end of file diff --git a/gen/admin1_directory-cli/src/main.rs b/gen/admin1_directory-cli/src/main.rs new file mode 100644 index 0000000000..3e68426ece --- /dev/null +++ b/gen/admin1_directory-cli/src/main.rs @@ -0,0 +1,4775 @@ +// DO NOT EDIT ! +// This file was generated automatically from 'src/mako/cli/main.rs.mako' +// DO NOT EDIT ! +#![feature(plugin, exit_status)] +#![plugin(docopt_macros)] +#![allow(unused_variables, unused_imports, dead_code, unused_mut)] + +extern crate docopt; +extern crate yup_oauth2 as oauth2; +extern crate yup_hyper_mock as mock; +extern crate rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_admin1_directory as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + admin1-directory [options] asps delete [-p ]... + admin1-directory [options] asps get [-p ]... [-o ] + admin1-directory [options] asps list [-p ]... [-o ] + admin1-directory [options] channels stop -r ... [-p ]... + admin1-directory [options] chromeosdevices get [-p ]... [-o ] + admin1-directory [options] chromeosdevices list [-p ]... [-o ] + admin1-directory [options] chromeosdevices patch -r ... [-p ]... [-o ] + admin1-directory [options] chromeosdevices update -r ... [-p ]... [-o ] + admin1-directory [options] groups aliases-delete [-p ]... + admin1-directory [options] groups aliases-insert -r ... [-p ]... [-o ] + admin1-directory [options] groups aliases-list [-p ]... [-o ] + admin1-directory [options] groups delete [-p ]... + admin1-directory [options] groups get [-p ]... [-o ] + admin1-directory [options] groups insert -r ... [-p ]... [-o ] + admin1-directory [options] groups list [-p ]... [-o ] + admin1-directory [options] groups patch -r ... [-p ]... [-o ] + admin1-directory [options] groups update -r ... [-p ]... [-o ] + admin1-directory [options] members delete [-p ]... + admin1-directory [options] members get [-p ]... [-o ] + admin1-directory [options] members insert -r ... [-p ]... [-o ] + admin1-directory [options] members list [-p ]... [-o ] + admin1-directory [options] members patch -r ... [-p ]... [-o ] + admin1-directory [options] members update -r ... [-p ]... [-o ] + admin1-directory [options] mobiledevices action -r ... [-p ]... + admin1-directory [options] mobiledevices delete [-p ]... + admin1-directory [options] mobiledevices get [-p ]... [-o ] + admin1-directory [options] mobiledevices list [-p ]... [-o ] + admin1-directory [options] notifications delete [-p ]... + admin1-directory [options] notifications get [-p ]... [-o ] + admin1-directory [options] notifications list [-p ]... [-o ] + admin1-directory [options] notifications patch -r ... [-p ]... [-o ] + admin1-directory [options] notifications update -r ... [-p ]... [-o ] + admin1-directory [options] orgunits delete ... [-p ]... + admin1-directory [options] orgunits get ... [-p ]... [-o ] + admin1-directory [options] orgunits insert -r ... [-p ]... [-o ] + admin1-directory [options] orgunits list [-p ]... [-o ] + admin1-directory [options] orgunits patch ... -r ... [-p ]... [-o ] + admin1-directory [options] orgunits update ... -r ... [-p ]... [-o ] + admin1-directory [options] schemas delete [-p ]... + admin1-directory [options] schemas get [-p ]... [-o ] + admin1-directory [options] schemas insert -r ... [-p ]... [-o ] + admin1-directory [options] schemas list [-p ]... [-o ] + admin1-directory [options] schemas patch -r ... [-p ]... [-o ] + admin1-directory [options] schemas update -r ... [-p ]... [-o ] + admin1-directory [options] tokens delete [-p ]... + admin1-directory [options] tokens get [-p ]... [-o ] + admin1-directory [options] tokens list [-p ]... [-o ] + admin1-directory [options] users aliases-delete [-p ]... + admin1-directory [options] users aliases-insert -r ... [-p ]... [-o ] + admin1-directory [options] users aliases-list [-p ]... [-o ] + admin1-directory [options] users aliases-watch -r ... [-p ]... [-o ] + admin1-directory [options] users delete [-p ]... + admin1-directory [options] users get [-p ]... [-o ] + admin1-directory [options] users insert -r ... [-p ]... [-o ] + admin1-directory [options] users list [-p ]... [-o ] + admin1-directory [options] users make-admin -r ... [-p ]... + admin1-directory [options] users patch -r ... [-p ]... [-o ] + admin1-directory [options] users photos-delete [-p ]... + admin1-directory [options] users photos-get [-p ]... [-o ] + admin1-directory [options] users photos-patch -r ... [-p ]... [-o ] + admin1-directory [options] users photos-update -r ... [-p ]... [-o ] + admin1-directory [options] users undelete -r ... [-p ]... + admin1-directory [options] users update -r ... [-p ]... [-o ] + admin1-directory [options] users watch -r ... [-p ]... [-o ] + admin1-directory [options] verification-codes generate [-p ]... + admin1-directory [options] verification-codes invalidate [-p ]... + admin1-directory [options] verification-codes list [-p ]... [-o ] + admin1-directory --help + +All documentation details can be found TODO: + +Configuration: + --scope + 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. + --config-dir + 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] + --debug + Output all server communication to standard error. `tx` and `rx` are placed into + the same stream. + --debug-auth + Output all communication related to authentication to standard error. `tx` and `rx` are placed into + the same stream. +"); + +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}; + +use std::default::Default; +use std::str::FromStr; + +use oauth2::{Authenticator, DefaultAuthenticatorDelegate}; +use rustc_serialize::json; + +struct Engine { + opt: Options, + hub: api::Directory>, +} + + +impl Engine { + fn _asps_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let code_id: i32 = arg_from_str(&self.opt.arg_code_id, err, "", "integer"); + let mut call = self.hub.asps().delete(&self.opt.arg_user_key, code_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + None + } + } + } + } + + fn _asps_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let code_id: i32 = arg_from_str(&self.opt.arg_code_id, err, "", "integer"); + let mut call = self.hub.asps().get(&self.opt.arg_user_key, code_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _asps_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.asps().list(&self.opt.arg_user_key); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _channels_stop(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request = api::Channel::default(); + let mut call = self.hub.channels().stop(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "resource-uri" => { + request.resource_uri = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "resource-id" => { + request.resource_id = Some(value.unwrap_or("").to_string()); + }, + "payload" => { + request.payload = Some(arg_from_str(value.unwrap_or("false"), err, "payload", "boolean")); + }, + "token" => { + request.token = Some(value.unwrap_or("").to_string()); + }, + "params" => { + if request.params.is_none() { + request.params = Some(Default::default()); + } + let (key, value) = parse_kv_arg(value.unwrap_or(""), err, true); + request.params.as_mut().unwrap().insert(key.to_string(), value.unwrap_or("").to_string()); + }, + "expiration" => { + request.expiration = Some(value.unwrap_or("").to_string()); + }, + "address" => { + request.address = Some(value.unwrap_or("").to_string()); + }, + "type" => { + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + None + } + } + } + } + + fn _chromeosdevices_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.chromeosdevices().get(&self.opt.arg_customer_id, &self.opt.arg_device_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "projection" => { + call = call.projection(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _chromeosdevices_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.chromeosdevices().list(&self.opt.arg_customer_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "sort-order" => { + call = call.sort_order(value.unwrap_or("")); + }, + "query" => { + call = call.query(value.unwrap_or("")); + }, + "projection" => { + call = call.projection(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "order-by" => { + call = call.order_by(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _chromeosdevices_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request = api::ChromeOsDevice::default(); + let mut call = self.hub.chromeosdevices().patch(&request, &self.opt.arg_customer_id, &self.opt.arg_device_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "projection" => { + call = call.projection(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "mac-address" => { + request.mac_address = Some(value.unwrap_or("").to_string()); + }, + "last-sync" => { + request.last_sync = Some(value.unwrap_or("").to_string()); + }, + "order-number" => { + request.order_number = Some(value.unwrap_or("").to_string()); + }, + "annotated-user" => { + request.annotated_user = Some(value.unwrap_or("").to_string()); + }, + "annotated-asset-id" => { + request.annotated_asset_id = Some(value.unwrap_or("").to_string()); + }, + "firmware-version" => { + request.firmware_version = Some(value.unwrap_or("").to_string()); + }, + "boot-mode" => { + request.boot_mode = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "org-unit-path" => { + request.org_unit_path = Some(value.unwrap_or("").to_string()); + }, + "status" => { + request.status = Some(value.unwrap_or("").to_string()); + }, + "will-auto-renew" => { + request.will_auto_renew = Some(arg_from_str(value.unwrap_or("false"), err, "will-auto-renew", "boolean")); + }, + "ethernet-mac-address" => { + request.ethernet_mac_address = Some(value.unwrap_or("").to_string()); + }, + "meid" => { + request.meid = Some(value.unwrap_or("").to_string()); + }, + "annotated-location" => { + request.annotated_location = Some(value.unwrap_or("").to_string()); + }, + "device-id" => { + request.device_id = Some(value.unwrap_or("").to_string()); + }, + "platform-version" => { + request.platform_version = Some(value.unwrap_or("").to_string()); + }, + "os-version" => { + request.os_version = Some(value.unwrap_or("").to_string()); + }, + "last-enrollment-time" => { + request.last_enrollment_time = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "notes" => { + request.notes = Some(value.unwrap_or("").to_string()); + }, + "serial-number" => { + request.serial_number = Some(value.unwrap_or("").to_string()); + }, + "support-end-date" => { + request.support_end_date = Some(value.unwrap_or("").to_string()); + }, + "model" => { + request.model = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _chromeosdevices_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request = api::ChromeOsDevice::default(); + let mut call = self.hub.chromeosdevices().update(&request, &self.opt.arg_customer_id, &self.opt.arg_device_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "projection" => { + call = call.projection(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "mac-address" => { + request.mac_address = Some(value.unwrap_or("").to_string()); + }, + "last-sync" => { + request.last_sync = Some(value.unwrap_or("").to_string()); + }, + "order-number" => { + request.order_number = Some(value.unwrap_or("").to_string()); + }, + "annotated-user" => { + request.annotated_user = Some(value.unwrap_or("").to_string()); + }, + "annotated-asset-id" => { + request.annotated_asset_id = Some(value.unwrap_or("").to_string()); + }, + "firmware-version" => { + request.firmware_version = Some(value.unwrap_or("").to_string()); + }, + "boot-mode" => { + request.boot_mode = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "org-unit-path" => { + request.org_unit_path = Some(value.unwrap_or("").to_string()); + }, + "status" => { + request.status = Some(value.unwrap_or("").to_string()); + }, + "will-auto-renew" => { + request.will_auto_renew = Some(arg_from_str(value.unwrap_or("false"), err, "will-auto-renew", "boolean")); + }, + "ethernet-mac-address" => { + request.ethernet_mac_address = Some(value.unwrap_or("").to_string()); + }, + "meid" => { + request.meid = Some(value.unwrap_or("").to_string()); + }, + "annotated-location" => { + request.annotated_location = Some(value.unwrap_or("").to_string()); + }, + "device-id" => { + request.device_id = Some(value.unwrap_or("").to_string()); + }, + "platform-version" => { + request.platform_version = Some(value.unwrap_or("").to_string()); + }, + "os-version" => { + request.os_version = Some(value.unwrap_or("").to_string()); + }, + "last-enrollment-time" => { + request.last_enrollment_time = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "notes" => { + request.notes = Some(value.unwrap_or("").to_string()); + }, + "serial-number" => { + request.serial_number = Some(value.unwrap_or("").to_string()); + }, + "support-end-date" => { + request.support_end_date = Some(value.unwrap_or("").to_string()); + }, + "model" => { + request.model = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _groups_aliases_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.groups().aliases_delete(&self.opt.arg_group_key, &self.opt.arg_alias); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + None + } + } + } + } + + fn _groups_aliases_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request = api::Alias::default(); + let mut call = self.hub.groups().aliases_insert(&request, &self.opt.arg_group_key); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "alias" => { + request.alias = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "primary-email" => { + request.primary_email = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _groups_aliases_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.groups().aliases_list(&self.opt.arg_group_key); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _groups_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.groups().delete(&self.opt.arg_group_key); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + None + } + } + } + } + + fn _groups_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.groups().get(&self.opt.arg_group_key); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _groups_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request = api::Group::default(); + let mut call = self.hub.groups().insert(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "non-editable-aliases" => { + if request.non_editable_aliases.is_none() { + request.non_editable_aliases = Some(Default::default()); + } + request.non_editable_aliases.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "admin-created" => { + request.admin_created = Some(arg_from_str(value.unwrap_or("false"), err, "admin-created", "boolean")); + }, + "direct-members-count" => { + request.direct_members_count = Some(arg_from_str(value.unwrap_or("-0"), err, "direct-members-count", "int64")); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "email" => { + request.email = Some(value.unwrap_or("").to_string()); + }, + "aliases" => { + if request.aliases.is_none() { + request.aliases = Some(Default::default()); + } + request.aliases.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _groups_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.groups().list(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "user-key" => { + call = call.user_key(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "domain" => { + call = call.domain(value.unwrap_or("")); + }, + "customer" => { + call = call.customer(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _groups_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request = api::Group::default(); + let mut call = self.hub.groups().patch(&request, &self.opt.arg_group_key); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "non-editable-aliases" => { + if request.non_editable_aliases.is_none() { + request.non_editable_aliases = Some(Default::default()); + } + request.non_editable_aliases.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "admin-created" => { + request.admin_created = Some(arg_from_str(value.unwrap_or("false"), err, "admin-created", "boolean")); + }, + "direct-members-count" => { + request.direct_members_count = Some(arg_from_str(value.unwrap_or("-0"), err, "direct-members-count", "int64")); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "email" => { + request.email = Some(value.unwrap_or("").to_string()); + }, + "aliases" => { + if request.aliases.is_none() { + request.aliases = Some(Default::default()); + } + request.aliases.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _groups_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request = api::Group::default(); + let mut call = self.hub.groups().update(&request, &self.opt.arg_group_key); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "non-editable-aliases" => { + if request.non_editable_aliases.is_none() { + request.non_editable_aliases = Some(Default::default()); + } + request.non_editable_aliases.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "admin-created" => { + request.admin_created = Some(arg_from_str(value.unwrap_or("false"), err, "admin-created", "boolean")); + }, + "direct-members-count" => { + request.direct_members_count = Some(arg_from_str(value.unwrap_or("-0"), err, "direct-members-count", "int64")); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "email" => { + request.email = Some(value.unwrap_or("").to_string()); + }, + "aliases" => { + if request.aliases.is_none() { + request.aliases = Some(Default::default()); + } + request.aliases.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _members_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.members().delete(&self.opt.arg_group_key, &self.opt.arg_member_key); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + None + } + } + } + } + + fn _members_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.members().get(&self.opt.arg_group_key, &self.opt.arg_member_key); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _members_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request = api::Member::default(); + let mut call = self.hub.members().insert(&request, &self.opt.arg_group_key); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "role" => { + request.role = Some(value.unwrap_or("").to_string()); + }, + "type" => { + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "email" => { + request.email = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _members_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.members().list(&self.opt.arg_group_key); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "roles" => { + call = call.roles(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _members_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request = api::Member::default(); + let mut call = self.hub.members().patch(&request, &self.opt.arg_group_key, &self.opt.arg_member_key); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "role" => { + request.role = Some(value.unwrap_or("").to_string()); + }, + "type" => { + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "email" => { + request.email = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _members_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request = api::Member::default(); + let mut call = self.hub.members().update(&request, &self.opt.arg_group_key, &self.opt.arg_member_key); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "role" => { + request.role = Some(value.unwrap_or("").to_string()); + }, + "type" => { + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "email" => { + request.email = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _mobiledevices_action(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request = api::MobileDeviceAction::default(); + let mut call = self.hub.mobiledevices().action(&request, &self.opt.arg_customer_id, &self.opt.arg_resource_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "action" => { + request.action = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + None + } + } + } + } + + fn _mobiledevices_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.mobiledevices().delete(&self.opt.arg_customer_id, &self.opt.arg_resource_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + None + } + } + } + } + + fn _mobiledevices_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.mobiledevices().get(&self.opt.arg_customer_id, &self.opt.arg_resource_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "projection" => { + call = call.projection(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _mobiledevices_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.mobiledevices().list(&self.opt.arg_customer_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "sort-order" => { + call = call.sort_order(value.unwrap_or("")); + }, + "query" => { + call = call.query(value.unwrap_or("")); + }, + "projection" => { + call = call.projection(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "order-by" => { + call = call.order_by(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _notifications_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.notifications().delete(&self.opt.arg_customer, &self.opt.arg_notification_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + None + } + } + } + } + + fn _notifications_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.notifications().get(&self.opt.arg_customer, &self.opt.arg_notification_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _notifications_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.notifications().list(&self.opt.arg_customer); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "language" => { + call = call.language(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _notifications_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request = api::Notification::default(); + let mut call = self.hub.notifications().patch(&request, &self.opt.arg_customer, &self.opt.arg_notification_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "body" => { + request.body = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "send-time" => { + request.send_time = Some(value.unwrap_or("").to_string()); + }, + "notification-id" => { + request.notification_id = Some(value.unwrap_or("").to_string()); + }, + "from-address" => { + request.from_address = Some(value.unwrap_or("").to_string()); + }, + "is-unread" => { + request.is_unread = Some(arg_from_str(value.unwrap_or("false"), err, "is-unread", "boolean")); + }, + "subject" => { + request.subject = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _notifications_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request = api::Notification::default(); + let mut call = self.hub.notifications().update(&request, &self.opt.arg_customer, &self.opt.arg_notification_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "body" => { + request.body = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "send-time" => { + request.send_time = Some(value.unwrap_or("").to_string()); + }, + "notification-id" => { + request.notification_id = Some(value.unwrap_or("").to_string()); + }, + "from-address" => { + request.from_address = Some(value.unwrap_or("").to_string()); + }, + "is-unread" => { + request.is_unread = Some(arg_from_str(value.unwrap_or("false"), err, "is-unread", "boolean")); + }, + "subject" => { + request.subject = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _orgunits_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.orgunits().delete(&self.opt.arg_customer_id, &self.opt.arg_org_unit_path); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + None + } + } + } + } + + fn _orgunits_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.orgunits().get(&self.opt.arg_customer_id, &self.opt.arg_org_unit_path); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _orgunits_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request = api::OrgUnit::default(); + let mut call = self.hub.orgunits().insert(&request, &self.opt.arg_customer_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "parent-org-unit-path" => { + request.parent_org_unit_path = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "org-unit-path" => { + request.org_unit_path = Some(value.unwrap_or("").to_string()); + }, + "parent-org-unit-id" => { + request.parent_org_unit_id = Some(value.unwrap_or("").to_string()); + }, + "block-inheritance" => { + request.block_inheritance = Some(arg_from_str(value.unwrap_or("false"), err, "block-inheritance", "boolean")); + }, + "org-unit-id" => { + request.org_unit_id = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _orgunits_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.orgunits().list(&self.opt.arg_customer_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "type" => { + call = call.type_(value.unwrap_or("")); + }, + "org-unit-path" => { + call = call.org_unit_path(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _orgunits_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request = api::OrgUnit::default(); + let mut call = self.hub.orgunits().patch(&request, &self.opt.arg_customer_id, &self.opt.arg_org_unit_path); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "parent-org-unit-path" => { + request.parent_org_unit_path = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "org-unit-path" => { + request.org_unit_path = Some(value.unwrap_or("").to_string()); + }, + "parent-org-unit-id" => { + request.parent_org_unit_id = Some(value.unwrap_or("").to_string()); + }, + "block-inheritance" => { + request.block_inheritance = Some(arg_from_str(value.unwrap_or("false"), err, "block-inheritance", "boolean")); + }, + "org-unit-id" => { + request.org_unit_id = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _orgunits_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request = api::OrgUnit::default(); + let mut call = self.hub.orgunits().update(&request, &self.opt.arg_customer_id, &self.opt.arg_org_unit_path); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "parent-org-unit-path" => { + request.parent_org_unit_path = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "org-unit-path" => { + request.org_unit_path = Some(value.unwrap_or("").to_string()); + }, + "parent-org-unit-id" => { + request.parent_org_unit_id = Some(value.unwrap_or("").to_string()); + }, + "block-inheritance" => { + request.block_inheritance = Some(arg_from_str(value.unwrap_or("false"), err, "block-inheritance", "boolean")); + }, + "org-unit-id" => { + request.org_unit_id = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _schemas_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.schemas().delete(&self.opt.arg_customer_id, &self.opt.arg_schema_key); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + None + } + } + } + } + + fn _schemas_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.schemas().get(&self.opt.arg_customer_id, &self.opt.arg_schema_key); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _schemas_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request = api::Schema::default(); + let mut call = self.hub.schemas().insert(&request, &self.opt.arg_customer_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "schema-id" => { + request.schema_id = Some(value.unwrap_or("").to_string()); + }, + "schema-name" => { + request.schema_name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _schemas_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.schemas().list(&self.opt.arg_customer_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _schemas_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request = api::Schema::default(); + let mut call = self.hub.schemas().patch(&request, &self.opt.arg_customer_id, &self.opt.arg_schema_key); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "schema-id" => { + request.schema_id = Some(value.unwrap_or("").to_string()); + }, + "schema-name" => { + request.schema_name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _schemas_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request = api::Schema::default(); + let mut call = self.hub.schemas().update(&request, &self.opt.arg_customer_id, &self.opt.arg_schema_key); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "schema-id" => { + request.schema_id = Some(value.unwrap_or("").to_string()); + }, + "schema-name" => { + request.schema_name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _tokens_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.tokens().delete(&self.opt.arg_user_key, &self.opt.arg_client_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + None + } + } + } + } + + fn _tokens_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.tokens().get(&self.opt.arg_user_key, &self.opt.arg_client_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _tokens_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.tokens().list(&self.opt.arg_user_key); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _users_aliases_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.users().aliases_delete(&self.opt.arg_user_key, &self.opt.arg_alias); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + None + } + } + } + } + + fn _users_aliases_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request = api::Alias::default(); + let mut call = self.hub.users().aliases_insert(&request, &self.opt.arg_user_key); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "alias" => { + request.alias = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "primary-email" => { + request.primary_email = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _users_aliases_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.users().aliases_list(&self.opt.arg_user_key); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "event" => { + call = call.event(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _users_aliases_watch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request = api::Channel::default(); + let mut call = self.hub.users().aliases_watch(&request, &self.opt.arg_user_key); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "event" => { + call = call.event(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "resource-uri" => { + request.resource_uri = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "resource-id" => { + request.resource_id = Some(value.unwrap_or("").to_string()); + }, + "payload" => { + request.payload = Some(arg_from_str(value.unwrap_or("false"), err, "payload", "boolean")); + }, + "token" => { + request.token = Some(value.unwrap_or("").to_string()); + }, + "params" => { + if request.params.is_none() { + request.params = Some(Default::default()); + } + let (key, value) = parse_kv_arg(value.unwrap_or(""), err, true); + request.params.as_mut().unwrap().insert(key.to_string(), value.unwrap_or("").to_string()); + }, + "expiration" => { + request.expiration = Some(value.unwrap_or("").to_string()); + }, + "address" => { + request.address = Some(value.unwrap_or("").to_string()); + }, + "type" => { + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _users_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.users().delete(&self.opt.arg_user_key); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + None + } + } + } + } + + fn _users_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.users().get(&self.opt.arg_user_key); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "view-type" => { + call = call.view_type(value.unwrap_or("")); + }, + "projection" => { + call = call.projection(value.unwrap_or("")); + }, + "custom-field-mask" => { + call = call.custom_field_mask(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _users_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request = api::User::default(); + let mut call = self.hub.users().insert(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_name_init(request: &mut api::User) { + if request.name.is_none() { + request.name = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "is-delegated-admin" => { + request.is_delegated_admin = Some(arg_from_str(value.unwrap_or("false"), err, "is-delegated-admin", "boolean")); + }, + "suspended" => { + request.suspended = Some(arg_from_str(value.unwrap_or("false"), err, "suspended", "boolean")); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "aliases" => { + if request.aliases.is_none() { + request.aliases = Some(Default::default()); + } + request.aliases.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "non-editable-aliases" => { + if request.non_editable_aliases.is_none() { + request.non_editable_aliases = Some(Default::default()); + } + request.non_editable_aliases.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "deletion-time" => { + request.deletion_time = Some(value.unwrap_or("").to_string()); + }, + "suspension-reason" => { + request.suspension_reason = Some(value.unwrap_or("").to_string()); + }, + "thumbnail-photo-url" => { + request.thumbnail_photo_url = Some(value.unwrap_or("").to_string()); + }, + "is-admin" => { + request.is_admin = Some(arg_from_str(value.unwrap_or("false"), err, "is-admin", "boolean")); + }, + "include-in-global-address-list" => { + request.include_in_global_address_list = Some(arg_from_str(value.unwrap_or("false"), err, "include-in-global-address-list", "boolean")); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "last-login-time" => { + request.last_login_time = Some(value.unwrap_or("").to_string()); + }, + "org-unit-path" => { + request.org_unit_path = Some(value.unwrap_or("").to_string()); + }, + "agreed-to-terms" => { + request.agreed_to_terms = Some(arg_from_str(value.unwrap_or("false"), err, "agreed-to-terms", "boolean")); + }, + "ip-whitelisted" => { + request.ip_whitelisted = Some(arg_from_str(value.unwrap_or("false"), err, "ip-whitelisted", "boolean")); + }, + "primary-email" => { + request.primary_email = Some(value.unwrap_or("").to_string()); + }, + "is-mailbox-setup" => { + request.is_mailbox_setup = Some(arg_from_str(value.unwrap_or("false"), err, "is-mailbox-setup", "boolean")); + }, + "password" => { + request.password = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "hash-function" => { + request.hash_function = Some(value.unwrap_or("").to_string()); + }, + "name.full-name" => { + request_name_init(&mut request); + request.name.as_mut().unwrap().full_name = Some(value.unwrap_or("").to_string()); + }, + "name.given-name" => { + request_name_init(&mut request); + request.name.as_mut().unwrap().given_name = Some(value.unwrap_or("").to_string()); + }, + "name.family-name" => { + request_name_init(&mut request); + request.name.as_mut().unwrap().family_name = Some(value.unwrap_or("").to_string()); + }, + "creation-time" => { + request_name_init(&mut request); + request.creation_time = Some(value.unwrap_or("").to_string()); + }, + "change-password-at-next-login" => { + request_name_init(&mut request); + request.change_password_at_next_login = Some(arg_from_str(value.unwrap_or("false"), err, "change-password-at-next-login", "boolean")); + }, + "customer-id" => { + request_name_init(&mut request); + request.customer_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _users_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.users().list(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "view-type" => { + call = call.view_type(value.unwrap_or("")); + }, + "sort-order" => { + call = call.sort_order(value.unwrap_or("")); + }, + "show-deleted" => { + call = call.show_deleted(value.unwrap_or("")); + }, + "query" => { + call = call.query(value.unwrap_or("")); + }, + "projection" => { + call = call.projection(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "order-by" => { + call = call.order_by(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "event" => { + call = call.event(value.unwrap_or("")); + }, + "domain" => { + call = call.domain(value.unwrap_or("")); + }, + "customer" => { + call = call.customer(value.unwrap_or("")); + }, + "custom-field-mask" => { + call = call.custom_field_mask(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _users_make_admin(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request = api::UserMakeAdmin::default(); + let mut call = self.hub.users().make_admin(&request, &self.opt.arg_user_key); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "status" => { + request.status = Some(arg_from_str(value.unwrap_or("false"), err, "status", "boolean")); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + None + } + } + } + } + + fn _users_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request = api::User::default(); + let mut call = self.hub.users().patch(&request, &self.opt.arg_user_key); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_name_init(request: &mut api::User) { + if request.name.is_none() { + request.name = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "is-delegated-admin" => { + request.is_delegated_admin = Some(arg_from_str(value.unwrap_or("false"), err, "is-delegated-admin", "boolean")); + }, + "suspended" => { + request.suspended = Some(arg_from_str(value.unwrap_or("false"), err, "suspended", "boolean")); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "aliases" => { + if request.aliases.is_none() { + request.aliases = Some(Default::default()); + } + request.aliases.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "non-editable-aliases" => { + if request.non_editable_aliases.is_none() { + request.non_editable_aliases = Some(Default::default()); + } + request.non_editable_aliases.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "deletion-time" => { + request.deletion_time = Some(value.unwrap_or("").to_string()); + }, + "suspension-reason" => { + request.suspension_reason = Some(value.unwrap_or("").to_string()); + }, + "thumbnail-photo-url" => { + request.thumbnail_photo_url = Some(value.unwrap_or("").to_string()); + }, + "is-admin" => { + request.is_admin = Some(arg_from_str(value.unwrap_or("false"), err, "is-admin", "boolean")); + }, + "include-in-global-address-list" => { + request.include_in_global_address_list = Some(arg_from_str(value.unwrap_or("false"), err, "include-in-global-address-list", "boolean")); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "last-login-time" => { + request.last_login_time = Some(value.unwrap_or("").to_string()); + }, + "org-unit-path" => { + request.org_unit_path = Some(value.unwrap_or("").to_string()); + }, + "agreed-to-terms" => { + request.agreed_to_terms = Some(arg_from_str(value.unwrap_or("false"), err, "agreed-to-terms", "boolean")); + }, + "ip-whitelisted" => { + request.ip_whitelisted = Some(arg_from_str(value.unwrap_or("false"), err, "ip-whitelisted", "boolean")); + }, + "primary-email" => { + request.primary_email = Some(value.unwrap_or("").to_string()); + }, + "is-mailbox-setup" => { + request.is_mailbox_setup = Some(arg_from_str(value.unwrap_or("false"), err, "is-mailbox-setup", "boolean")); + }, + "password" => { + request.password = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "hash-function" => { + request.hash_function = Some(value.unwrap_or("").to_string()); + }, + "name.full-name" => { + request_name_init(&mut request); + request.name.as_mut().unwrap().full_name = Some(value.unwrap_or("").to_string()); + }, + "name.given-name" => { + request_name_init(&mut request); + request.name.as_mut().unwrap().given_name = Some(value.unwrap_or("").to_string()); + }, + "name.family-name" => { + request_name_init(&mut request); + request.name.as_mut().unwrap().family_name = Some(value.unwrap_or("").to_string()); + }, + "creation-time" => { + request_name_init(&mut request); + request.creation_time = Some(value.unwrap_or("").to_string()); + }, + "change-password-at-next-login" => { + request_name_init(&mut request); + request.change_password_at_next_login = Some(arg_from_str(value.unwrap_or("false"), err, "change-password-at-next-login", "boolean")); + }, + "customer-id" => { + request_name_init(&mut request); + request.customer_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _users_photos_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.users().photos_delete(&self.opt.arg_user_key); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + None + } + } + } + } + + fn _users_photos_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.users().photos_get(&self.opt.arg_user_key); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _users_photos_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request = api::UserPhoto::default(); + let mut call = self.hub.users().photos_patch(&request, &self.opt.arg_user_key); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "mime-type" => { + request.mime_type = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "photo-data" => { + request.photo_data = Some(value.unwrap_or("").to_string()); + }, + "height" => { + request.height = Some(arg_from_str(value.unwrap_or("-0"), err, "height", "integer")); + }, + "width" => { + request.width = Some(arg_from_str(value.unwrap_or("-0"), err, "width", "integer")); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "primary-email" => { + request.primary_email = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _users_photos_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request = api::UserPhoto::default(); + let mut call = self.hub.users().photos_update(&request, &self.opt.arg_user_key); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "mime-type" => { + request.mime_type = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "photo-data" => { + request.photo_data = Some(value.unwrap_or("").to_string()); + }, + "height" => { + request.height = Some(arg_from_str(value.unwrap_or("-0"), err, "height", "integer")); + }, + "width" => { + request.width = Some(arg_from_str(value.unwrap_or("-0"), err, "width", "integer")); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "primary-email" => { + request.primary_email = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _users_undelete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request = api::UserUndelete::default(); + let mut call = self.hub.users().undelete(&request, &self.opt.arg_user_key); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "org-unit-path" => { + request.org_unit_path = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + None + } + } + } + } + + fn _users_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request = api::User::default(); + let mut call = self.hub.users().update(&request, &self.opt.arg_user_key); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_name_init(request: &mut api::User) { + if request.name.is_none() { + request.name = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "is-delegated-admin" => { + request.is_delegated_admin = Some(arg_from_str(value.unwrap_or("false"), err, "is-delegated-admin", "boolean")); + }, + "suspended" => { + request.suspended = Some(arg_from_str(value.unwrap_or("false"), err, "suspended", "boolean")); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "aliases" => { + if request.aliases.is_none() { + request.aliases = Some(Default::default()); + } + request.aliases.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "non-editable-aliases" => { + if request.non_editable_aliases.is_none() { + request.non_editable_aliases = Some(Default::default()); + } + request.non_editable_aliases.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "deletion-time" => { + request.deletion_time = Some(value.unwrap_or("").to_string()); + }, + "suspension-reason" => { + request.suspension_reason = Some(value.unwrap_or("").to_string()); + }, + "thumbnail-photo-url" => { + request.thumbnail_photo_url = Some(value.unwrap_or("").to_string()); + }, + "is-admin" => { + request.is_admin = Some(arg_from_str(value.unwrap_or("false"), err, "is-admin", "boolean")); + }, + "include-in-global-address-list" => { + request.include_in_global_address_list = Some(arg_from_str(value.unwrap_or("false"), err, "include-in-global-address-list", "boolean")); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "last-login-time" => { + request.last_login_time = Some(value.unwrap_or("").to_string()); + }, + "org-unit-path" => { + request.org_unit_path = Some(value.unwrap_or("").to_string()); + }, + "agreed-to-terms" => { + request.agreed_to_terms = Some(arg_from_str(value.unwrap_or("false"), err, "agreed-to-terms", "boolean")); + }, + "ip-whitelisted" => { + request.ip_whitelisted = Some(arg_from_str(value.unwrap_or("false"), err, "ip-whitelisted", "boolean")); + }, + "primary-email" => { + request.primary_email = Some(value.unwrap_or("").to_string()); + }, + "is-mailbox-setup" => { + request.is_mailbox_setup = Some(arg_from_str(value.unwrap_or("false"), err, "is-mailbox-setup", "boolean")); + }, + "password" => { + request.password = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "hash-function" => { + request.hash_function = Some(value.unwrap_or("").to_string()); + }, + "name.full-name" => { + request_name_init(&mut request); + request.name.as_mut().unwrap().full_name = Some(value.unwrap_or("").to_string()); + }, + "name.given-name" => { + request_name_init(&mut request); + request.name.as_mut().unwrap().given_name = Some(value.unwrap_or("").to_string()); + }, + "name.family-name" => { + request_name_init(&mut request); + request.name.as_mut().unwrap().family_name = Some(value.unwrap_or("").to_string()); + }, + "creation-time" => { + request_name_init(&mut request); + request.creation_time = Some(value.unwrap_or("").to_string()); + }, + "change-password-at-next-login" => { + request_name_init(&mut request); + request.change_password_at_next_login = Some(arg_from_str(value.unwrap_or("false"), err, "change-password-at-next-login", "boolean")); + }, + "customer-id" => { + request_name_init(&mut request); + request.customer_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _users_watch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request = api::Channel::default(); + let mut call = self.hub.users().watch(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "view-type" => { + call = call.view_type(value.unwrap_or("")); + }, + "sort-order" => { + call = call.sort_order(value.unwrap_or("")); + }, + "show-deleted" => { + call = call.show_deleted(value.unwrap_or("")); + }, + "query" => { + call = call.query(value.unwrap_or("")); + }, + "projection" => { + call = call.projection(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "order-by" => { + call = call.order_by(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "event" => { + call = call.event(value.unwrap_or("")); + }, + "domain" => { + call = call.domain(value.unwrap_or("")); + }, + "customer" => { + call = call.customer(value.unwrap_or("")); + }, + "custom-field-mask" => { + call = call.custom_field_mask(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "resource-uri" => { + request.resource_uri = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "resource-id" => { + request.resource_id = Some(value.unwrap_or("").to_string()); + }, + "payload" => { + request.payload = Some(arg_from_str(value.unwrap_or("false"), err, "payload", "boolean")); + }, + "token" => { + request.token = Some(value.unwrap_or("").to_string()); + }, + "params" => { + if request.params.is_none() { + request.params = Some(Default::default()); + } + let (key, value) = parse_kv_arg(value.unwrap_or(""), err, true); + request.params.as_mut().unwrap().insert(key.to_string(), value.unwrap_or("").to_string()); + }, + "expiration" => { + request.expiration = Some(value.unwrap_or("").to_string()); + }, + "address" => { + request.address = Some(value.unwrap_or("").to_string()); + }, + "type" => { + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _verification_codes_generate(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.verification_codes().generate(&self.opt.arg_user_key); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + None + } + } + } + } + + fn _verification_codes_invalidate(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.verification_codes().invalidate(&self.opt.arg_user_key); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + None + } + } + } + } + + fn _verification_codes_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.verification_codes().list(&self.opt.arg_user_key); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option, Option) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option; + let mut err_opt: Option = None; + + if self.opt.cmd_asps { + if self.opt.cmd_delete { + call_result = self._asps_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._asps_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._asps_list(dry_run, &mut err); + } else { + unreachable!(); + } + } + else if self.opt.cmd_channels { + if self.opt.cmd_stop { + call_result = self._channels_stop(dry_run, &mut err); + } else { + unreachable!(); + } + } + else if self.opt.cmd_chromeosdevices { + if self.opt.cmd_get { + call_result = self._chromeosdevices_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._chromeosdevices_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._chromeosdevices_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._chromeosdevices_update(dry_run, &mut err); + } else { + unreachable!(); + } + } + else if self.opt.cmd_groups { + if self.opt.cmd_aliases_delete { + call_result = self._groups_aliases_delete(dry_run, &mut err); + } else if self.opt.cmd_aliases_insert { + call_result = self._groups_aliases_insert(dry_run, &mut err); + } else if self.opt.cmd_aliases_list { + call_result = self._groups_aliases_list(dry_run, &mut err); + } else if self.opt.cmd_delete { + call_result = self._groups_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._groups_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._groups_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._groups_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._groups_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._groups_update(dry_run, &mut err); + } else { + unreachable!(); + } + } + else if self.opt.cmd_members { + if self.opt.cmd_delete { + call_result = self._members_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._members_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._members_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._members_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._members_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._members_update(dry_run, &mut err); + } else { + unreachable!(); + } + } + else if self.opt.cmd_mobiledevices { + if self.opt.cmd_action { + call_result = self._mobiledevices_action(dry_run, &mut err); + } else if self.opt.cmd_delete { + call_result = self._mobiledevices_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._mobiledevices_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._mobiledevices_list(dry_run, &mut err); + } else { + unreachable!(); + } + } + else if self.opt.cmd_notifications { + if self.opt.cmd_delete { + call_result = self._notifications_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._notifications_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._notifications_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._notifications_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._notifications_update(dry_run, &mut err); + } else { + unreachable!(); + } + } + else if self.opt.cmd_orgunits { + if self.opt.cmd_delete { + call_result = self._orgunits_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._orgunits_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._orgunits_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._orgunits_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._orgunits_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._orgunits_update(dry_run, &mut err); + } else { + unreachable!(); + } + } + else if self.opt.cmd_schemas { + if self.opt.cmd_delete { + call_result = self._schemas_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._schemas_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._schemas_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._schemas_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._schemas_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._schemas_update(dry_run, &mut err); + } else { + unreachable!(); + } + } + else if self.opt.cmd_tokens { + if self.opt.cmd_delete { + call_result = self._tokens_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._tokens_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._tokens_list(dry_run, &mut err); + } else { + unreachable!(); + } + } + else if self.opt.cmd_users { + if self.opt.cmd_aliases_delete { + call_result = self._users_aliases_delete(dry_run, &mut err); + } else if self.opt.cmd_aliases_insert { + call_result = self._users_aliases_insert(dry_run, &mut err); + } else if self.opt.cmd_aliases_list { + call_result = self._users_aliases_list(dry_run, &mut err); + } else if self.opt.cmd_aliases_watch { + call_result = self._users_aliases_watch(dry_run, &mut err); + } else if self.opt.cmd_delete { + call_result = self._users_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._users_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._users_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._users_list(dry_run, &mut err); + } else if self.opt.cmd_make_admin { + call_result = self._users_make_admin(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._users_patch(dry_run, &mut err); + } else if self.opt.cmd_photos_delete { + call_result = self._users_photos_delete(dry_run, &mut err); + } else if self.opt.cmd_photos_get { + call_result = self._users_photos_get(dry_run, &mut err); + } else if self.opt.cmd_photos_patch { + call_result = self._users_photos_patch(dry_run, &mut err); + } else if self.opt.cmd_photos_update { + call_result = self._users_photos_update(dry_run, &mut err); + } else if self.opt.cmd_undelete { + call_result = self._users_undelete(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._users_update(dry_run, &mut err); + } else if self.opt.cmd_watch { + call_result = self._users_watch(dry_run, &mut err); + } else { + unreachable!(); + } + } + else if self.opt.cmd_verification_codes { + if self.opt.cmd_generate { + call_result = self._verification_codes_generate(dry_run, &mut err); + } else if self.opt.cmd_invalidate { + call_result = self._verification_codes_invalidate(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._verification_codes_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else { + unreachable!(); + } + + if dry_run { + if err.issues.len() > 0 { + err_opt = Some(err); + } + } + (call_result, err_opt) + } + + // Please note that this call will fail if any part of the opt can't be handled + fn new(opt: Options) -> Result { + let (config_dir, secret) = { + let config_dir = match cmn::assure_config_dir_exists(&opt.flag_config_dir) { + Err(e) => return Err(InvalidOptionsError::single(e, 3)), + Ok(p) => p, + }; + + match cmn::application_secret_from_directory(&config_dir, "admin1-directory-secret.json", + "{\"installed\":{\"auth_uri\":\"https://accounts.google.com/o/oauth2/auth\",\"client_secret\":\"hCsslbCUyfehWMmbkG8vTYxG\",\"token_uri\":\"https://accounts.google.com/o/oauth2/token\",\"client_email\":\"\",\"redirect_uris\":[\"urn:ietf:wg:oauth:2.0:oob\",\"oob\"],\"client_x509_cert_url\":\"\",\"client_id\":\"620010449518-9ngf7o4dhs0dka470npqvor6dc5lqb9b.apps.googleusercontent.com\",\"auth_provider_x509_cert_url\":\"https://www.googleapis.com/oauth2/v1/certs\"}}") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new( &secret, DefaultAuthenticatorDelegate, + if opt.flag_debug_auth { + hyper::Client::with_connector(mock::TeeConnector { + connector: hyper::net::HttpConnector(None) + }) + } else { + hyper::Client::new() + }, + JsonTokenStorage { + program_name: "admin1-directory", + db_dir: config_dir.clone(), + }, None); + + let client = + if opt.flag_debug { + hyper::Client::with_connector(mock::TeeConnector { + connector: hyper::net::HttpConnector(None) + }) + } else { + hyper::Client::new() + }; + let engine = Engine { + opt: opt, + hub: api::Directory::new(client, auth), + }; + + match engine._doit(true) { + (_, Some(err)) => Err(err), + _ => Ok(engine), + } + } + + // Execute the call with all the bells and whistles, informing the caller only if there was an error. + // The absense of one indicates success. + fn doit(&self) -> Option { + self._doit(false).0 + } +} + +fn main() { + let opts: Options = Options::docopt().decode().unwrap_or_else(|e| e.exit()); + match Engine::new(opts) { + Err(err) => { + writeln!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + writeln!(io::stderr(), "{:?}", err).ok(); + writeln!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/admin1_reports-cli/Cargo.toml b/gen/admin1_reports-cli/Cargo.toml new file mode 100644 index 0000000000..9b3bfa8c59 --- /dev/null +++ b/gen/admin1_reports-cli/Cargo.toml @@ -0,0 +1,31 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-admin1_reports-cli" +version = "0.0.1+20150115" +authors = ["Sebastian Thiel "] +description = "A complete library to interact with reports (protocol reports_v1)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/admin1_reports-cli" +homepage = "https://developers.google.com/admin-sdk/reports/" +documentation = "http://byron.github.io/google-apis-rs/google_admin1_reports_cli" +license = "MIT" +keywords = ["admin", "google", "cli"] + +[[bin]] +name = "admin1-reports" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "*" +docopt_macros = "*" +rustc-serialize = "*" +yup-hyper-mock = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-admin1_reports] +path = "../admin1_reports" diff --git a/gen/admin1_reports-cli/LICENSE.md b/gen/admin1_reports-cli/LICENSE.md new file mode 100644 index 0000000000..ae22e6ec52 --- /dev/null +++ b/gen/admin1_reports-cli/LICENSE.md @@ -0,0 +1,30 @@ + +The MIT License (MIT) +===================== + +Copyright © `2015` `Sebastian Thiel` + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the “Software”), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. diff --git a/gen/admin1_reports-cli/README.md b/gen/admin1_reports-cli/README.md new file mode 100644 index 0000000000..d63739eb1c --- /dev/null +++ b/gen/admin1_reports-cli/README.md @@ -0,0 +1,4 @@ +# HELLO ADMIN:REPORTS_V1 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/admin1_reports-cli/mkdocs.yml b/gen/admin1_reports-cli/mkdocs.yml new file mode 100644 index 0000000000..d5581f072c --- /dev/null +++ b/gen/admin1_reports-cli/mkdocs.yml @@ -0,0 +1,21 @@ +site_name: reports v0.0.1+20150115 +site_url: http://byron.github.io/google-apis-rs/google-admin1_reports-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/admin1_reports-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['activities_list.md', 'Activities', 'List'] +- ['activities_watch.md', 'Activities', 'Watch'] +- ['channels_stop.md', 'Channels', 'Stop'] +- ['customer-usage-reports_get.md', 'Customer Usage Reports', 'Get'] +- ['user-usage-report_get.md', 'User Usage Report', 'Get'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/admin1_reports-cli/src/cmn.rs b/gen/admin1_reports-cli/src/cmn.rs new file mode 100644 index 0000000000..a8d3f46368 --- /dev/null +++ b/gen/admin1_reports-cli/src/cmn.rs @@ -0,0 +1,454 @@ +// COPY OF 'src/rust/cli/cmn.rs' +// DO NOT EDIT +use oauth2::{ApplicationSecret, ConsoleApplicationSecret, TokenStorage, Token}; +use rustc_serialize::json; +use mime::Mime; + +use std::fs; +use std::env; +use std::io; +use std::fmt; +use std::path::{Path, PathBuf}; +use std::str::FromStr; +use std::string::ToString; +use std::io::{Write, Read, stdout}; + +use std::default::Default; + +const FIELD_SEP: char = '.'; + +#[derive(Clone, Default)] +pub struct FieldCursor(Vec); + +impl ToString for FieldCursor { + fn to_string(&self) -> String { + self.0.connect(".") + } +} + +impl FieldCursor { + pub fn set(&mut self, value: &str) -> Result<(), CLIError> { + if value.len() == 0 { + return Err(CLIError::Field(FieldError::Empty)) + } + + let mut first_is_field_sep = false; + let mut char_count: usize = 0; + let mut last_c = FIELD_SEP; + let mut num_conscutive_field_seps = 0; + + let mut field = String::new(); + let mut fields = self.0.clone(); + + let push_field = |fs: &mut Vec, f: &mut String| { + if f.len() > 0 { + fs.push(f.clone()); + f.truncate(0); + } + }; + + for (cid, c) in value.chars().enumerate() { + char_count += 1; + + if c == FIELD_SEP { + if cid == 0 { + first_is_field_sep = true; + } + num_conscutive_field_seps += 1; + if cid > 0 && last_c == FIELD_SEP { + if fields.pop().is_none() { + return Err(CLIError::Field(FieldError::PopOnEmpty(value.to_string()))) + } + } else { + push_field(&mut fields, &mut field); + } + } else { + num_conscutive_field_seps = 0; + if cid == 1 { + if first_is_field_sep { + fields.truncate(0); + } + } + field.push(c); + } + + last_c = c; + } + + push_field(&mut fields, &mut field); + + if char_count == 1 && first_is_field_sep { + fields.truncate(0); + } + if char_count > 1 && num_conscutive_field_seps == 1 { + return Err(CLIError::Field(FieldError::TrailingFieldSep(value.to_string()))) + } + + self.0 = fields; + Ok(()) + } + + pub fn num_fields(&self) -> usize { + self.0.len() + } +} + +pub fn parse_kv_arg<'a>(kv: &'a str, err: &mut InvalidOptionsError, for_hashmap: bool) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string(),for_hashmap)); + match kv.find('=') { + None => { + add_err(); + return (kv, None) + }, + Some(pos) => { + let key = &kv[..pos]; + if kv.len() <= pos + 1 { + add_err(); + return (key, None) + } + (key, Some(&kv[pos+1..])) + } + } +} + +pub fn input_file_from_opts(file_path: &str, err: &mut InvalidOptionsError) -> Option { + match fs::File::open(file_path) { + Ok(f) => Some(f), + Err(io_err) => { + err.issues.push(CLIError::Input(InputError::IOError((file_path.to_string(), io_err)))); + None + } + } +} + +pub fn input_mime_from_opts(mime: &str, err: &mut InvalidOptionsError) -> Option { + match mime.parse() { + Ok(m) => Some(m), + Err(_) => { + err.issues.push(CLIError::Input(InputError::Mime(mime.to_string()))); + None + } + } +} + +// May panic if we can't open the file - this is anticipated, we can't currently communicate this +// kind of error: TODO: fix this architecture :) +pub fn writer_from_opts(flag: bool, arg: &str) -> Box { + if !flag || arg == "-" { + Box::new(stdout()) + } else { + Box::new(fs::OpenOptions::new().create(true).write(true).open(arg).unwrap()) + } +} + + +pub fn arg_from_str(arg: &str, err: &mut InvalidOptionsError, + arg_name: &'static str, + arg_type: &'static str) -> T + where T: FromStr + Default, + ::Err: fmt::Display { + match FromStr::from_str(arg) { + Err(perr) => { + err.issues.push( + CLIError::ParseError((arg_name, arg_type, arg.to_string(), format!("{}", perr))) + ); + Default::default() + }, + Ok(v) => v, + } +} + +pub struct JsonTokenStorage { + pub program_name: &'static str, + pub db_dir: String, +} + +impl JsonTokenStorage { + fn path(&self, scope_hash: u64) -> PathBuf { + Path::new(&self.db_dir).join(&format!("{}-token-{}.json", self.program_name, scope_hash)) + } +} + +impl TokenStorage for JsonTokenStorage { + type Error = io::Error; + + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, _: &Vec<&str>, token: Option) -> Option { + match token { + None => { + match fs::remove_file(self.path(scope_hash)) { + Err(err) => + match err.kind() { + io::ErrorKind::NotFound => None, + _ => Some(err) + }, + Ok(_) => None + } + } + Some(token) => { + let json_token = json::encode(&token).unwrap(); + match fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)) { + Ok(mut f) => { + match f.write(json_token.as_bytes()) { + Ok(_) => None, + Err(io_err) => Some(io_err), + } + }, + Err(io_err) => Some(io_err) + } + } + } + } + + fn get(&self, scope_hash: u64, _: &Vec<&str>) -> Result, io::Error> { + match fs::File::open(&self.path(scope_hash)) { + Ok(mut f) => { + let mut json_string = String::new(); + match f.read_to_string(&mut json_string) { + Ok(_) => Ok(Some(json::decode::(&json_string).unwrap())), + Err(io_err) => Err(io_err), + } + }, + Err(io_err) => { + match io_err.kind() { + io::ErrorKind::NotFound => Ok(None), + _ => Err(io_err) + } + } + } + } +} + + +#[derive(Debug)] +pub enum ApplicationSecretError { + DecoderError((String, json::DecoderError)), + FormatError(String), +} + +impl fmt::Display for ApplicationSecretError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + match *self { + ApplicationSecretError::DecoderError((ref path, ref err)) + => writeln!(f, "Could not decode file at '{}' with error: {}", + path, err), + ApplicationSecretError::FormatError(ref path) + => writeln!(f, "'installed' field is unset in secret file at '{}'", + path), + } + } +} + +#[derive(Debug)] +pub enum ConfigurationError { + DirectoryCreationFailed((String, io::Error)), + DirectoryUnset, + HomeExpansionFailed(String), + Secret(ApplicationSecretError), + IOError((String, io::Error)), +} + +impl fmt::Display for ConfigurationError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + match *self { + ConfigurationError::DirectoryCreationFailed((ref dir, ref err)) + => writeln!(f, "Directory '{}' could not be created with error: {}", dir, err), + ConfigurationError::DirectoryUnset + => writeln!(f, "--config-dir was unset or empty"), + ConfigurationError::HomeExpansionFailed(ref dir) + => writeln!(f, "Couldn't find HOME directory of current user, failed to expand '{}'", dir), + ConfigurationError::Secret(ref err) + => writeln!(f, "Secret -> {}", err), + ConfigurationError::IOError((ref path, ref err)) + => writeln!(f, "IO operation failed on path '{}' with error: {}", path, err), + } + } +} + +#[derive(Debug)] +pub enum InputError { + IOError((String, io::Error)), + Mime(String), +} + +impl fmt::Display for InputError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + match *self { + InputError::IOError((ref file_path, ref io_err)) + => writeln!(f, "Failed to open '{}' for reading with error: {}", file_path, io_err), + InputError::Mime(ref mime) + => writeln!(f, "'{}' is not a known mime-type", mime), + } + } +} + +#[derive(Debug)] +pub enum FieldError { + PopOnEmpty(String), + TrailingFieldSep(String), + Unknown(String), + Empty, +} + + +impl fmt::Display for FieldError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + match *self { + FieldError::PopOnEmpty(ref field) + => writeln!(f, "'{}': Cannot move up on empty field cursor", field), + FieldError::TrailingFieldSep(ref field) + => writeln!(f, "'{}': Single field separator may not be last character", field), + FieldError::Unknown(ref field) + => writeln!(f, "Field '{}' does not exist", field), + FieldError::Empty + => writeln!(f, "Field names must not be empty"), + } + } +} + + +#[derive(Debug)] +pub enum CLIError { + Configuration(ConfigurationError), + ParseError((&'static str, &'static str, String, String)), + UnknownParameter(String), + InvalidKeyValueSyntax(String, bool), + Input(InputError), + Field(FieldError), +} + +impl fmt::Display for CLIError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + match *self { + CLIError::Configuration(ref err) => write!(f, "Configuration -> {}", err), + CLIError::Input(ref err) => write!(f, "Input -> {}", err), + CLIError::Field(ref err) => write!(f, "Field -> {}", err), + CLIError::ParseError((arg_name, 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) + => writeln!(f, "Parameter '{}' is unknown.", param_name), + CLIError::InvalidKeyValueSyntax(ref kv, is_hashmap) => { + let hashmap_info = if is_hashmap { "hashmap " } else { "" }; + writeln!(f, "'{}' does not match {}pattern =", kv, hashmap_info) + }, + } + } +} + +#[derive(Debug)] +pub struct InvalidOptionsError { + pub issues: Vec, + pub exit_code: i32, +} + +impl fmt::Display for InvalidOptionsError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + for issue in &self.issues { + try!(issue.fmt(f)); + } + Ok(()) + } +} + +impl InvalidOptionsError { + pub fn single(err: CLIError, exit_code: i32) -> InvalidOptionsError { + InvalidOptionsError { + issues: vec![err], + exit_code: exit_code, + } + } + + pub fn new() -> InvalidOptionsError { + InvalidOptionsError { + issues: Vec::new(), + exit_code: 1, + } + } +} + +pub fn assure_config_dir_exists(dir: &str) -> Result { + let trdir = dir.trim(); + if trdir.len() == 0 { + return Err(CLIError::Configuration(ConfigurationError::DirectoryUnset)) + } + + let expanded_config_dir = + if trdir.as_bytes()[0] == b'~' { + match env::var("HOME").ok().or(env::var("UserProfile").ok()) { + None => return Err(CLIError::Configuration(ConfigurationError::HomeExpansionFailed(trdir.to_string()))), + Some(mut user) => { + user.push_str(&trdir[1..]); + user + } + } + } else { + trdir.to_string() + }; + + if let Err(err) = fs::create_dir(&expanded_config_dir) { + if err.kind() != io::ErrorKind::AlreadyExists { + return Err(CLIError::Configuration( + ConfigurationError::DirectoryCreationFailed((expanded_config_dir, err)))) + } + } + + Ok(expanded_config_dir) +} + +pub fn application_secret_from_directory(dir: &str, + secret_basename: &str, + json_app_secret: &str) + -> Result { + let secret_path = Path::new(dir).join(secret_basename); + let secret_str = || secret_path.as_path().to_str().unwrap().to_string(); + let secret_io_error = |io_err: io::Error| { + Err(CLIError::Configuration(ConfigurationError::IOError( + (secret_str(), io_err) + ))) + }; + + for _ in 0..2 { + match fs::File::open(&secret_path) { + Err(mut err) => { + if err.kind() == io::ErrorKind::NotFound { + // Write our built-in one - user may adjust the written file at will + + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_app_secret.as_bytes()) { + Err(io_err) => io_err, + Ok(_) => continue, + } + } + }; + // fall through to IO error handling + } + return secret_io_error(err) + }, + Ok(mut f) => { + let mut json_encoded_secret = String::new(); + if let Err(io_err) = f.read_to_string(&mut json_encoded_secret) { + return secret_io_error(io_err) + } + match json::decode::(&json_encoded_secret) { + Err(json_decode_error) => return Err(CLIError::Configuration( + ConfigurationError::Secret(ApplicationSecretError::DecoderError( + (secret_str(), json_decode_error) + )))), + Ok(console_secret) => match console_secret.installed { + Some(secret) => return Ok(secret), + None => return Err( + CLIError::Configuration( + ConfigurationError::Secret( + ApplicationSecretError::FormatError(secret_str()) + ))) + }, + } + } + } + } + unreachable!(); +} \ No newline at end of file diff --git a/gen/admin1_reports-cli/src/main.rs b/gen/admin1_reports-cli/src/main.rs new file mode 100644 index 0000000000..1a9fc29c3e --- /dev/null +++ b/gen/admin1_reports-cli/src/main.rs @@ -0,0 +1,561 @@ +// DO NOT EDIT ! +// This file was generated automatically from 'src/mako/cli/main.rs.mako' +// DO NOT EDIT ! +#![feature(plugin, exit_status)] +#![plugin(docopt_macros)] +#![allow(unused_variables, unused_imports, dead_code, unused_mut)] + +extern crate docopt; +extern crate yup_oauth2 as oauth2; +extern crate yup_hyper_mock as mock; +extern crate rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_admin1_reports as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + admin1-reports [options] activities list [-p ]... [-o ] + admin1-reports [options] activities watch -r ... [-p ]... [-o ] + admin1-reports [options] channels stop -r ... [-p ]... + admin1-reports [options] customer-usage-reports get [-p ]... [-o ] + admin1-reports [options] user-usage-report get [-p ]... [-o ] + admin1-reports --help + +All documentation details can be found TODO: + +Configuration: + --scope + 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. + --config-dir + 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] + --debug + Output all server communication to standard error. `tx` and `rx` are placed into + the same stream. + --debug-auth + Output all communication related to authentication to standard error. `tx` and `rx` are placed into + the same stream. +"); + +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}; + +use std::default::Default; +use std::str::FromStr; + +use oauth2::{Authenticator, DefaultAuthenticatorDelegate}; +use rustc_serialize::json; + +struct Engine { + opt: Options, + hub: api::Reports>, +} + + +impl Engine { + fn _activities_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.activities().list(&self.opt.arg_user_key, &self.opt.arg_application_name); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "start-time" => { + call = call.start_time(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "filters" => { + call = call.filters(value.unwrap_or("")); + }, + "event-name" => { + call = call.event_name(value.unwrap_or("")); + }, + "end-time" => { + call = call.end_time(value.unwrap_or("")); + }, + "customer-id" => { + call = call.customer_id(value.unwrap_or("")); + }, + "actor-ip-address" => { + call = call.actor_ip_address(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _activities_watch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request = api::Channel::default(); + let mut call = self.hub.activities().watch(&request, &self.opt.arg_user_key, &self.opt.arg_application_name); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "start-time" => { + call = call.start_time(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "filters" => { + call = call.filters(value.unwrap_or("")); + }, + "event-name" => { + call = call.event_name(value.unwrap_or("")); + }, + "end-time" => { + call = call.end_time(value.unwrap_or("")); + }, + "customer-id" => { + call = call.customer_id(value.unwrap_or("")); + }, + "actor-ip-address" => { + call = call.actor_ip_address(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "resource-uri" => { + request.resource_uri = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "resource-id" => { + request.resource_id = Some(value.unwrap_or("").to_string()); + }, + "payload" => { + request.payload = Some(arg_from_str(value.unwrap_or("false"), err, "payload", "boolean")); + }, + "token" => { + request.token = Some(value.unwrap_or("").to_string()); + }, + "params" => { + if request.params.is_none() { + request.params = Some(Default::default()); + } + let (key, value) = parse_kv_arg(value.unwrap_or(""), err, true); + request.params.as_mut().unwrap().insert(key.to_string(), value.unwrap_or("").to_string()); + }, + "expiration" => { + request.expiration = Some(value.unwrap_or("").to_string()); + }, + "address" => { + request.address = Some(value.unwrap_or("").to_string()); + }, + "type" => { + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _channels_stop(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request = api::Channel::default(); + let mut call = self.hub.channels().stop(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "resource-uri" => { + request.resource_uri = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "resource-id" => { + request.resource_id = Some(value.unwrap_or("").to_string()); + }, + "payload" => { + request.payload = Some(arg_from_str(value.unwrap_or("false"), err, "payload", "boolean")); + }, + "token" => { + request.token = Some(value.unwrap_or("").to_string()); + }, + "params" => { + if request.params.is_none() { + request.params = Some(Default::default()); + } + let (key, value) = parse_kv_arg(value.unwrap_or(""), err, true); + request.params.as_mut().unwrap().insert(key.to_string(), value.unwrap_or("").to_string()); + }, + "expiration" => { + request.expiration = Some(value.unwrap_or("").to_string()); + }, + "address" => { + request.address = Some(value.unwrap_or("").to_string()); + }, + "type" => { + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + None + } + } + } + } + + fn _customer_usage_reports_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.customer_usage_reports().get(&self.opt.arg_date); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "parameters" => { + call = call.parameters(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "customer-id" => { + call = call.customer_id(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _user_usage_report_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.user_usage_report().get(&self.opt.arg_user_key, &self.opt.arg_date); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "parameters" => { + call = call.parameters(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "filters" => { + call = call.filters(value.unwrap_or("")); + }, + "customer-id" => { + call = call.customer_id(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option, Option) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option; + let mut err_opt: Option = None; + + if self.opt.cmd_activities { + if self.opt.cmd_list { + call_result = self._activities_list(dry_run, &mut err); + } else if self.opt.cmd_watch { + call_result = self._activities_watch(dry_run, &mut err); + } else { + unreachable!(); + } + } + else if self.opt.cmd_channels { + if self.opt.cmd_stop { + call_result = self._channels_stop(dry_run, &mut err); + } else { + unreachable!(); + } + } + else if self.opt.cmd_customer_usage_reports { + if self.opt.cmd_get { + call_result = self._customer_usage_reports_get(dry_run, &mut err); + } else { + unreachable!(); + } + } + else if self.opt.cmd_user_usage_report { + if self.opt.cmd_get { + call_result = self._user_usage_report_get(dry_run, &mut err); + } else { + unreachable!(); + } + } else { + unreachable!(); + } + + if dry_run { + if err.issues.len() > 0 { + err_opt = Some(err); + } + } + (call_result, err_opt) + } + + // Please note that this call will fail if any part of the opt can't be handled + fn new(opt: Options) -> Result { + let (config_dir, secret) = { + let config_dir = match cmn::assure_config_dir_exists(&opt.flag_config_dir) { + Err(e) => return Err(InvalidOptionsError::single(e, 3)), + Ok(p) => p, + }; + + match cmn::application_secret_from_directory(&config_dir, "admin1-reports-secret.json", + "{\"installed\":{\"auth_uri\":\"https://accounts.google.com/o/oauth2/auth\",\"client_secret\":\"hCsslbCUyfehWMmbkG8vTYxG\",\"token_uri\":\"https://accounts.google.com/o/oauth2/token\",\"client_email\":\"\",\"redirect_uris\":[\"urn:ietf:wg:oauth:2.0:oob\",\"oob\"],\"client_x509_cert_url\":\"\",\"client_id\":\"620010449518-9ngf7o4dhs0dka470npqvor6dc5lqb9b.apps.googleusercontent.com\",\"auth_provider_x509_cert_url\":\"https://www.googleapis.com/oauth2/v1/certs\"}}") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new( &secret, DefaultAuthenticatorDelegate, + if opt.flag_debug_auth { + hyper::Client::with_connector(mock::TeeConnector { + connector: hyper::net::HttpConnector(None) + }) + } else { + hyper::Client::new() + }, + JsonTokenStorage { + program_name: "admin1-reports", + db_dir: config_dir.clone(), + }, None); + + let client = + if opt.flag_debug { + hyper::Client::with_connector(mock::TeeConnector { + connector: hyper::net::HttpConnector(None) + }) + } else { + hyper::Client::new() + }; + let engine = Engine { + opt: opt, + hub: api::Reports::new(client, auth), + }; + + match engine._doit(true) { + (_, Some(err)) => Err(err), + _ => Ok(engine), + } + } + + // Execute the call with all the bells and whistles, informing the caller only if there was an error. + // The absense of one indicates success. + fn doit(&self) -> Option { + self._doit(false).0 + } +} + +fn main() { + let opts: Options = Options::docopt().decode().unwrap_or_else(|e| e.exit()); + match Engine::new(opts) { + Err(err) => { + writeln!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + writeln!(io::stderr(), "{:?}", err).ok(); + writeln!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/admin2_email_migration-cli/Cargo.toml b/gen/admin2_email_migration-cli/Cargo.toml new file mode 100644 index 0000000000..6f392cb62b --- /dev/null +++ b/gen/admin2_email_migration-cli/Cargo.toml @@ -0,0 +1,31 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-admin2_email_migration-cli" +version = "0.0.1+20150303" +authors = ["Sebastian Thiel "] +description = "A complete library to interact with admin (protocol email_migration_v2)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/admin2_email_migration-cli" +homepage = "https://developers.google.com/admin-sdk/email-migration/v2/" +documentation = "http://byron.github.io/google-apis-rs/google_admin2_email_migration_cli" +license = "MIT" +keywords = ["admin", "google", "cli"] + +[[bin]] +name = "admin2-email-migration" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "*" +docopt_macros = "*" +rustc-serialize = "*" +yup-hyper-mock = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-admin2_email_migration] +path = "../admin2_email_migration" diff --git a/gen/admin2_email_migration-cli/LICENSE.md b/gen/admin2_email_migration-cli/LICENSE.md new file mode 100644 index 0000000000..ae22e6ec52 --- /dev/null +++ b/gen/admin2_email_migration-cli/LICENSE.md @@ -0,0 +1,30 @@ + +The MIT License (MIT) +===================== + +Copyright © `2015` `Sebastian Thiel` + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the “Software”), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. diff --git a/gen/admin2_email_migration-cli/README.md b/gen/admin2_email_migration-cli/README.md new file mode 100644 index 0000000000..ed6449c3ab --- /dev/null +++ b/gen/admin2_email_migration-cli/README.md @@ -0,0 +1,4 @@ +# HELLO ADMIN:EMAIL_MIGRATION_V2 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/admin2_email_migration-cli/mkdocs.yml b/gen/admin2_email_migration-cli/mkdocs.yml new file mode 100644 index 0000000000..c666938a66 --- /dev/null +++ b/gen/admin2_email_migration-cli/mkdocs.yml @@ -0,0 +1,17 @@ +site_name: admin v0.0.1+20150303 +site_url: http://byron.github.io/google-apis-rs/google-admin2_email_migration-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/admin2_email_migration-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['mail_insert.md', 'Mail', 'Insert'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/admin2_email_migration-cli/src/cmn.rs b/gen/admin2_email_migration-cli/src/cmn.rs new file mode 100644 index 0000000000..a8d3f46368 --- /dev/null +++ b/gen/admin2_email_migration-cli/src/cmn.rs @@ -0,0 +1,454 @@ +// COPY OF 'src/rust/cli/cmn.rs' +// DO NOT EDIT +use oauth2::{ApplicationSecret, ConsoleApplicationSecret, TokenStorage, Token}; +use rustc_serialize::json; +use mime::Mime; + +use std::fs; +use std::env; +use std::io; +use std::fmt; +use std::path::{Path, PathBuf}; +use std::str::FromStr; +use std::string::ToString; +use std::io::{Write, Read, stdout}; + +use std::default::Default; + +const FIELD_SEP: char = '.'; + +#[derive(Clone, Default)] +pub struct FieldCursor(Vec); + +impl ToString for FieldCursor { + fn to_string(&self) -> String { + self.0.connect(".") + } +} + +impl FieldCursor { + pub fn set(&mut self, value: &str) -> Result<(), CLIError> { + if value.len() == 0 { + return Err(CLIError::Field(FieldError::Empty)) + } + + let mut first_is_field_sep = false; + let mut char_count: usize = 0; + let mut last_c = FIELD_SEP; + let mut num_conscutive_field_seps = 0; + + let mut field = String::new(); + let mut fields = self.0.clone(); + + let push_field = |fs: &mut Vec, f: &mut String| { + if f.len() > 0 { + fs.push(f.clone()); + f.truncate(0); + } + }; + + for (cid, c) in value.chars().enumerate() { + char_count += 1; + + if c == FIELD_SEP { + if cid == 0 { + first_is_field_sep = true; + } + num_conscutive_field_seps += 1; + if cid > 0 && last_c == FIELD_SEP { + if fields.pop().is_none() { + return Err(CLIError::Field(FieldError::PopOnEmpty(value.to_string()))) + } + } else { + push_field(&mut fields, &mut field); + } + } else { + num_conscutive_field_seps = 0; + if cid == 1 { + if first_is_field_sep { + fields.truncate(0); + } + } + field.push(c); + } + + last_c = c; + } + + push_field(&mut fields, &mut field); + + if char_count == 1 && first_is_field_sep { + fields.truncate(0); + } + if char_count > 1 && num_conscutive_field_seps == 1 { + return Err(CLIError::Field(FieldError::TrailingFieldSep(value.to_string()))) + } + + self.0 = fields; + Ok(()) + } + + pub fn num_fields(&self) -> usize { + self.0.len() + } +} + +pub fn parse_kv_arg<'a>(kv: &'a str, err: &mut InvalidOptionsError, for_hashmap: bool) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string(),for_hashmap)); + match kv.find('=') { + None => { + add_err(); + return (kv, None) + }, + Some(pos) => { + let key = &kv[..pos]; + if kv.len() <= pos + 1 { + add_err(); + return (key, None) + } + (key, Some(&kv[pos+1..])) + } + } +} + +pub fn input_file_from_opts(file_path: &str, err: &mut InvalidOptionsError) -> Option { + match fs::File::open(file_path) { + Ok(f) => Some(f), + Err(io_err) => { + err.issues.push(CLIError::Input(InputError::IOError((file_path.to_string(), io_err)))); + None + } + } +} + +pub fn input_mime_from_opts(mime: &str, err: &mut InvalidOptionsError) -> Option { + match mime.parse() { + Ok(m) => Some(m), + Err(_) => { + err.issues.push(CLIError::Input(InputError::Mime(mime.to_string()))); + None + } + } +} + +// May panic if we can't open the file - this is anticipated, we can't currently communicate this +// kind of error: TODO: fix this architecture :) +pub fn writer_from_opts(flag: bool, arg: &str) -> Box { + if !flag || arg == "-" { + Box::new(stdout()) + } else { + Box::new(fs::OpenOptions::new().create(true).write(true).open(arg).unwrap()) + } +} + + +pub fn arg_from_str(arg: &str, err: &mut InvalidOptionsError, + arg_name: &'static str, + arg_type: &'static str) -> T + where T: FromStr + Default, + ::Err: fmt::Display { + match FromStr::from_str(arg) { + Err(perr) => { + err.issues.push( + CLIError::ParseError((arg_name, arg_type, arg.to_string(), format!("{}", perr))) + ); + Default::default() + }, + Ok(v) => v, + } +} + +pub struct JsonTokenStorage { + pub program_name: &'static str, + pub db_dir: String, +} + +impl JsonTokenStorage { + fn path(&self, scope_hash: u64) -> PathBuf { + Path::new(&self.db_dir).join(&format!("{}-token-{}.json", self.program_name, scope_hash)) + } +} + +impl TokenStorage for JsonTokenStorage { + type Error = io::Error; + + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, _: &Vec<&str>, token: Option) -> Option { + match token { + None => { + match fs::remove_file(self.path(scope_hash)) { + Err(err) => + match err.kind() { + io::ErrorKind::NotFound => None, + _ => Some(err) + }, + Ok(_) => None + } + } + Some(token) => { + let json_token = json::encode(&token).unwrap(); + match fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)) { + Ok(mut f) => { + match f.write(json_token.as_bytes()) { + Ok(_) => None, + Err(io_err) => Some(io_err), + } + }, + Err(io_err) => Some(io_err) + } + } + } + } + + fn get(&self, scope_hash: u64, _: &Vec<&str>) -> Result, io::Error> { + match fs::File::open(&self.path(scope_hash)) { + Ok(mut f) => { + let mut json_string = String::new(); + match f.read_to_string(&mut json_string) { + Ok(_) => Ok(Some(json::decode::(&json_string).unwrap())), + Err(io_err) => Err(io_err), + } + }, + Err(io_err) => { + match io_err.kind() { + io::ErrorKind::NotFound => Ok(None), + _ => Err(io_err) + } + } + } + } +} + + +#[derive(Debug)] +pub enum ApplicationSecretError { + DecoderError((String, json::DecoderError)), + FormatError(String), +} + +impl fmt::Display for ApplicationSecretError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + match *self { + ApplicationSecretError::DecoderError((ref path, ref err)) + => writeln!(f, "Could not decode file at '{}' with error: {}", + path, err), + ApplicationSecretError::FormatError(ref path) + => writeln!(f, "'installed' field is unset in secret file at '{}'", + path), + } + } +} + +#[derive(Debug)] +pub enum ConfigurationError { + DirectoryCreationFailed((String, io::Error)), + DirectoryUnset, + HomeExpansionFailed(String), + Secret(ApplicationSecretError), + IOError((String, io::Error)), +} + +impl fmt::Display for ConfigurationError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + match *self { + ConfigurationError::DirectoryCreationFailed((ref dir, ref err)) + => writeln!(f, "Directory '{}' could not be created with error: {}", dir, err), + ConfigurationError::DirectoryUnset + => writeln!(f, "--config-dir was unset or empty"), + ConfigurationError::HomeExpansionFailed(ref dir) + => writeln!(f, "Couldn't find HOME directory of current user, failed to expand '{}'", dir), + ConfigurationError::Secret(ref err) + => writeln!(f, "Secret -> {}", err), + ConfigurationError::IOError((ref path, ref err)) + => writeln!(f, "IO operation failed on path '{}' with error: {}", path, err), + } + } +} + +#[derive(Debug)] +pub enum InputError { + IOError((String, io::Error)), + Mime(String), +} + +impl fmt::Display for InputError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + match *self { + InputError::IOError((ref file_path, ref io_err)) + => writeln!(f, "Failed to open '{}' for reading with error: {}", file_path, io_err), + InputError::Mime(ref mime) + => writeln!(f, "'{}' is not a known mime-type", mime), + } + } +} + +#[derive(Debug)] +pub enum FieldError { + PopOnEmpty(String), + TrailingFieldSep(String), + Unknown(String), + Empty, +} + + +impl fmt::Display for FieldError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + match *self { + FieldError::PopOnEmpty(ref field) + => writeln!(f, "'{}': Cannot move up on empty field cursor", field), + FieldError::TrailingFieldSep(ref field) + => writeln!(f, "'{}': Single field separator may not be last character", field), + FieldError::Unknown(ref field) + => writeln!(f, "Field '{}' does not exist", field), + FieldError::Empty + => writeln!(f, "Field names must not be empty"), + } + } +} + + +#[derive(Debug)] +pub enum CLIError { + Configuration(ConfigurationError), + ParseError((&'static str, &'static str, String, String)), + UnknownParameter(String), + InvalidKeyValueSyntax(String, bool), + Input(InputError), + Field(FieldError), +} + +impl fmt::Display for CLIError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + match *self { + CLIError::Configuration(ref err) => write!(f, "Configuration -> {}", err), + CLIError::Input(ref err) => write!(f, "Input -> {}", err), + CLIError::Field(ref err) => write!(f, "Field -> {}", err), + CLIError::ParseError((arg_name, 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) + => writeln!(f, "Parameter '{}' is unknown.", param_name), + CLIError::InvalidKeyValueSyntax(ref kv, is_hashmap) => { + let hashmap_info = if is_hashmap { "hashmap " } else { "" }; + writeln!(f, "'{}' does not match {}pattern =", kv, hashmap_info) + }, + } + } +} + +#[derive(Debug)] +pub struct InvalidOptionsError { + pub issues: Vec, + pub exit_code: i32, +} + +impl fmt::Display for InvalidOptionsError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + for issue in &self.issues { + try!(issue.fmt(f)); + } + Ok(()) + } +} + +impl InvalidOptionsError { + pub fn single(err: CLIError, exit_code: i32) -> InvalidOptionsError { + InvalidOptionsError { + issues: vec![err], + exit_code: exit_code, + } + } + + pub fn new() -> InvalidOptionsError { + InvalidOptionsError { + issues: Vec::new(), + exit_code: 1, + } + } +} + +pub fn assure_config_dir_exists(dir: &str) -> Result { + let trdir = dir.trim(); + if trdir.len() == 0 { + return Err(CLIError::Configuration(ConfigurationError::DirectoryUnset)) + } + + let expanded_config_dir = + if trdir.as_bytes()[0] == b'~' { + match env::var("HOME").ok().or(env::var("UserProfile").ok()) { + None => return Err(CLIError::Configuration(ConfigurationError::HomeExpansionFailed(trdir.to_string()))), + Some(mut user) => { + user.push_str(&trdir[1..]); + user + } + } + } else { + trdir.to_string() + }; + + if let Err(err) = fs::create_dir(&expanded_config_dir) { + if err.kind() != io::ErrorKind::AlreadyExists { + return Err(CLIError::Configuration( + ConfigurationError::DirectoryCreationFailed((expanded_config_dir, err)))) + } + } + + Ok(expanded_config_dir) +} + +pub fn application_secret_from_directory(dir: &str, + secret_basename: &str, + json_app_secret: &str) + -> Result { + let secret_path = Path::new(dir).join(secret_basename); + let secret_str = || secret_path.as_path().to_str().unwrap().to_string(); + let secret_io_error = |io_err: io::Error| { + Err(CLIError::Configuration(ConfigurationError::IOError( + (secret_str(), io_err) + ))) + }; + + for _ in 0..2 { + match fs::File::open(&secret_path) { + Err(mut err) => { + if err.kind() == io::ErrorKind::NotFound { + // Write our built-in one - user may adjust the written file at will + + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_app_secret.as_bytes()) { + Err(io_err) => io_err, + Ok(_) => continue, + } + } + }; + // fall through to IO error handling + } + return secret_io_error(err) + }, + Ok(mut f) => { + let mut json_encoded_secret = String::new(); + if let Err(io_err) = f.read_to_string(&mut json_encoded_secret) { + return secret_io_error(io_err) + } + match json::decode::(&json_encoded_secret) { + Err(json_decode_error) => return Err(CLIError::Configuration( + ConfigurationError::Secret(ApplicationSecretError::DecoderError( + (secret_str(), json_decode_error) + )))), + Ok(console_secret) => match console_secret.installed { + Some(secret) => return Ok(secret), + None => return Err( + CLIError::Configuration( + ConfigurationError::Secret( + ApplicationSecretError::FormatError(secret_str()) + ))) + }, + } + } + } + } + unreachable!(); +} \ No newline at end of file diff --git a/gen/admin2_email_migration-cli/src/main.rs b/gen/admin2_email_migration-cli/src/main.rs new file mode 100644 index 0000000000..4fd3d63094 --- /dev/null +++ b/gen/admin2_email_migration-cli/src/main.rs @@ -0,0 +1,248 @@ +// DO NOT EDIT ! +// This file was generated automatically from 'src/mako/cli/main.rs.mako' +// DO NOT EDIT ! +#![feature(plugin, exit_status)] +#![plugin(docopt_macros)] +#![allow(unused_variables, unused_imports, dead_code, unused_mut)] + +extern crate docopt; +extern crate yup_oauth2 as oauth2; +extern crate yup_hyper_mock as mock; +extern crate rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_admin2_email_migration as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + admin2-email-migration [options] mail insert -r ... -u (simple|resumable) [-p ]... + admin2-email-migration --help + +All documentation details can be found TODO: + +Configuration: + --scope + 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. + --config-dir + 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] + --debug + Output all server communication to standard error. `tx` and `rx` are placed into + the same stream. + --debug-auth + Output all communication related to authentication to standard error. `tx` and `rx` are placed into + the same stream. +"); + +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}; + +use std::default::Default; +use std::str::FromStr; + +use oauth2::{Authenticator, DefaultAuthenticatorDelegate}; +use rustc_serialize::json; + +struct Engine { + opt: Options, + hub: api::Admin>, +} + + +impl Engine { + fn _mail_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request = api::MailItem::default(); + let mut call = self.hub.mail().insert(&request, &self.opt.arg_user_key); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "is-trash" => { + request.is_trash = Some(arg_from_str(value.unwrap_or("false"), err, "is-trash", "boolean")); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "labels" => { + if request.labels.is_none() { + request.labels = Some(Default::default()); + } + request.labels.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "is-draft" => { + request.is_draft = Some(arg_from_str(value.unwrap_or("false"), err, "is-draft", "boolean")); + }, + "is-inbox" => { + request.is_inbox = Some(arg_from_str(value.unwrap_or("false"), err, "is-inbox", "boolean")); + }, + "is-sent" => { + request.is_sent = Some(arg_from_str(value.unwrap_or("false"), err, "is-sent", "boolean")); + }, + "is-starred" => { + request.is_starred = Some(arg_from_str(value.unwrap_or("false"), err, "is-starred", "boolean")); + }, + "is-unread" => { + request.is_unread = Some(arg_from_str(value.unwrap_or("false"), err, "is-unread", "boolean")); + }, + "is-deleted" => { + request.is_deleted = Some(arg_from_str(value.unwrap_or("false"), err, "is-deleted", "boolean")); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = + if self.opt.cmd_simple { + "simple" + } else if self.opt.cmd_resumable { + "resumable" + } else { + unreachable!() + }; + let mut input_file = input_file_from_opts(&self.opt.arg_file, err); + let mime_type = input_mime_from_opts(&self.opt.arg_mime, err); + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "simple" => call.upload(input_file.unwrap(), mime_type.unwrap()), + "resumable" => call.upload_resumable(input_file.unwrap(), mime_type.unwrap()), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option, Option) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option; + let mut err_opt: Option = None; + + if self.opt.cmd_mail { + if self.opt.cmd_insert { + call_result = self._mail_insert(dry_run, &mut err); + } else { + unreachable!(); + } + } else { + unreachable!(); + } + + if dry_run { + if err.issues.len() > 0 { + err_opt = Some(err); + } + } + (call_result, err_opt) + } + + // Please note that this call will fail if any part of the opt can't be handled + fn new(opt: Options) -> Result { + let (config_dir, secret) = { + let config_dir = match cmn::assure_config_dir_exists(&opt.flag_config_dir) { + Err(e) => return Err(InvalidOptionsError::single(e, 3)), + Ok(p) => p, + }; + + match cmn::application_secret_from_directory(&config_dir, "admin2-email-migration-secret.json", + "{\"installed\":{\"auth_uri\":\"https://accounts.google.com/o/oauth2/auth\",\"client_secret\":\"hCsslbCUyfehWMmbkG8vTYxG\",\"token_uri\":\"https://accounts.google.com/o/oauth2/token\",\"client_email\":\"\",\"redirect_uris\":[\"urn:ietf:wg:oauth:2.0:oob\",\"oob\"],\"client_x509_cert_url\":\"\",\"client_id\":\"620010449518-9ngf7o4dhs0dka470npqvor6dc5lqb9b.apps.googleusercontent.com\",\"auth_provider_x509_cert_url\":\"https://www.googleapis.com/oauth2/v1/certs\"}}") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new( &secret, DefaultAuthenticatorDelegate, + if opt.flag_debug_auth { + hyper::Client::with_connector(mock::TeeConnector { + connector: hyper::net::HttpConnector(None) + }) + } else { + hyper::Client::new() + }, + JsonTokenStorage { + program_name: "admin2-email-migration", + db_dir: config_dir.clone(), + }, None); + + let client = + if opt.flag_debug { + hyper::Client::with_connector(mock::TeeConnector { + connector: hyper::net::HttpConnector(None) + }) + } else { + hyper::Client::new() + }; + let engine = Engine { + opt: opt, + hub: api::Admin::new(client, auth), + }; + + match engine._doit(true) { + (_, Some(err)) => Err(err), + _ => Ok(engine), + } + } + + // Execute the call with all the bells and whistles, informing the caller only if there was an error. + // The absense of one indicates success. + fn doit(&self) -> Option { + self._doit(false).0 + } +} + +fn main() { + let opts: Options = Options::docopt().decode().unwrap_or_else(|e| e.exit()); + match Engine::new(opts) { + Err(err) => { + writeln!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + writeln!(io::stderr(), "{:?}", err).ok(); + writeln!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/adsensehost4d1-cli/Cargo.toml b/gen/adsensehost4d1-cli/Cargo.toml new file mode 100644 index 0000000000..5a681acc51 --- /dev/null +++ b/gen/adsensehost4d1-cli/Cargo.toml @@ -0,0 +1,31 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-adsensehost4d1-cli" +version = "0.0.1+20150307" +authors = ["Sebastian Thiel "] +description = "A complete library to interact with AdSense Host (protocol v4.1)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/adsensehost4d1-cli" +homepage = "https://developers.google.com/adsense/host/" +documentation = "http://byron.github.io/google-apis-rs/google_adsensehost4d1_cli" +license = "MIT" +keywords = ["adsensehost", "google", "cli"] + +[[bin]] +name = "adsensehost4d1" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "*" +docopt_macros = "*" +rustc-serialize = "*" +yup-hyper-mock = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-adsensehost4d1] +path = "../adsensehost4d1" diff --git a/gen/adsensehost4d1-cli/LICENSE.md b/gen/adsensehost4d1-cli/LICENSE.md new file mode 100644 index 0000000000..ae22e6ec52 --- /dev/null +++ b/gen/adsensehost4d1-cli/LICENSE.md @@ -0,0 +1,30 @@ + +The MIT License (MIT) +===================== + +Copyright © `2015` `Sebastian Thiel` + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the “Software”), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. diff --git a/gen/adsensehost4d1-cli/README.md b/gen/adsensehost4d1-cli/README.md new file mode 100644 index 0000000000..cc58d0fdf2 --- /dev/null +++ b/gen/adsensehost4d1-cli/README.md @@ -0,0 +1,4 @@ +# HELLO ADSENSEHOST:V4.1 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/adsensehost4d1-cli/mkdocs.yml b/gen/adsensehost4d1-cli/mkdocs.yml new file mode 100644 index 0000000000..d9d584d6d6 --- /dev/null +++ b/gen/adsensehost4d1-cli/mkdocs.yml @@ -0,0 +1,42 @@ +site_name: AdSense Host v0.0.1+20150307 +site_url: http://byron.github.io/google-apis-rs/google-adsensehost4d1-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/adsensehost4d1-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['accounts_adclients-get.md', 'Accounts', 'Adclients Get'] +- ['accounts_adclients-list.md', 'Accounts', 'Adclients List'] +- ['accounts_adunits-delete.md', 'Accounts', 'Adunits Delete'] +- ['accounts_adunits-get.md', 'Accounts', 'Adunits Get'] +- ['accounts_adunits-get-ad-code.md', 'Accounts', 'Adunits Get Ad Code'] +- ['accounts_adunits-insert.md', 'Accounts', 'Adunits Insert'] +- ['accounts_adunits-list.md', 'Accounts', 'Adunits List'] +- ['accounts_adunits-patch.md', 'Accounts', 'Adunits Patch'] +- ['accounts_adunits-update.md', 'Accounts', 'Adunits Update'] +- ['accounts_get.md', 'Accounts', 'Get'] +- ['accounts_list.md', 'Accounts', 'List'] +- ['accounts_reports-generate.md', 'Accounts', 'Reports Generate'] +- ['adclients_get.md', 'Adclients', 'Get'] +- ['adclients_list.md', 'Adclients', 'List'] +- ['associationsessions_start.md', 'Associationsessions', 'Start'] +- ['associationsessions_verify.md', 'Associationsessions', 'Verify'] +- ['customchannels_delete.md', 'Customchannels', 'Delete'] +- ['customchannels_get.md', 'Customchannels', 'Get'] +- ['customchannels_insert.md', 'Customchannels', 'Insert'] +- ['customchannels_list.md', 'Customchannels', 'List'] +- ['customchannels_patch.md', 'Customchannels', 'Patch'] +- ['customchannels_update.md', 'Customchannels', 'Update'] +- ['reports_generate.md', 'Reports', 'Generate'] +- ['urlchannels_delete.md', 'Urlchannels', 'Delete'] +- ['urlchannels_insert.md', 'Urlchannels', 'Insert'] +- ['urlchannels_list.md', 'Urlchannels', 'List'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/adsensehost4d1-cli/src/cmn.rs b/gen/adsensehost4d1-cli/src/cmn.rs new file mode 100644 index 0000000000..a8d3f46368 --- /dev/null +++ b/gen/adsensehost4d1-cli/src/cmn.rs @@ -0,0 +1,454 @@ +// COPY OF 'src/rust/cli/cmn.rs' +// DO NOT EDIT +use oauth2::{ApplicationSecret, ConsoleApplicationSecret, TokenStorage, Token}; +use rustc_serialize::json; +use mime::Mime; + +use std::fs; +use std::env; +use std::io; +use std::fmt; +use std::path::{Path, PathBuf}; +use std::str::FromStr; +use std::string::ToString; +use std::io::{Write, Read, stdout}; + +use std::default::Default; + +const FIELD_SEP: char = '.'; + +#[derive(Clone, Default)] +pub struct FieldCursor(Vec); + +impl ToString for FieldCursor { + fn to_string(&self) -> String { + self.0.connect(".") + } +} + +impl FieldCursor { + pub fn set(&mut self, value: &str) -> Result<(), CLIError> { + if value.len() == 0 { + return Err(CLIError::Field(FieldError::Empty)) + } + + let mut first_is_field_sep = false; + let mut char_count: usize = 0; + let mut last_c = FIELD_SEP; + let mut num_conscutive_field_seps = 0; + + let mut field = String::new(); + let mut fields = self.0.clone(); + + let push_field = |fs: &mut Vec, f: &mut String| { + if f.len() > 0 { + fs.push(f.clone()); + f.truncate(0); + } + }; + + for (cid, c) in value.chars().enumerate() { + char_count += 1; + + if c == FIELD_SEP { + if cid == 0 { + first_is_field_sep = true; + } + num_conscutive_field_seps += 1; + if cid > 0 && last_c == FIELD_SEP { + if fields.pop().is_none() { + return Err(CLIError::Field(FieldError::PopOnEmpty(value.to_string()))) + } + } else { + push_field(&mut fields, &mut field); + } + } else { + num_conscutive_field_seps = 0; + if cid == 1 { + if first_is_field_sep { + fields.truncate(0); + } + } + field.push(c); + } + + last_c = c; + } + + push_field(&mut fields, &mut field); + + if char_count == 1 && first_is_field_sep { + fields.truncate(0); + } + if char_count > 1 && num_conscutive_field_seps == 1 { + return Err(CLIError::Field(FieldError::TrailingFieldSep(value.to_string()))) + } + + self.0 = fields; + Ok(()) + } + + pub fn num_fields(&self) -> usize { + self.0.len() + } +} + +pub fn parse_kv_arg<'a>(kv: &'a str, err: &mut InvalidOptionsError, for_hashmap: bool) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string(),for_hashmap)); + match kv.find('=') { + None => { + add_err(); + return (kv, None) + }, + Some(pos) => { + let key = &kv[..pos]; + if kv.len() <= pos + 1 { + add_err(); + return (key, None) + } + (key, Some(&kv[pos+1..])) + } + } +} + +pub fn input_file_from_opts(file_path: &str, err: &mut InvalidOptionsError) -> Option { + match fs::File::open(file_path) { + Ok(f) => Some(f), + Err(io_err) => { + err.issues.push(CLIError::Input(InputError::IOError((file_path.to_string(), io_err)))); + None + } + } +} + +pub fn input_mime_from_opts(mime: &str, err: &mut InvalidOptionsError) -> Option { + match mime.parse() { + Ok(m) => Some(m), + Err(_) => { + err.issues.push(CLIError::Input(InputError::Mime(mime.to_string()))); + None + } + } +} + +// May panic if we can't open the file - this is anticipated, we can't currently communicate this +// kind of error: TODO: fix this architecture :) +pub fn writer_from_opts(flag: bool, arg: &str) -> Box { + if !flag || arg == "-" { + Box::new(stdout()) + } else { + Box::new(fs::OpenOptions::new().create(true).write(true).open(arg).unwrap()) + } +} + + +pub fn arg_from_str(arg: &str, err: &mut InvalidOptionsError, + arg_name: &'static str, + arg_type: &'static str) -> T + where T: FromStr + Default, + ::Err: fmt::Display { + match FromStr::from_str(arg) { + Err(perr) => { + err.issues.push( + CLIError::ParseError((arg_name, arg_type, arg.to_string(), format!("{}", perr))) + ); + Default::default() + }, + Ok(v) => v, + } +} + +pub struct JsonTokenStorage { + pub program_name: &'static str, + pub db_dir: String, +} + +impl JsonTokenStorage { + fn path(&self, scope_hash: u64) -> PathBuf { + Path::new(&self.db_dir).join(&format!("{}-token-{}.json", self.program_name, scope_hash)) + } +} + +impl TokenStorage for JsonTokenStorage { + type Error = io::Error; + + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, _: &Vec<&str>, token: Option) -> Option { + match token { + None => { + match fs::remove_file(self.path(scope_hash)) { + Err(err) => + match err.kind() { + io::ErrorKind::NotFound => None, + _ => Some(err) + }, + Ok(_) => None + } + } + Some(token) => { + let json_token = json::encode(&token).unwrap(); + match fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)) { + Ok(mut f) => { + match f.write(json_token.as_bytes()) { + Ok(_) => None, + Err(io_err) => Some(io_err), + } + }, + Err(io_err) => Some(io_err) + } + } + } + } + + fn get(&self, scope_hash: u64, _: &Vec<&str>) -> Result, io::Error> { + match fs::File::open(&self.path(scope_hash)) { + Ok(mut f) => { + let mut json_string = String::new(); + match f.read_to_string(&mut json_string) { + Ok(_) => Ok(Some(json::decode::(&json_string).unwrap())), + Err(io_err) => Err(io_err), + } + }, + Err(io_err) => { + match io_err.kind() { + io::ErrorKind::NotFound => Ok(None), + _ => Err(io_err) + } + } + } + } +} + + +#[derive(Debug)] +pub enum ApplicationSecretError { + DecoderError((String, json::DecoderError)), + FormatError(String), +} + +impl fmt::Display for ApplicationSecretError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + match *self { + ApplicationSecretError::DecoderError((ref path, ref err)) + => writeln!(f, "Could not decode file at '{}' with error: {}", + path, err), + ApplicationSecretError::FormatError(ref path) + => writeln!(f, "'installed' field is unset in secret file at '{}'", + path), + } + } +} + +#[derive(Debug)] +pub enum ConfigurationError { + DirectoryCreationFailed((String, io::Error)), + DirectoryUnset, + HomeExpansionFailed(String), + Secret(ApplicationSecretError), + IOError((String, io::Error)), +} + +impl fmt::Display for ConfigurationError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + match *self { + ConfigurationError::DirectoryCreationFailed((ref dir, ref err)) + => writeln!(f, "Directory '{}' could not be created with error: {}", dir, err), + ConfigurationError::DirectoryUnset + => writeln!(f, "--config-dir was unset or empty"), + ConfigurationError::HomeExpansionFailed(ref dir) + => writeln!(f, "Couldn't find HOME directory of current user, failed to expand '{}'", dir), + ConfigurationError::Secret(ref err) + => writeln!(f, "Secret -> {}", err), + ConfigurationError::IOError((ref path, ref err)) + => writeln!(f, "IO operation failed on path '{}' with error: {}", path, err), + } + } +} + +#[derive(Debug)] +pub enum InputError { + IOError((String, io::Error)), + Mime(String), +} + +impl fmt::Display for InputError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + match *self { + InputError::IOError((ref file_path, ref io_err)) + => writeln!(f, "Failed to open '{}' for reading with error: {}", file_path, io_err), + InputError::Mime(ref mime) + => writeln!(f, "'{}' is not a known mime-type", mime), + } + } +} + +#[derive(Debug)] +pub enum FieldError { + PopOnEmpty(String), + TrailingFieldSep(String), + Unknown(String), + Empty, +} + + +impl fmt::Display for FieldError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + match *self { + FieldError::PopOnEmpty(ref field) + => writeln!(f, "'{}': Cannot move up on empty field cursor", field), + FieldError::TrailingFieldSep(ref field) + => writeln!(f, "'{}': Single field separator may not be last character", field), + FieldError::Unknown(ref field) + => writeln!(f, "Field '{}' does not exist", field), + FieldError::Empty + => writeln!(f, "Field names must not be empty"), + } + } +} + + +#[derive(Debug)] +pub enum CLIError { + Configuration(ConfigurationError), + ParseError((&'static str, &'static str, String, String)), + UnknownParameter(String), + InvalidKeyValueSyntax(String, bool), + Input(InputError), + Field(FieldError), +} + +impl fmt::Display for CLIError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + match *self { + CLIError::Configuration(ref err) => write!(f, "Configuration -> {}", err), + CLIError::Input(ref err) => write!(f, "Input -> {}", err), + CLIError::Field(ref err) => write!(f, "Field -> {}", err), + CLIError::ParseError((arg_name, 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) + => writeln!(f, "Parameter '{}' is unknown.", param_name), + CLIError::InvalidKeyValueSyntax(ref kv, is_hashmap) => { + let hashmap_info = if is_hashmap { "hashmap " } else { "" }; + writeln!(f, "'{}' does not match {}pattern =", kv, hashmap_info) + }, + } + } +} + +#[derive(Debug)] +pub struct InvalidOptionsError { + pub issues: Vec, + pub exit_code: i32, +} + +impl fmt::Display for InvalidOptionsError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + for issue in &self.issues { + try!(issue.fmt(f)); + } + Ok(()) + } +} + +impl InvalidOptionsError { + pub fn single(err: CLIError, exit_code: i32) -> InvalidOptionsError { + InvalidOptionsError { + issues: vec![err], + exit_code: exit_code, + } + } + + pub fn new() -> InvalidOptionsError { + InvalidOptionsError { + issues: Vec::new(), + exit_code: 1, + } + } +} + +pub fn assure_config_dir_exists(dir: &str) -> Result { + let trdir = dir.trim(); + if trdir.len() == 0 { + return Err(CLIError::Configuration(ConfigurationError::DirectoryUnset)) + } + + let expanded_config_dir = + if trdir.as_bytes()[0] == b'~' { + match env::var("HOME").ok().or(env::var("UserProfile").ok()) { + None => return Err(CLIError::Configuration(ConfigurationError::HomeExpansionFailed(trdir.to_string()))), + Some(mut user) => { + user.push_str(&trdir[1..]); + user + } + } + } else { + trdir.to_string() + }; + + if let Err(err) = fs::create_dir(&expanded_config_dir) { + if err.kind() != io::ErrorKind::AlreadyExists { + return Err(CLIError::Configuration( + ConfigurationError::DirectoryCreationFailed((expanded_config_dir, err)))) + } + } + + Ok(expanded_config_dir) +} + +pub fn application_secret_from_directory(dir: &str, + secret_basename: &str, + json_app_secret: &str) + -> Result { + let secret_path = Path::new(dir).join(secret_basename); + let secret_str = || secret_path.as_path().to_str().unwrap().to_string(); + let secret_io_error = |io_err: io::Error| { + Err(CLIError::Configuration(ConfigurationError::IOError( + (secret_str(), io_err) + ))) + }; + + for _ in 0..2 { + match fs::File::open(&secret_path) { + Err(mut err) => { + if err.kind() == io::ErrorKind::NotFound { + // Write our built-in one - user may adjust the written file at will + + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_app_secret.as_bytes()) { + Err(io_err) => io_err, + Ok(_) => continue, + } + } + }; + // fall through to IO error handling + } + return secret_io_error(err) + }, + Ok(mut f) => { + let mut json_encoded_secret = String::new(); + if let Err(io_err) = f.read_to_string(&mut json_encoded_secret) { + return secret_io_error(io_err) + } + match json::decode::(&json_encoded_secret) { + Err(json_decode_error) => return Err(CLIError::Configuration( + ConfigurationError::Secret(ApplicationSecretError::DecoderError( + (secret_str(), json_decode_error) + )))), + Ok(console_secret) => match console_secret.installed { + Some(secret) => return Ok(secret), + None => return Err( + CLIError::Configuration( + ConfigurationError::Secret( + ApplicationSecretError::FormatError(secret_str()) + ))) + }, + } + } + } + } + unreachable!(); +} \ No newline at end of file diff --git a/gen/adsensehost4d1-cli/src/main.rs b/gen/adsensehost4d1-cli/src/main.rs new file mode 100644 index 0000000000..4ec6a5dfc3 --- /dev/null +++ b/gen/adsensehost4d1-cli/src/main.rs @@ -0,0 +1,1979 @@ +// DO NOT EDIT ! +// This file was generated automatically from 'src/mako/cli/main.rs.mako' +// DO NOT EDIT ! +#![feature(plugin, exit_status)] +#![plugin(docopt_macros)] +#![allow(unused_variables, unused_imports, dead_code, unused_mut)] + +extern crate docopt; +extern crate yup_oauth2 as oauth2; +extern crate yup_hyper_mock as mock; +extern crate rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_adsensehost4d1 as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + adsensehost4d1 [options] accounts adclients-get [-p ]... [-o ] + adsensehost4d1 [options] accounts adclients-list [-p ]... [-o ] + adsensehost4d1 [options] accounts adunits-delete [-p ]... [-o ] + adsensehost4d1 [options] accounts adunits-get [-p ]... [-o ] + adsensehost4d1 [options] accounts adunits-get-ad-code [-p ]... [-o ] + adsensehost4d1 [options] accounts adunits-insert -r ... [-p ]... [-o ] + adsensehost4d1 [options] accounts adunits-list [-p ]... [-o ] + adsensehost4d1 [options] accounts adunits-patch -r ... [-p ]... [-o ] + adsensehost4d1 [options] accounts adunits-update -r ... [-p ]... [-o ] + adsensehost4d1 [options] accounts get [-p ]... [-o ] + adsensehost4d1 [options] accounts list ... [-p ]... [-o ] + adsensehost4d1 [options] accounts reports-generate [-p ]... [-o ] + adsensehost4d1 [options] adclients get [-p ]... [-o ] + adsensehost4d1 [options] adclients list [-p ]... [-o ] + adsensehost4d1 [options] associationsessions start ... [-p ]... [-o ] + adsensehost4d1 [options] associationsessions verify [-p ]... [-o ] + adsensehost4d1 [options] customchannels delete [-p ]... [-o ] + adsensehost4d1 [options] customchannels get [-p ]... [-o ] + adsensehost4d1 [options] customchannels insert -r ... [-p ]... [-o ] + adsensehost4d1 [options] customchannels list [-p ]... [-o ] + adsensehost4d1 [options] customchannels patch -r ... [-p ]... [-o ] + adsensehost4d1 [options] customchannels update -r ... [-p ]... [-o ] + adsensehost4d1 [options] reports generate [-p ]... [-o ] + adsensehost4d1 [options] urlchannels delete [-p ]... [-o ] + adsensehost4d1 [options] urlchannels insert -r ... [-p ]... [-o ] + adsensehost4d1 [options] urlchannels list [-p ]... [-o ] + adsensehost4d1 --help + +All documentation details can be found TODO: + +Configuration: + --scope + 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. + --config-dir + 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] + --debug + Output all server communication to standard error. `tx` and `rx` are placed into + the same stream. + --debug-auth + Output all communication related to authentication to standard error. `tx` and `rx` are placed into + the same stream. +"); + +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}; + +use std::default::Default; +use std::str::FromStr; + +use oauth2::{Authenticator, DefaultAuthenticatorDelegate}; +use rustc_serialize::json; + +struct Engine { + opt: Options, + hub: api::AdSenseHost>, +} + + +impl Engine { + fn _accounts_adclients_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.accounts().adclients_get(&self.opt.arg_account_id, &self.opt.arg_ad_client_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_adclients_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.accounts().adclients_list(&self.opt.arg_account_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_adunits_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.accounts().adunits_delete(&self.opt.arg_account_id, &self.opt.arg_ad_client_id, &self.opt.arg_ad_unit_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_adunits_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.accounts().adunits_get(&self.opt.arg_account_id, &self.opt.arg_ad_client_id, &self.opt.arg_ad_unit_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_adunits_get_ad_code(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.accounts().adunits_get_ad_code(&self.opt.arg_account_id, &self.opt.arg_ad_client_id, &self.opt.arg_ad_unit_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "host-custom-channel-id" => { + call = call.add_host_custom_channel_id(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_adunits_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request = api::AdUnit::default(); + let mut call = self.hub.accounts().adunits_insert(&request, &self.opt.arg_account_id, &self.opt.arg_ad_client_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_content_ads_settings_backup_option_init(request: &mut api::AdUnit) { + request_content_ads_settings_init(request); + if request.content_ads_settings.as_mut().unwrap().backup_option.is_none() { + request.content_ads_settings.as_mut().unwrap().backup_option = Some(Default::default()); + } + } + + fn request_content_ads_settings_init(request: &mut api::AdUnit) { + if request.content_ads_settings.is_none() { + request.content_ads_settings = Some(Default::default()); + } + } + + fn request_custom_style_colors_init(request: &mut api::AdUnit) { + request_custom_style_init(request); + if request.custom_style.as_mut().unwrap().colors.is_none() { + request.custom_style.as_mut().unwrap().colors = Some(Default::default()); + } + } + + fn request_custom_style_font_init(request: &mut api::AdUnit) { + request_custom_style_init(request); + if request.custom_style.as_mut().unwrap().font.is_none() { + request.custom_style.as_mut().unwrap().font = Some(Default::default()); + } + } + + fn request_custom_style_init(request: &mut api::AdUnit) { + if request.custom_style.is_none() { + request.custom_style = Some(Default::default()); + } + } + + fn request_mobile_content_ads_settings_init(request: &mut api::AdUnit) { + if request.mobile_content_ads_settings.is_none() { + request.mobile_content_ads_settings = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "status" => { + request.status = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "code" => { + request.code = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "content-ads-settings.type" => { + request_content_ads_settings_init(&mut request); + request.content_ads_settings.as_mut().unwrap().type_ = Some(value.unwrap_or("").to_string()); + }, + "content-ads-settings.backup-option.color" => { + request_content_ads_settings_backup_option_init(&mut request); + request.content_ads_settings.as_mut().unwrap().backup_option.as_mut().unwrap().color = Some(value.unwrap_or("").to_string()); + }, + "content-ads-settings.backup-option.url" => { + request_content_ads_settings_backup_option_init(&mut request); + request.content_ads_settings.as_mut().unwrap().backup_option.as_mut().unwrap().url = Some(value.unwrap_or("").to_string()); + }, + "content-ads-settings.backup-option.type" => { + request_content_ads_settings_backup_option_init(&mut request); + request.content_ads_settings.as_mut().unwrap().backup_option.as_mut().unwrap().type_ = Some(value.unwrap_or("").to_string()); + }, + "content-ads-settings.size" => { + request_content_ads_settings_backup_option_init(&mut request); + request.content_ads_settings.as_mut().unwrap().size = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_content_ads_settings_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "mobile-content-ads-settings.scripting-language" => { + request_mobile_content_ads_settings_init(&mut request); + request.mobile_content_ads_settings.as_mut().unwrap().scripting_language = Some(value.unwrap_or("").to_string()); + }, + "mobile-content-ads-settings.type" => { + request_mobile_content_ads_settings_init(&mut request); + request.mobile_content_ads_settings.as_mut().unwrap().type_ = Some(value.unwrap_or("").to_string()); + }, + "mobile-content-ads-settings.markup-language" => { + request_mobile_content_ads_settings_init(&mut request); + request.mobile_content_ads_settings.as_mut().unwrap().markup_language = Some(value.unwrap_or("").to_string()); + }, + "mobile-content-ads-settings.size" => { + request_mobile_content_ads_settings_init(&mut request); + request.mobile_content_ads_settings.as_mut().unwrap().size = Some(value.unwrap_or("").to_string()); + }, + "custom-style.corners" => { + request_custom_style_init(&mut request); + request.custom_style.as_mut().unwrap().corners = Some(value.unwrap_or("").to_string()); + }, + "custom-style.colors.url" => { + request_custom_style_colors_init(&mut request); + request.custom_style.as_mut().unwrap().colors.as_mut().unwrap().url = Some(value.unwrap_or("").to_string()); + }, + "custom-style.colors.text" => { + request_custom_style_colors_init(&mut request); + request.custom_style.as_mut().unwrap().colors.as_mut().unwrap().text = Some(value.unwrap_or("").to_string()); + }, + "custom-style.colors.border" => { + request_custom_style_colors_init(&mut request); + request.custom_style.as_mut().unwrap().colors.as_mut().unwrap().border = Some(value.unwrap_or("").to_string()); + }, + "custom-style.colors.background" => { + request_custom_style_colors_init(&mut request); + request.custom_style.as_mut().unwrap().colors.as_mut().unwrap().background = Some(value.unwrap_or("").to_string()); + }, + "custom-style.colors.title" => { + request_custom_style_colors_init(&mut request); + request.custom_style.as_mut().unwrap().colors.as_mut().unwrap().title = Some(value.unwrap_or("").to_string()); + }, + "custom-style.font.family" => { + request_custom_style_font_init(&mut request); + request.custom_style.as_mut().unwrap().font.as_mut().unwrap().family = Some(value.unwrap_or("").to_string()); + }, + "custom-style.font.size" => { + request_custom_style_font_init(&mut request); + request.custom_style.as_mut().unwrap().font.as_mut().unwrap().size = Some(value.unwrap_or("").to_string()); + }, + "custom-style.kind" => { + request_custom_style_font_init(&mut request); + request.custom_style.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_adunits_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.accounts().adunits_list(&self.opt.arg_account_id, &self.opt.arg_ad_client_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "include-inactive" => { + call = call.include_inactive(arg_from_str(value.unwrap_or("false"), err, "include-inactive", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_adunits_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request = api::AdUnit::default(); + let mut call = self.hub.accounts().adunits_patch(&request, &self.opt.arg_account_id, &self.opt.arg_ad_client_id, &self.opt.arg_ad_unit_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_content_ads_settings_backup_option_init(request: &mut api::AdUnit) { + request_content_ads_settings_init(request); + if request.content_ads_settings.as_mut().unwrap().backup_option.is_none() { + request.content_ads_settings.as_mut().unwrap().backup_option = Some(Default::default()); + } + } + + fn request_content_ads_settings_init(request: &mut api::AdUnit) { + if request.content_ads_settings.is_none() { + request.content_ads_settings = Some(Default::default()); + } + } + + fn request_custom_style_colors_init(request: &mut api::AdUnit) { + request_custom_style_init(request); + if request.custom_style.as_mut().unwrap().colors.is_none() { + request.custom_style.as_mut().unwrap().colors = Some(Default::default()); + } + } + + fn request_custom_style_font_init(request: &mut api::AdUnit) { + request_custom_style_init(request); + if request.custom_style.as_mut().unwrap().font.is_none() { + request.custom_style.as_mut().unwrap().font = Some(Default::default()); + } + } + + fn request_custom_style_init(request: &mut api::AdUnit) { + if request.custom_style.is_none() { + request.custom_style = Some(Default::default()); + } + } + + fn request_mobile_content_ads_settings_init(request: &mut api::AdUnit) { + if request.mobile_content_ads_settings.is_none() { + request.mobile_content_ads_settings = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "status" => { + request.status = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "code" => { + request.code = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "content-ads-settings.type" => { + request_content_ads_settings_init(&mut request); + request.content_ads_settings.as_mut().unwrap().type_ = Some(value.unwrap_or("").to_string()); + }, + "content-ads-settings.backup-option.color" => { + request_content_ads_settings_backup_option_init(&mut request); + request.content_ads_settings.as_mut().unwrap().backup_option.as_mut().unwrap().color = Some(value.unwrap_or("").to_string()); + }, + "content-ads-settings.backup-option.url" => { + request_content_ads_settings_backup_option_init(&mut request); + request.content_ads_settings.as_mut().unwrap().backup_option.as_mut().unwrap().url = Some(value.unwrap_or("").to_string()); + }, + "content-ads-settings.backup-option.type" => { + request_content_ads_settings_backup_option_init(&mut request); + request.content_ads_settings.as_mut().unwrap().backup_option.as_mut().unwrap().type_ = Some(value.unwrap_or("").to_string()); + }, + "content-ads-settings.size" => { + request_content_ads_settings_backup_option_init(&mut request); + request.content_ads_settings.as_mut().unwrap().size = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_content_ads_settings_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "mobile-content-ads-settings.scripting-language" => { + request_mobile_content_ads_settings_init(&mut request); + request.mobile_content_ads_settings.as_mut().unwrap().scripting_language = Some(value.unwrap_or("").to_string()); + }, + "mobile-content-ads-settings.type" => { + request_mobile_content_ads_settings_init(&mut request); + request.mobile_content_ads_settings.as_mut().unwrap().type_ = Some(value.unwrap_or("").to_string()); + }, + "mobile-content-ads-settings.markup-language" => { + request_mobile_content_ads_settings_init(&mut request); + request.mobile_content_ads_settings.as_mut().unwrap().markup_language = Some(value.unwrap_or("").to_string()); + }, + "mobile-content-ads-settings.size" => { + request_mobile_content_ads_settings_init(&mut request); + request.mobile_content_ads_settings.as_mut().unwrap().size = Some(value.unwrap_or("").to_string()); + }, + "custom-style.corners" => { + request_custom_style_init(&mut request); + request.custom_style.as_mut().unwrap().corners = Some(value.unwrap_or("").to_string()); + }, + "custom-style.colors.url" => { + request_custom_style_colors_init(&mut request); + request.custom_style.as_mut().unwrap().colors.as_mut().unwrap().url = Some(value.unwrap_or("").to_string()); + }, + "custom-style.colors.text" => { + request_custom_style_colors_init(&mut request); + request.custom_style.as_mut().unwrap().colors.as_mut().unwrap().text = Some(value.unwrap_or("").to_string()); + }, + "custom-style.colors.border" => { + request_custom_style_colors_init(&mut request); + request.custom_style.as_mut().unwrap().colors.as_mut().unwrap().border = Some(value.unwrap_or("").to_string()); + }, + "custom-style.colors.background" => { + request_custom_style_colors_init(&mut request); + request.custom_style.as_mut().unwrap().colors.as_mut().unwrap().background = Some(value.unwrap_or("").to_string()); + }, + "custom-style.colors.title" => { + request_custom_style_colors_init(&mut request); + request.custom_style.as_mut().unwrap().colors.as_mut().unwrap().title = Some(value.unwrap_or("").to_string()); + }, + "custom-style.font.family" => { + request_custom_style_font_init(&mut request); + request.custom_style.as_mut().unwrap().font.as_mut().unwrap().family = Some(value.unwrap_or("").to_string()); + }, + "custom-style.font.size" => { + request_custom_style_font_init(&mut request); + request.custom_style.as_mut().unwrap().font.as_mut().unwrap().size = Some(value.unwrap_or("").to_string()); + }, + "custom-style.kind" => { + request_custom_style_font_init(&mut request); + request.custom_style.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_adunits_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request = api::AdUnit::default(); + let mut call = self.hub.accounts().adunits_update(&request, &self.opt.arg_account_id, &self.opt.arg_ad_client_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_content_ads_settings_backup_option_init(request: &mut api::AdUnit) { + request_content_ads_settings_init(request); + if request.content_ads_settings.as_mut().unwrap().backup_option.is_none() { + request.content_ads_settings.as_mut().unwrap().backup_option = Some(Default::default()); + } + } + + fn request_content_ads_settings_init(request: &mut api::AdUnit) { + if request.content_ads_settings.is_none() { + request.content_ads_settings = Some(Default::default()); + } + } + + fn request_custom_style_colors_init(request: &mut api::AdUnit) { + request_custom_style_init(request); + if request.custom_style.as_mut().unwrap().colors.is_none() { + request.custom_style.as_mut().unwrap().colors = Some(Default::default()); + } + } + + fn request_custom_style_font_init(request: &mut api::AdUnit) { + request_custom_style_init(request); + if request.custom_style.as_mut().unwrap().font.is_none() { + request.custom_style.as_mut().unwrap().font = Some(Default::default()); + } + } + + fn request_custom_style_init(request: &mut api::AdUnit) { + if request.custom_style.is_none() { + request.custom_style = Some(Default::default()); + } + } + + fn request_mobile_content_ads_settings_init(request: &mut api::AdUnit) { + if request.mobile_content_ads_settings.is_none() { + request.mobile_content_ads_settings = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "status" => { + request.status = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "code" => { + request.code = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "content-ads-settings.type" => { + request_content_ads_settings_init(&mut request); + request.content_ads_settings.as_mut().unwrap().type_ = Some(value.unwrap_or("").to_string()); + }, + "content-ads-settings.backup-option.color" => { + request_content_ads_settings_backup_option_init(&mut request); + request.content_ads_settings.as_mut().unwrap().backup_option.as_mut().unwrap().color = Some(value.unwrap_or("").to_string()); + }, + "content-ads-settings.backup-option.url" => { + request_content_ads_settings_backup_option_init(&mut request); + request.content_ads_settings.as_mut().unwrap().backup_option.as_mut().unwrap().url = Some(value.unwrap_or("").to_string()); + }, + "content-ads-settings.backup-option.type" => { + request_content_ads_settings_backup_option_init(&mut request); + request.content_ads_settings.as_mut().unwrap().backup_option.as_mut().unwrap().type_ = Some(value.unwrap_or("").to_string()); + }, + "content-ads-settings.size" => { + request_content_ads_settings_backup_option_init(&mut request); + request.content_ads_settings.as_mut().unwrap().size = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_content_ads_settings_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "mobile-content-ads-settings.scripting-language" => { + request_mobile_content_ads_settings_init(&mut request); + request.mobile_content_ads_settings.as_mut().unwrap().scripting_language = Some(value.unwrap_or("").to_string()); + }, + "mobile-content-ads-settings.type" => { + request_mobile_content_ads_settings_init(&mut request); + request.mobile_content_ads_settings.as_mut().unwrap().type_ = Some(value.unwrap_or("").to_string()); + }, + "mobile-content-ads-settings.markup-language" => { + request_mobile_content_ads_settings_init(&mut request); + request.mobile_content_ads_settings.as_mut().unwrap().markup_language = Some(value.unwrap_or("").to_string()); + }, + "mobile-content-ads-settings.size" => { + request_mobile_content_ads_settings_init(&mut request); + request.mobile_content_ads_settings.as_mut().unwrap().size = Some(value.unwrap_or("").to_string()); + }, + "custom-style.corners" => { + request_custom_style_init(&mut request); + request.custom_style.as_mut().unwrap().corners = Some(value.unwrap_or("").to_string()); + }, + "custom-style.colors.url" => { + request_custom_style_colors_init(&mut request); + request.custom_style.as_mut().unwrap().colors.as_mut().unwrap().url = Some(value.unwrap_or("").to_string()); + }, + "custom-style.colors.text" => { + request_custom_style_colors_init(&mut request); + request.custom_style.as_mut().unwrap().colors.as_mut().unwrap().text = Some(value.unwrap_or("").to_string()); + }, + "custom-style.colors.border" => { + request_custom_style_colors_init(&mut request); + request.custom_style.as_mut().unwrap().colors.as_mut().unwrap().border = Some(value.unwrap_or("").to_string()); + }, + "custom-style.colors.background" => { + request_custom_style_colors_init(&mut request); + request.custom_style.as_mut().unwrap().colors.as_mut().unwrap().background = Some(value.unwrap_or("").to_string()); + }, + "custom-style.colors.title" => { + request_custom_style_colors_init(&mut request); + request.custom_style.as_mut().unwrap().colors.as_mut().unwrap().title = Some(value.unwrap_or("").to_string()); + }, + "custom-style.font.family" => { + request_custom_style_font_init(&mut request); + request.custom_style.as_mut().unwrap().font.as_mut().unwrap().family = Some(value.unwrap_or("").to_string()); + }, + "custom-style.font.size" => { + request_custom_style_font_init(&mut request); + request.custom_style.as_mut().unwrap().font.as_mut().unwrap().size = Some(value.unwrap_or("").to_string()); + }, + "custom-style.kind" => { + request_custom_style_font_init(&mut request); + request.custom_style.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.accounts().get(&self.opt.arg_account_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.accounts().list(&self.opt.arg_filter_ad_client_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_reports_generate(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.accounts().reports_generate(&self.opt.arg_account_id, &self.opt.arg_start_date, &self.opt.arg_end_date); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "start-index" => { + call = call.start_index(arg_from_str(value.unwrap_or("-0"), err, "start-index", "integer")); + }, + "sort" => { + call = call.add_sort(value.unwrap_or("")); + }, + "metric" => { + call = call.add_metric(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "locale" => { + call = call.locale(value.unwrap_or("")); + }, + "filter" => { + call = call.add_filter(value.unwrap_or("")); + }, + "dimension" => { + call = call.add_dimension(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _adclients_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.adclients().get(&self.opt.arg_ad_client_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _adclients_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.adclients().list(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _associationsessions_start(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.associationsessions().start(&self.opt.arg_product_code, &self.opt.arg_website_url); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "website-locale" => { + call = call.website_locale(value.unwrap_or("")); + }, + "user-locale" => { + call = call.user_locale(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _associationsessions_verify(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.associationsessions().verify(&self.opt.arg_token); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _customchannels_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.customchannels().delete(&self.opt.arg_ad_client_id, &self.opt.arg_custom_channel_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _customchannels_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.customchannels().get(&self.opt.arg_ad_client_id, &self.opt.arg_custom_channel_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _customchannels_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request = api::CustomChannel::default(); + let mut call = self.hub.customchannels().insert(&request, &self.opt.arg_ad_client_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "code" => { + request.code = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _customchannels_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.customchannels().list(&self.opt.arg_ad_client_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _customchannels_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request = api::CustomChannel::default(); + let mut call = self.hub.customchannels().patch(&request, &self.opt.arg_ad_client_id, &self.opt.arg_custom_channel_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "code" => { + request.code = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _customchannels_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request = api::CustomChannel::default(); + let mut call = self.hub.customchannels().update(&request, &self.opt.arg_ad_client_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "code" => { + request.code = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _reports_generate(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.reports().generate(&self.opt.arg_start_date, &self.opt.arg_end_date); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "start-index" => { + call = call.start_index(arg_from_str(value.unwrap_or("-0"), err, "start-index", "integer")); + }, + "sort" => { + call = call.add_sort(value.unwrap_or("")); + }, + "metric" => { + call = call.add_metric(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "locale" => { + call = call.locale(value.unwrap_or("")); + }, + "filter" => { + call = call.add_filter(value.unwrap_or("")); + }, + "dimension" => { + call = call.add_dimension(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _urlchannels_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.urlchannels().delete(&self.opt.arg_ad_client_id, &self.opt.arg_url_channel_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _urlchannels_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request = api::UrlChannel::default(); + let mut call = self.hub.urlchannels().insert(&request, &self.opt.arg_ad_client_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "url-pattern" => { + request.url_pattern = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _urlchannels_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.urlchannels().list(&self.opt.arg_ad_client_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option, Option) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option; + let mut err_opt: Option = None; + + if self.opt.cmd_accounts { + if self.opt.cmd_adclients_get { + call_result = self._accounts_adclients_get(dry_run, &mut err); + } else if self.opt.cmd_adclients_list { + call_result = self._accounts_adclients_list(dry_run, &mut err); + } else if self.opt.cmd_adunits_delete { + call_result = self._accounts_adunits_delete(dry_run, &mut err); + } else if self.opt.cmd_adunits_get { + call_result = self._accounts_adunits_get(dry_run, &mut err); + } else if self.opt.cmd_adunits_get_ad_code { + call_result = self._accounts_adunits_get_ad_code(dry_run, &mut err); + } else if self.opt.cmd_adunits_insert { + call_result = self._accounts_adunits_insert(dry_run, &mut err); + } else if self.opt.cmd_adunits_list { + call_result = self._accounts_adunits_list(dry_run, &mut err); + } else if self.opt.cmd_adunits_patch { + call_result = self._accounts_adunits_patch(dry_run, &mut err); + } else if self.opt.cmd_adunits_update { + call_result = self._accounts_adunits_update(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._accounts_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._accounts_list(dry_run, &mut err); + } else if self.opt.cmd_reports_generate { + call_result = self._accounts_reports_generate(dry_run, &mut err); + } else { + unreachable!(); + } + } + else if self.opt.cmd_adclients { + if self.opt.cmd_get { + call_result = self._adclients_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._adclients_list(dry_run, &mut err); + } else { + unreachable!(); + } + } + else if self.opt.cmd_associationsessions { + if self.opt.cmd_start { + call_result = self._associationsessions_start(dry_run, &mut err); + } else if self.opt.cmd_verify { + call_result = self._associationsessions_verify(dry_run, &mut err); + } else { + unreachable!(); + } + } + else if self.opt.cmd_customchannels { + if self.opt.cmd_delete { + call_result = self._customchannels_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._customchannels_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._customchannels_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._customchannels_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._customchannels_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._customchannels_update(dry_run, &mut err); + } else { + unreachable!(); + } + } + else if self.opt.cmd_reports { + if self.opt.cmd_generate { + call_result = self._reports_generate(dry_run, &mut err); + } else { + unreachable!(); + } + } + else if self.opt.cmd_urlchannels { + if self.opt.cmd_delete { + call_result = self._urlchannels_delete(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._urlchannels_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._urlchannels_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else { + unreachable!(); + } + + if dry_run { + if err.issues.len() > 0 { + err_opt = Some(err); + } + } + (call_result, err_opt) + } + + // Please note that this call will fail if any part of the opt can't be handled + fn new(opt: Options) -> Result { + let (config_dir, secret) = { + let config_dir = match cmn::assure_config_dir_exists(&opt.flag_config_dir) { + Err(e) => return Err(InvalidOptionsError::single(e, 3)), + Ok(p) => p, + }; + + match cmn::application_secret_from_directory(&config_dir, "adsensehost4d1-secret.json", + "{\"installed\":{\"auth_uri\":\"https://accounts.google.com/o/oauth2/auth\",\"client_secret\":\"hCsslbCUyfehWMmbkG8vTYxG\",\"token_uri\":\"https://accounts.google.com/o/oauth2/token\",\"client_email\":\"\",\"redirect_uris\":[\"urn:ietf:wg:oauth:2.0:oob\",\"oob\"],\"client_x509_cert_url\":\"\",\"client_id\":\"620010449518-9ngf7o4dhs0dka470npqvor6dc5lqb9b.apps.googleusercontent.com\",\"auth_provider_x509_cert_url\":\"https://www.googleapis.com/oauth2/v1/certs\"}}") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new( &secret, DefaultAuthenticatorDelegate, + if opt.flag_debug_auth { + hyper::Client::with_connector(mock::TeeConnector { + connector: hyper::net::HttpConnector(None) + }) + } else { + hyper::Client::new() + }, + JsonTokenStorage { + program_name: "adsensehost4d1", + db_dir: config_dir.clone(), + }, None); + + let client = + if opt.flag_debug { + hyper::Client::with_connector(mock::TeeConnector { + connector: hyper::net::HttpConnector(None) + }) + } else { + hyper::Client::new() + }; + let engine = Engine { + opt: opt, + hub: api::AdSenseHost::new(client, auth), + }; + + match engine._doit(true) { + (_, Some(err)) => Err(err), + _ => Ok(engine), + } + } + + // Execute the call with all the bells and whistles, informing the caller only if there was an error. + // The absense of one indicates success. + fn doit(&self) -> Option { + self._doit(false).0 + } +} + +fn main() { + let opts: Options = Options::docopt().decode().unwrap_or_else(|e| e.exit()); + match Engine::new(opts) { + Err(err) => { + writeln!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + writeln!(io::stderr(), "{:?}", err).ok(); + writeln!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/audit1-cli/Cargo.toml b/gen/audit1-cli/Cargo.toml new file mode 100644 index 0000000000..998720b3ca --- /dev/null +++ b/gen/audit1-cli/Cargo.toml @@ -0,0 +1,31 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-audit1-cli" +version = "0.0.1+20150419" +authors = ["Sebastian Thiel "] +description = "A complete library to interact with audit (protocol v1)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/audit1-cli" +homepage = "https://developers.google.com/google-apps/admin-audit/get_started" +documentation = "http://byron.github.io/google-apis-rs/google_audit1_cli" +license = "MIT" +keywords = ["audit", "google", "cli"] + +[[bin]] +name = "audit1" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "*" +docopt_macros = "*" +rustc-serialize = "*" +yup-hyper-mock = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-audit1] +path = "../audit1" diff --git a/gen/audit1-cli/LICENSE.md b/gen/audit1-cli/LICENSE.md new file mode 100644 index 0000000000..ae22e6ec52 --- /dev/null +++ b/gen/audit1-cli/LICENSE.md @@ -0,0 +1,30 @@ + +The MIT License (MIT) +===================== + +Copyright © `2015` `Sebastian Thiel` + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the “Software”), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. diff --git a/gen/audit1-cli/README.md b/gen/audit1-cli/README.md new file mode 100644 index 0000000000..a997937649 --- /dev/null +++ b/gen/audit1-cli/README.md @@ -0,0 +1,4 @@ +# HELLO AUDIT:V1 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/audit1-cli/mkdocs.yml b/gen/audit1-cli/mkdocs.yml new file mode 100644 index 0000000000..a73833f02c --- /dev/null +++ b/gen/audit1-cli/mkdocs.yml @@ -0,0 +1,17 @@ +site_name: audit v0.0.1+20150419 +site_url: http://byron.github.io/google-apis-rs/google-audit1-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/audit1-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['activities_list.md', 'Activities', 'List'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/audit1-cli/src/cmn.rs b/gen/audit1-cli/src/cmn.rs new file mode 100644 index 0000000000..a8d3f46368 --- /dev/null +++ b/gen/audit1-cli/src/cmn.rs @@ -0,0 +1,454 @@ +// COPY OF 'src/rust/cli/cmn.rs' +// DO NOT EDIT +use oauth2::{ApplicationSecret, ConsoleApplicationSecret, TokenStorage, Token}; +use rustc_serialize::json; +use mime::Mime; + +use std::fs; +use std::env; +use std::io; +use std::fmt; +use std::path::{Path, PathBuf}; +use std::str::FromStr; +use std::string::ToString; +use std::io::{Write, Read, stdout}; + +use std::default::Default; + +const FIELD_SEP: char = '.'; + +#[derive(Clone, Default)] +pub struct FieldCursor(Vec); + +impl ToString for FieldCursor { + fn to_string(&self) -> String { + self.0.connect(".") + } +} + +impl FieldCursor { + pub fn set(&mut self, value: &str) -> Result<(), CLIError> { + if value.len() == 0 { + return Err(CLIError::Field(FieldError::Empty)) + } + + let mut first_is_field_sep = false; + let mut char_count: usize = 0; + let mut last_c = FIELD_SEP; + let mut num_conscutive_field_seps = 0; + + let mut field = String::new(); + let mut fields = self.0.clone(); + + let push_field = |fs: &mut Vec, f: &mut String| { + if f.len() > 0 { + fs.push(f.clone()); + f.truncate(0); + } + }; + + for (cid, c) in value.chars().enumerate() { + char_count += 1; + + if c == FIELD_SEP { + if cid == 0 { + first_is_field_sep = true; + } + num_conscutive_field_seps += 1; + if cid > 0 && last_c == FIELD_SEP { + if fields.pop().is_none() { + return Err(CLIError::Field(FieldError::PopOnEmpty(value.to_string()))) + } + } else { + push_field(&mut fields, &mut field); + } + } else { + num_conscutive_field_seps = 0; + if cid == 1 { + if first_is_field_sep { + fields.truncate(0); + } + } + field.push(c); + } + + last_c = c; + } + + push_field(&mut fields, &mut field); + + if char_count == 1 && first_is_field_sep { + fields.truncate(0); + } + if char_count > 1 && num_conscutive_field_seps == 1 { + return Err(CLIError::Field(FieldError::TrailingFieldSep(value.to_string()))) + } + + self.0 = fields; + Ok(()) + } + + pub fn num_fields(&self) -> usize { + self.0.len() + } +} + +pub fn parse_kv_arg<'a>(kv: &'a str, err: &mut InvalidOptionsError, for_hashmap: bool) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string(),for_hashmap)); + match kv.find('=') { + None => { + add_err(); + return (kv, None) + }, + Some(pos) => { + let key = &kv[..pos]; + if kv.len() <= pos + 1 { + add_err(); + return (key, None) + } + (key, Some(&kv[pos+1..])) + } + } +} + +pub fn input_file_from_opts(file_path: &str, err: &mut InvalidOptionsError) -> Option { + match fs::File::open(file_path) { + Ok(f) => Some(f), + Err(io_err) => { + err.issues.push(CLIError::Input(InputError::IOError((file_path.to_string(), io_err)))); + None + } + } +} + +pub fn input_mime_from_opts(mime: &str, err: &mut InvalidOptionsError) -> Option { + match mime.parse() { + Ok(m) => Some(m), + Err(_) => { + err.issues.push(CLIError::Input(InputError::Mime(mime.to_string()))); + None + } + } +} + +// May panic if we can't open the file - this is anticipated, we can't currently communicate this +// kind of error: TODO: fix this architecture :) +pub fn writer_from_opts(flag: bool, arg: &str) -> Box { + if !flag || arg == "-" { + Box::new(stdout()) + } else { + Box::new(fs::OpenOptions::new().create(true).write(true).open(arg).unwrap()) + } +} + + +pub fn arg_from_str(arg: &str, err: &mut InvalidOptionsError, + arg_name: &'static str, + arg_type: &'static str) -> T + where T: FromStr + Default, + ::Err: fmt::Display { + match FromStr::from_str(arg) { + Err(perr) => { + err.issues.push( + CLIError::ParseError((arg_name, arg_type, arg.to_string(), format!("{}", perr))) + ); + Default::default() + }, + Ok(v) => v, + } +} + +pub struct JsonTokenStorage { + pub program_name: &'static str, + pub db_dir: String, +} + +impl JsonTokenStorage { + fn path(&self, scope_hash: u64) -> PathBuf { + Path::new(&self.db_dir).join(&format!("{}-token-{}.json", self.program_name, scope_hash)) + } +} + +impl TokenStorage for JsonTokenStorage { + type Error = io::Error; + + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, _: &Vec<&str>, token: Option) -> Option { + match token { + None => { + match fs::remove_file(self.path(scope_hash)) { + Err(err) => + match err.kind() { + io::ErrorKind::NotFound => None, + _ => Some(err) + }, + Ok(_) => None + } + } + Some(token) => { + let json_token = json::encode(&token).unwrap(); + match fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)) { + Ok(mut f) => { + match f.write(json_token.as_bytes()) { + Ok(_) => None, + Err(io_err) => Some(io_err), + } + }, + Err(io_err) => Some(io_err) + } + } + } + } + + fn get(&self, scope_hash: u64, _: &Vec<&str>) -> Result, io::Error> { + match fs::File::open(&self.path(scope_hash)) { + Ok(mut f) => { + let mut json_string = String::new(); + match f.read_to_string(&mut json_string) { + Ok(_) => Ok(Some(json::decode::(&json_string).unwrap())), + Err(io_err) => Err(io_err), + } + }, + Err(io_err) => { + match io_err.kind() { + io::ErrorKind::NotFound => Ok(None), + _ => Err(io_err) + } + } + } + } +} + + +#[derive(Debug)] +pub enum ApplicationSecretError { + DecoderError((String, json::DecoderError)), + FormatError(String), +} + +impl fmt::Display for ApplicationSecretError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + match *self { + ApplicationSecretError::DecoderError((ref path, ref err)) + => writeln!(f, "Could not decode file at '{}' with error: {}", + path, err), + ApplicationSecretError::FormatError(ref path) + => writeln!(f, "'installed' field is unset in secret file at '{}'", + path), + } + } +} + +#[derive(Debug)] +pub enum ConfigurationError { + DirectoryCreationFailed((String, io::Error)), + DirectoryUnset, + HomeExpansionFailed(String), + Secret(ApplicationSecretError), + IOError((String, io::Error)), +} + +impl fmt::Display for ConfigurationError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + match *self { + ConfigurationError::DirectoryCreationFailed((ref dir, ref err)) + => writeln!(f, "Directory '{}' could not be created with error: {}", dir, err), + ConfigurationError::DirectoryUnset + => writeln!(f, "--config-dir was unset or empty"), + ConfigurationError::HomeExpansionFailed(ref dir) + => writeln!(f, "Couldn't find HOME directory of current user, failed to expand '{}'", dir), + ConfigurationError::Secret(ref err) + => writeln!(f, "Secret -> {}", err), + ConfigurationError::IOError((ref path, ref err)) + => writeln!(f, "IO operation failed on path '{}' with error: {}", path, err), + } + } +} + +#[derive(Debug)] +pub enum InputError { + IOError((String, io::Error)), + Mime(String), +} + +impl fmt::Display for InputError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + match *self { + InputError::IOError((ref file_path, ref io_err)) + => writeln!(f, "Failed to open '{}' for reading with error: {}", file_path, io_err), + InputError::Mime(ref mime) + => writeln!(f, "'{}' is not a known mime-type", mime), + } + } +} + +#[derive(Debug)] +pub enum FieldError { + PopOnEmpty(String), + TrailingFieldSep(String), + Unknown(String), + Empty, +} + + +impl fmt::Display for FieldError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + match *self { + FieldError::PopOnEmpty(ref field) + => writeln!(f, "'{}': Cannot move up on empty field cursor", field), + FieldError::TrailingFieldSep(ref field) + => writeln!(f, "'{}': Single field separator may not be last character", field), + FieldError::Unknown(ref field) + => writeln!(f, "Field '{}' does not exist", field), + FieldError::Empty + => writeln!(f, "Field names must not be empty"), + } + } +} + + +#[derive(Debug)] +pub enum CLIError { + Configuration(ConfigurationError), + ParseError((&'static str, &'static str, String, String)), + UnknownParameter(String), + InvalidKeyValueSyntax(String, bool), + Input(InputError), + Field(FieldError), +} + +impl fmt::Display for CLIError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + match *self { + CLIError::Configuration(ref err) => write!(f, "Configuration -> {}", err), + CLIError::Input(ref err) => write!(f, "Input -> {}", err), + CLIError::Field(ref err) => write!(f, "Field -> {}", err), + CLIError::ParseError((arg_name, 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) + => writeln!(f, "Parameter '{}' is unknown.", param_name), + CLIError::InvalidKeyValueSyntax(ref kv, is_hashmap) => { + let hashmap_info = if is_hashmap { "hashmap " } else { "" }; + writeln!(f, "'{}' does not match {}pattern =", kv, hashmap_info) + }, + } + } +} + +#[derive(Debug)] +pub struct InvalidOptionsError { + pub issues: Vec, + pub exit_code: i32, +} + +impl fmt::Display for InvalidOptionsError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + for issue in &self.issues { + try!(issue.fmt(f)); + } + Ok(()) + } +} + +impl InvalidOptionsError { + pub fn single(err: CLIError, exit_code: i32) -> InvalidOptionsError { + InvalidOptionsError { + issues: vec![err], + exit_code: exit_code, + } + } + + pub fn new() -> InvalidOptionsError { + InvalidOptionsError { + issues: Vec::new(), + exit_code: 1, + } + } +} + +pub fn assure_config_dir_exists(dir: &str) -> Result { + let trdir = dir.trim(); + if trdir.len() == 0 { + return Err(CLIError::Configuration(ConfigurationError::DirectoryUnset)) + } + + let expanded_config_dir = + if trdir.as_bytes()[0] == b'~' { + match env::var("HOME").ok().or(env::var("UserProfile").ok()) { + None => return Err(CLIError::Configuration(ConfigurationError::HomeExpansionFailed(trdir.to_string()))), + Some(mut user) => { + user.push_str(&trdir[1..]); + user + } + } + } else { + trdir.to_string() + }; + + if let Err(err) = fs::create_dir(&expanded_config_dir) { + if err.kind() != io::ErrorKind::AlreadyExists { + return Err(CLIError::Configuration( + ConfigurationError::DirectoryCreationFailed((expanded_config_dir, err)))) + } + } + + Ok(expanded_config_dir) +} + +pub fn application_secret_from_directory(dir: &str, + secret_basename: &str, + json_app_secret: &str) + -> Result { + let secret_path = Path::new(dir).join(secret_basename); + let secret_str = || secret_path.as_path().to_str().unwrap().to_string(); + let secret_io_error = |io_err: io::Error| { + Err(CLIError::Configuration(ConfigurationError::IOError( + (secret_str(), io_err) + ))) + }; + + for _ in 0..2 { + match fs::File::open(&secret_path) { + Err(mut err) => { + if err.kind() == io::ErrorKind::NotFound { + // Write our built-in one - user may adjust the written file at will + + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_app_secret.as_bytes()) { + Err(io_err) => io_err, + Ok(_) => continue, + } + } + }; + // fall through to IO error handling + } + return secret_io_error(err) + }, + Ok(mut f) => { + let mut json_encoded_secret = String::new(); + if let Err(io_err) = f.read_to_string(&mut json_encoded_secret) { + return secret_io_error(io_err) + } + match json::decode::(&json_encoded_secret) { + Err(json_decode_error) => return Err(CLIError::Configuration( + ConfigurationError::Secret(ApplicationSecretError::DecoderError( + (secret_str(), json_decode_error) + )))), + Ok(console_secret) => match console_secret.installed { + Some(secret) => return Ok(secret), + None => return Err( + CLIError::Configuration( + ConfigurationError::Secret( + ApplicationSecretError::FormatError(secret_str()) + ))) + }, + } + } + } + } + unreachable!(); +} \ No newline at end of file diff --git a/gen/audit1-cli/src/main.rs b/gen/audit1-cli/src/main.rs new file mode 100644 index 0000000000..78a205fdf1 --- /dev/null +++ b/gen/audit1-cli/src/main.rs @@ -0,0 +1,219 @@ +// DO NOT EDIT ! +// This file was generated automatically from 'src/mako/cli/main.rs.mako' +// DO NOT EDIT ! +#![feature(plugin, exit_status)] +#![plugin(docopt_macros)] +#![allow(unused_variables, unused_imports, dead_code, unused_mut)] + +extern crate docopt; +extern crate yup_oauth2 as oauth2; +extern crate yup_hyper_mock as mock; +extern crate rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_audit1 as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + audit1 [options] activities list [-p ]... [-o ] + audit1 --help + +All documentation details can be found TODO: + +Configuration: + --config-dir + 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] + --debug + Output all server communication to standard error. `tx` and `rx` are placed into + the same stream. + --debug-auth + Output all communication related to authentication to standard error. `tx` and `rx` are placed into + the same stream. +"); + +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}; + +use std::default::Default; +use std::str::FromStr; + +use oauth2::{Authenticator, DefaultAuthenticatorDelegate}; +use rustc_serialize::json; + +struct Engine { + opt: Options, + hub: api::Audit>, +} + + +impl Engine { + fn _activities_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.activities().list(&self.opt.arg_customer_id, &self.opt.arg_application_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "start-time" => { + call = call.start_time(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "event-name" => { + call = call.event_name(value.unwrap_or("")); + }, + "end-time" => { + call = call.end_time(value.unwrap_or("")); + }, + "continuation-token" => { + call = call.continuation_token(value.unwrap_or("")); + }, + "caller" => { + call = call.caller(value.unwrap_or("")); + }, + "actor-ip-address" => { + call = call.actor_ip_address(value.unwrap_or("")); + }, + "actor-email" => { + call = call.actor_email(value.unwrap_or("")); + }, + "actor-application-id" => { + call = call.actor_application_id(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option, Option) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option; + let mut err_opt: Option = None; + + if self.opt.cmd_activities { + if self.opt.cmd_list { + call_result = self._activities_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else { + unreachable!(); + } + + if dry_run { + if err.issues.len() > 0 { + err_opt = Some(err); + } + } + (call_result, err_opt) + } + + // Please note that this call will fail if any part of the opt can't be handled + fn new(opt: Options) -> Result { + let (config_dir, secret) = { + let config_dir = match cmn::assure_config_dir_exists(&opt.flag_config_dir) { + Err(e) => return Err(InvalidOptionsError::single(e, 3)), + Ok(p) => p, + }; + + match cmn::application_secret_from_directory(&config_dir, "audit1-secret.json", + "{\"installed\":{\"auth_uri\":\"https://accounts.google.com/o/oauth2/auth\",\"client_secret\":\"hCsslbCUyfehWMmbkG8vTYxG\",\"token_uri\":\"https://accounts.google.com/o/oauth2/token\",\"client_email\":\"\",\"redirect_uris\":[\"urn:ietf:wg:oauth:2.0:oob\",\"oob\"],\"client_x509_cert_url\":\"\",\"client_id\":\"620010449518-9ngf7o4dhs0dka470npqvor6dc5lqb9b.apps.googleusercontent.com\",\"auth_provider_x509_cert_url\":\"https://www.googleapis.com/oauth2/v1/certs\"}}") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new( &secret, DefaultAuthenticatorDelegate, + if opt.flag_debug_auth { + hyper::Client::with_connector(mock::TeeConnector { + connector: hyper::net::HttpConnector(None) + }) + } else { + hyper::Client::new() + }, + JsonTokenStorage { + program_name: "audit1", + db_dir: config_dir.clone(), + }, None); + + let client = + if opt.flag_debug { + hyper::Client::with_connector(mock::TeeConnector { + connector: hyper::net::HttpConnector(None) + }) + } else { + hyper::Client::new() + }; + let engine = Engine { + opt: opt, + hub: api::Audit::new(client, auth), + }; + + match engine._doit(true) { + (_, Some(err)) => Err(err), + _ => Ok(engine), + } + } + + // Execute the call with all the bells and whistles, informing the caller only if there was an error. + // The absense of one indicates success. + fn doit(&self) -> Option { + self._doit(false).0 + } +} + +fn main() { + let opts: Options = Options::docopt().decode().unwrap_or_else(|e| e.exit()); + match Engine::new(opts) { + Err(err) => { + writeln!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + writeln!(io::stderr(), "{:?}", err).ok(); + writeln!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/coordinate1-cli/Cargo.toml b/gen/coordinate1-cli/Cargo.toml new file mode 100644 index 0000000000..0c83cc000b --- /dev/null +++ b/gen/coordinate1-cli/Cargo.toml @@ -0,0 +1,31 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-coordinate1-cli" +version = "0.0.1+20141215" +authors = ["Sebastian Thiel "] +description = "A complete library to interact with coordinate (protocol v1)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/coordinate1-cli" +homepage = "https://developers.google.com/coordinate/" +documentation = "http://byron.github.io/google-apis-rs/google_coordinate1_cli" +license = "MIT" +keywords = ["coordinate", "google", "cli"] + +[[bin]] +name = "coordinate1" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "*" +docopt_macros = "*" +rustc-serialize = "*" +yup-hyper-mock = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-coordinate1] +path = "../coordinate1" diff --git a/gen/coordinate1-cli/LICENSE.md b/gen/coordinate1-cli/LICENSE.md new file mode 100644 index 0000000000..ae22e6ec52 --- /dev/null +++ b/gen/coordinate1-cli/LICENSE.md @@ -0,0 +1,30 @@ + +The MIT License (MIT) +===================== + +Copyright © `2015` `Sebastian Thiel` + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the “Software”), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. diff --git a/gen/coordinate1-cli/README.md b/gen/coordinate1-cli/README.md new file mode 100644 index 0000000000..79383e596c --- /dev/null +++ b/gen/coordinate1-cli/README.md @@ -0,0 +1,4 @@ +# HELLO COORDINATE:V1 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/coordinate1-cli/mkdocs.yml b/gen/coordinate1-cli/mkdocs.yml new file mode 100644 index 0000000000..56fb9f231b --- /dev/null +++ b/gen/coordinate1-cli/mkdocs.yml @@ -0,0 +1,28 @@ +site_name: coordinate v0.0.1+20141215 +site_url: http://byron.github.io/google-apis-rs/google-coordinate1-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/coordinate1-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['custom-field-def_list.md', 'Custom Field Def', 'List'] +- ['jobs_get.md', 'Jobs', 'Get'] +- ['jobs_insert.md', 'Jobs', 'Insert'] +- ['jobs_list.md', 'Jobs', 'List'] +- ['jobs_patch.md', 'Jobs', 'Patch'] +- ['jobs_update.md', 'Jobs', 'Update'] +- ['location_list.md', 'Location', 'List'] +- ['schedule_get.md', 'Schedule', 'Get'] +- ['schedule_patch.md', 'Schedule', 'Patch'] +- ['schedule_update.md', 'Schedule', 'Update'] +- ['team_list.md', 'Team', 'List'] +- ['worker_list.md', 'Worker', 'List'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/coordinate1-cli/src/cmn.rs b/gen/coordinate1-cli/src/cmn.rs new file mode 100644 index 0000000000..a8d3f46368 --- /dev/null +++ b/gen/coordinate1-cli/src/cmn.rs @@ -0,0 +1,454 @@ +// COPY OF 'src/rust/cli/cmn.rs' +// DO NOT EDIT +use oauth2::{ApplicationSecret, ConsoleApplicationSecret, TokenStorage, Token}; +use rustc_serialize::json; +use mime::Mime; + +use std::fs; +use std::env; +use std::io; +use std::fmt; +use std::path::{Path, PathBuf}; +use std::str::FromStr; +use std::string::ToString; +use std::io::{Write, Read, stdout}; + +use std::default::Default; + +const FIELD_SEP: char = '.'; + +#[derive(Clone, Default)] +pub struct FieldCursor(Vec); + +impl ToString for FieldCursor { + fn to_string(&self) -> String { + self.0.connect(".") + } +} + +impl FieldCursor { + pub fn set(&mut self, value: &str) -> Result<(), CLIError> { + if value.len() == 0 { + return Err(CLIError::Field(FieldError::Empty)) + } + + let mut first_is_field_sep = false; + let mut char_count: usize = 0; + let mut last_c = FIELD_SEP; + let mut num_conscutive_field_seps = 0; + + let mut field = String::new(); + let mut fields = self.0.clone(); + + let push_field = |fs: &mut Vec, f: &mut String| { + if f.len() > 0 { + fs.push(f.clone()); + f.truncate(0); + } + }; + + for (cid, c) in value.chars().enumerate() { + char_count += 1; + + if c == FIELD_SEP { + if cid == 0 { + first_is_field_sep = true; + } + num_conscutive_field_seps += 1; + if cid > 0 && last_c == FIELD_SEP { + if fields.pop().is_none() { + return Err(CLIError::Field(FieldError::PopOnEmpty(value.to_string()))) + } + } else { + push_field(&mut fields, &mut field); + } + } else { + num_conscutive_field_seps = 0; + if cid == 1 { + if first_is_field_sep { + fields.truncate(0); + } + } + field.push(c); + } + + last_c = c; + } + + push_field(&mut fields, &mut field); + + if char_count == 1 && first_is_field_sep { + fields.truncate(0); + } + if char_count > 1 && num_conscutive_field_seps == 1 { + return Err(CLIError::Field(FieldError::TrailingFieldSep(value.to_string()))) + } + + self.0 = fields; + Ok(()) + } + + pub fn num_fields(&self) -> usize { + self.0.len() + } +} + +pub fn parse_kv_arg<'a>(kv: &'a str, err: &mut InvalidOptionsError, for_hashmap: bool) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string(),for_hashmap)); + match kv.find('=') { + None => { + add_err(); + return (kv, None) + }, + Some(pos) => { + let key = &kv[..pos]; + if kv.len() <= pos + 1 { + add_err(); + return (key, None) + } + (key, Some(&kv[pos+1..])) + } + } +} + +pub fn input_file_from_opts(file_path: &str, err: &mut InvalidOptionsError) -> Option { + match fs::File::open(file_path) { + Ok(f) => Some(f), + Err(io_err) => { + err.issues.push(CLIError::Input(InputError::IOError((file_path.to_string(), io_err)))); + None + } + } +} + +pub fn input_mime_from_opts(mime: &str, err: &mut InvalidOptionsError) -> Option { + match mime.parse() { + Ok(m) => Some(m), + Err(_) => { + err.issues.push(CLIError::Input(InputError::Mime(mime.to_string()))); + None + } + } +} + +// May panic if we can't open the file - this is anticipated, we can't currently communicate this +// kind of error: TODO: fix this architecture :) +pub fn writer_from_opts(flag: bool, arg: &str) -> Box { + if !flag || arg == "-" { + Box::new(stdout()) + } else { + Box::new(fs::OpenOptions::new().create(true).write(true).open(arg).unwrap()) + } +} + + +pub fn arg_from_str(arg: &str, err: &mut InvalidOptionsError, + arg_name: &'static str, + arg_type: &'static str) -> T + where T: FromStr + Default, + ::Err: fmt::Display { + match FromStr::from_str(arg) { + Err(perr) => { + err.issues.push( + CLIError::ParseError((arg_name, arg_type, arg.to_string(), format!("{}", perr))) + ); + Default::default() + }, + Ok(v) => v, + } +} + +pub struct JsonTokenStorage { + pub program_name: &'static str, + pub db_dir: String, +} + +impl JsonTokenStorage { + fn path(&self, scope_hash: u64) -> PathBuf { + Path::new(&self.db_dir).join(&format!("{}-token-{}.json", self.program_name, scope_hash)) + } +} + +impl TokenStorage for JsonTokenStorage { + type Error = io::Error; + + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, _: &Vec<&str>, token: Option) -> Option { + match token { + None => { + match fs::remove_file(self.path(scope_hash)) { + Err(err) => + match err.kind() { + io::ErrorKind::NotFound => None, + _ => Some(err) + }, + Ok(_) => None + } + } + Some(token) => { + let json_token = json::encode(&token).unwrap(); + match fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)) { + Ok(mut f) => { + match f.write(json_token.as_bytes()) { + Ok(_) => None, + Err(io_err) => Some(io_err), + } + }, + Err(io_err) => Some(io_err) + } + } + } + } + + fn get(&self, scope_hash: u64, _: &Vec<&str>) -> Result, io::Error> { + match fs::File::open(&self.path(scope_hash)) { + Ok(mut f) => { + let mut json_string = String::new(); + match f.read_to_string(&mut json_string) { + Ok(_) => Ok(Some(json::decode::(&json_string).unwrap())), + Err(io_err) => Err(io_err), + } + }, + Err(io_err) => { + match io_err.kind() { + io::ErrorKind::NotFound => Ok(None), + _ => Err(io_err) + } + } + } + } +} + + +#[derive(Debug)] +pub enum ApplicationSecretError { + DecoderError((String, json::DecoderError)), + FormatError(String), +} + +impl fmt::Display for ApplicationSecretError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + match *self { + ApplicationSecretError::DecoderError((ref path, ref err)) + => writeln!(f, "Could not decode file at '{}' with error: {}", + path, err), + ApplicationSecretError::FormatError(ref path) + => writeln!(f, "'installed' field is unset in secret file at '{}'", + path), + } + } +} + +#[derive(Debug)] +pub enum ConfigurationError { + DirectoryCreationFailed((String, io::Error)), + DirectoryUnset, + HomeExpansionFailed(String), + Secret(ApplicationSecretError), + IOError((String, io::Error)), +} + +impl fmt::Display for ConfigurationError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + match *self { + ConfigurationError::DirectoryCreationFailed((ref dir, ref err)) + => writeln!(f, "Directory '{}' could not be created with error: {}", dir, err), + ConfigurationError::DirectoryUnset + => writeln!(f, "--config-dir was unset or empty"), + ConfigurationError::HomeExpansionFailed(ref dir) + => writeln!(f, "Couldn't find HOME directory of current user, failed to expand '{}'", dir), + ConfigurationError::Secret(ref err) + => writeln!(f, "Secret -> {}", err), + ConfigurationError::IOError((ref path, ref err)) + => writeln!(f, "IO operation failed on path '{}' with error: {}", path, err), + } + } +} + +#[derive(Debug)] +pub enum InputError { + IOError((String, io::Error)), + Mime(String), +} + +impl fmt::Display for InputError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + match *self { + InputError::IOError((ref file_path, ref io_err)) + => writeln!(f, "Failed to open '{}' for reading with error: {}", file_path, io_err), + InputError::Mime(ref mime) + => writeln!(f, "'{}' is not a known mime-type", mime), + } + } +} + +#[derive(Debug)] +pub enum FieldError { + PopOnEmpty(String), + TrailingFieldSep(String), + Unknown(String), + Empty, +} + + +impl fmt::Display for FieldError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + match *self { + FieldError::PopOnEmpty(ref field) + => writeln!(f, "'{}': Cannot move up on empty field cursor", field), + FieldError::TrailingFieldSep(ref field) + => writeln!(f, "'{}': Single field separator may not be last character", field), + FieldError::Unknown(ref field) + => writeln!(f, "Field '{}' does not exist", field), + FieldError::Empty + => writeln!(f, "Field names must not be empty"), + } + } +} + + +#[derive(Debug)] +pub enum CLIError { + Configuration(ConfigurationError), + ParseError((&'static str, &'static str, String, String)), + UnknownParameter(String), + InvalidKeyValueSyntax(String, bool), + Input(InputError), + Field(FieldError), +} + +impl fmt::Display for CLIError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + match *self { + CLIError::Configuration(ref err) => write!(f, "Configuration -> {}", err), + CLIError::Input(ref err) => write!(f, "Input -> {}", err), + CLIError::Field(ref err) => write!(f, "Field -> {}", err), + CLIError::ParseError((arg_name, 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) + => writeln!(f, "Parameter '{}' is unknown.", param_name), + CLIError::InvalidKeyValueSyntax(ref kv, is_hashmap) => { + let hashmap_info = if is_hashmap { "hashmap " } else { "" }; + writeln!(f, "'{}' does not match {}pattern =", kv, hashmap_info) + }, + } + } +} + +#[derive(Debug)] +pub struct InvalidOptionsError { + pub issues: Vec, + pub exit_code: i32, +} + +impl fmt::Display for InvalidOptionsError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + for issue in &self.issues { + try!(issue.fmt(f)); + } + Ok(()) + } +} + +impl InvalidOptionsError { + pub fn single(err: CLIError, exit_code: i32) -> InvalidOptionsError { + InvalidOptionsError { + issues: vec![err], + exit_code: exit_code, + } + } + + pub fn new() -> InvalidOptionsError { + InvalidOptionsError { + issues: Vec::new(), + exit_code: 1, + } + } +} + +pub fn assure_config_dir_exists(dir: &str) -> Result { + let trdir = dir.trim(); + if trdir.len() == 0 { + return Err(CLIError::Configuration(ConfigurationError::DirectoryUnset)) + } + + let expanded_config_dir = + if trdir.as_bytes()[0] == b'~' { + match env::var("HOME").ok().or(env::var("UserProfile").ok()) { + None => return Err(CLIError::Configuration(ConfigurationError::HomeExpansionFailed(trdir.to_string()))), + Some(mut user) => { + user.push_str(&trdir[1..]); + user + } + } + } else { + trdir.to_string() + }; + + if let Err(err) = fs::create_dir(&expanded_config_dir) { + if err.kind() != io::ErrorKind::AlreadyExists { + return Err(CLIError::Configuration( + ConfigurationError::DirectoryCreationFailed((expanded_config_dir, err)))) + } + } + + Ok(expanded_config_dir) +} + +pub fn application_secret_from_directory(dir: &str, + secret_basename: &str, + json_app_secret: &str) + -> Result { + let secret_path = Path::new(dir).join(secret_basename); + let secret_str = || secret_path.as_path().to_str().unwrap().to_string(); + let secret_io_error = |io_err: io::Error| { + Err(CLIError::Configuration(ConfigurationError::IOError( + (secret_str(), io_err) + ))) + }; + + for _ in 0..2 { + match fs::File::open(&secret_path) { + Err(mut err) => { + if err.kind() == io::ErrorKind::NotFound { + // Write our built-in one - user may adjust the written file at will + + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_app_secret.as_bytes()) { + Err(io_err) => io_err, + Ok(_) => continue, + } + } + }; + // fall through to IO error handling + } + return secret_io_error(err) + }, + Ok(mut f) => { + let mut json_encoded_secret = String::new(); + if let Err(io_err) = f.read_to_string(&mut json_encoded_secret) { + return secret_io_error(io_err) + } + match json::decode::(&json_encoded_secret) { + Err(json_decode_error) => return Err(CLIError::Configuration( + ConfigurationError::Secret(ApplicationSecretError::DecoderError( + (secret_str(), json_decode_error) + )))), + Ok(console_secret) => match console_secret.installed { + Some(secret) => return Ok(secret), + None => return Err( + CLIError::Configuration( + ConfigurationError::Secret( + ApplicationSecretError::FormatError(secret_str()) + ))) + }, + } + } + } + } + unreachable!(); +} \ No newline at end of file diff --git a/gen/coordinate1-cli/src/main.rs b/gen/coordinate1-cli/src/main.rs new file mode 100644 index 0000000000..325a52a532 --- /dev/null +++ b/gen/coordinate1-cli/src/main.rs @@ -0,0 +1,1192 @@ +// DO NOT EDIT ! +// This file was generated automatically from 'src/mako/cli/main.rs.mako' +// DO NOT EDIT ! +#![feature(plugin, exit_status)] +#![plugin(docopt_macros)] +#![allow(unused_variables, unused_imports, dead_code, unused_mut)] + +extern crate docopt; +extern crate yup_oauth2 as oauth2; +extern crate yup_hyper_mock as mock; +extern crate rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_coordinate1 as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + coordinate1 [options] custom-field-def list [-p ]... [-o ] + coordinate1 [options] jobs get [-p ]... [-o ] + coordinate1 [options] jobs insert
-r <kv>... [-p <v>]... [-o <out>] + coordinate1 [options] jobs list <team-id> [-p <v>]... [-o <out>] + coordinate1 [options] jobs patch <team-id> <job-id> -r <kv>... [-p <v>]... [-o <out>] + coordinate1 [options] jobs update <team-id> <job-id> -r <kv>... [-p <v>]... [-o <out>] + coordinate1 [options] location list <team-id> <worker-email> <start-timestamp-ms> [-p <v>]... [-o <out>] + coordinate1 [options] schedule get <team-id> <job-id> [-p <v>]... [-o <out>] + coordinate1 [options] schedule patch <team-id> <job-id> -r <kv>... [-p <v>]... [-o <out>] + coordinate1 [options] schedule update <team-id> <job-id> -r <kv>... [-p <v>]... [-o <out>] + coordinate1 [options] team list [-p <v>]... [-o <out>] + coordinate1 [options] worker list <team-id> [-p <v>]... [-o <out>] + coordinate1 --help + +All documentation details can be found TODO: <URL to github.io docs here, see #51> + +Configuration: + --scope <url> + 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. + --config-dir <folder> + 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] + --debug + Output all server communication to standard error. `tx` and `rx` are placed into + the same stream. + --debug-auth + Output all communication related to authentication to standard error. `tx` and `rx` are placed into + the same stream. +"); + +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}; + +use std::default::Default; +use std::str::FromStr; + +use oauth2::{Authenticator, DefaultAuthenticatorDelegate}; +use rustc_serialize::json; + +struct Engine { + opt: Options, + hub: api::Coordinate<hyper::Client, Authenticator<DefaultAuthenticatorDelegate, JsonTokenStorage, hyper::Client>>, +} + + +impl Engine { + fn _custom_field_def_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.custom_field_def().list(&self.opt.arg_team_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _jobs_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.jobs().get(&self.opt.arg_team_id, &self.opt.arg_job_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _jobs_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request = api::Job::default(); + let lat: f64 = arg_from_str(&self.opt.arg_lat, err, "<lat>", "number"); + let lng: f64 = arg_from_str(&self.opt.arg_lng, err, "<lng>", "number"); + let mut call = self.hub.jobs().insert(&request, &self.opt.arg_team_id, &self.opt.arg_address, lat, lng, &self.opt.arg_title); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "note" => { + call = call.note(value.unwrap_or("")); + }, + "customer-phone-number" => { + call = call.customer_phone_number(value.unwrap_or("")); + }, + "customer-name" => { + call = call.customer_name(value.unwrap_or("")); + }, + "custom-field" => { + call = call.add_custom_field(value.unwrap_or("")); + }, + "assignee" => { + call = call.assignee(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_state_custom_fields_init(request: &mut api::Job) { + request_state_init(request); + if request.state.as_mut().unwrap().custom_fields.is_none() { + request.state.as_mut().unwrap().custom_fields = Some(Default::default()); + } + } + + fn request_state_init(request: &mut api::Job) { + if request.state.is_none() { + request.state = Some(Default::default()); + } + } + + fn request_state_location_init(request: &mut api::Job) { + request_state_init(request); + if request.state.as_mut().unwrap().location.is_none() { + request.state.as_mut().unwrap().location = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "state.kind" => { + request_state_init(&mut request); + request.state.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "state.customer-name" => { + request_state_init(&mut request); + request.state.as_mut().unwrap().customer_name = Some(value.unwrap_or("").to_string()); + }, + "state.title" => { + request_state_init(&mut request); + request.state.as_mut().unwrap().title = Some(value.unwrap_or("").to_string()); + }, + "state.note" => { + request_state_init(&mut request); + if request.state.as_mut().unwrap().note.is_none() { + request.state.as_mut().unwrap().note = Some(Default::default()); + } + request.state.as_mut().unwrap().note.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "state.assignee" => { + request_state_init(&mut request); + request.state.as_mut().unwrap().assignee = Some(value.unwrap_or("").to_string()); + }, + "state.customer-phone-number" => { + request_state_init(&mut request); + request.state.as_mut().unwrap().customer_phone_number = Some(value.unwrap_or("").to_string()); + }, + "state.location.lat" => { + request_state_location_init(&mut request); + request.state.as_mut().unwrap().location.as_mut().unwrap().lat = Some(arg_from_str(value.unwrap_or("0.0"), err, "state.location.lat", "number")); + }, + "state.location.kind" => { + request_state_location_init(&mut request); + request.state.as_mut().unwrap().location.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "state.location.address-line" => { + request_state_location_init(&mut request); + if request.state.as_mut().unwrap().location.as_mut().unwrap().address_line.is_none() { + request.state.as_mut().unwrap().location.as_mut().unwrap().address_line = Some(Default::default()); + } + request.state.as_mut().unwrap().location.as_mut().unwrap().address_line.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "state.location.lng" => { + request_state_location_init(&mut request); + request.state.as_mut().unwrap().location.as_mut().unwrap().lng = Some(arg_from_str(value.unwrap_or("0.0"), err, "state.location.lng", "number")); + }, + "state.progress" => { + request_state_location_init(&mut request); + request.state.as_mut().unwrap().progress = Some(value.unwrap_or("").to_string()); + }, + "state.custom-fields.kind" => { + request_state_custom_fields_init(&mut request); + request.state.as_mut().unwrap().custom_fields.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _jobs_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.jobs().list(&self.opt.arg_team_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "min-modified-timestamp-ms" => { + call = call.min_modified_timestamp_ms(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _jobs_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request = api::Job::default(); + let mut call = self.hub.jobs().patch(&request, &self.opt.arg_team_id, &self.opt.arg_job_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "title" => { + call = call.title(value.unwrap_or("")); + }, + "progress" => { + call = call.progress(value.unwrap_or("")); + }, + "note" => { + call = call.note(value.unwrap_or("")); + }, + "lng" => { + call = call.lng(arg_from_str(value.unwrap_or("0.0"), err, "lng", "number")); + }, + "lat" => { + call = call.lat(arg_from_str(value.unwrap_or("0.0"), err, "lat", "number")); + }, + "customer-phone-number" => { + call = call.customer_phone_number(value.unwrap_or("")); + }, + "customer-name" => { + call = call.customer_name(value.unwrap_or("")); + }, + "custom-field" => { + call = call.add_custom_field(value.unwrap_or("")); + }, + "assignee" => { + call = call.assignee(value.unwrap_or("")); + }, + "address" => { + call = call.address(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_state_custom_fields_init(request: &mut api::Job) { + request_state_init(request); + if request.state.as_mut().unwrap().custom_fields.is_none() { + request.state.as_mut().unwrap().custom_fields = Some(Default::default()); + } + } + + fn request_state_init(request: &mut api::Job) { + if request.state.is_none() { + request.state = Some(Default::default()); + } + } + + fn request_state_location_init(request: &mut api::Job) { + request_state_init(request); + if request.state.as_mut().unwrap().location.is_none() { + request.state.as_mut().unwrap().location = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "state.kind" => { + request_state_init(&mut request); + request.state.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "state.customer-name" => { + request_state_init(&mut request); + request.state.as_mut().unwrap().customer_name = Some(value.unwrap_or("").to_string()); + }, + "state.title" => { + request_state_init(&mut request); + request.state.as_mut().unwrap().title = Some(value.unwrap_or("").to_string()); + }, + "state.note" => { + request_state_init(&mut request); + if request.state.as_mut().unwrap().note.is_none() { + request.state.as_mut().unwrap().note = Some(Default::default()); + } + request.state.as_mut().unwrap().note.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "state.assignee" => { + request_state_init(&mut request); + request.state.as_mut().unwrap().assignee = Some(value.unwrap_or("").to_string()); + }, + "state.customer-phone-number" => { + request_state_init(&mut request); + request.state.as_mut().unwrap().customer_phone_number = Some(value.unwrap_or("").to_string()); + }, + "state.location.lat" => { + request_state_location_init(&mut request); + request.state.as_mut().unwrap().location.as_mut().unwrap().lat = Some(arg_from_str(value.unwrap_or("0.0"), err, "state.location.lat", "number")); + }, + "state.location.kind" => { + request_state_location_init(&mut request); + request.state.as_mut().unwrap().location.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "state.location.address-line" => { + request_state_location_init(&mut request); + if request.state.as_mut().unwrap().location.as_mut().unwrap().address_line.is_none() { + request.state.as_mut().unwrap().location.as_mut().unwrap().address_line = Some(Default::default()); + } + request.state.as_mut().unwrap().location.as_mut().unwrap().address_line.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "state.location.lng" => { + request_state_location_init(&mut request); + request.state.as_mut().unwrap().location.as_mut().unwrap().lng = Some(arg_from_str(value.unwrap_or("0.0"), err, "state.location.lng", "number")); + }, + "state.progress" => { + request_state_location_init(&mut request); + request.state.as_mut().unwrap().progress = Some(value.unwrap_or("").to_string()); + }, + "state.custom-fields.kind" => { + request_state_custom_fields_init(&mut request); + request.state.as_mut().unwrap().custom_fields.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _jobs_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request = api::Job::default(); + let mut call = self.hub.jobs().update(&request, &self.opt.arg_team_id, &self.opt.arg_job_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "title" => { + call = call.title(value.unwrap_or("")); + }, + "progress" => { + call = call.progress(value.unwrap_or("")); + }, + "note" => { + call = call.note(value.unwrap_or("")); + }, + "lng" => { + call = call.lng(arg_from_str(value.unwrap_or("0.0"), err, "lng", "number")); + }, + "lat" => { + call = call.lat(arg_from_str(value.unwrap_or("0.0"), err, "lat", "number")); + }, + "customer-phone-number" => { + call = call.customer_phone_number(value.unwrap_or("")); + }, + "customer-name" => { + call = call.customer_name(value.unwrap_or("")); + }, + "custom-field" => { + call = call.add_custom_field(value.unwrap_or("")); + }, + "assignee" => { + call = call.assignee(value.unwrap_or("")); + }, + "address" => { + call = call.address(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_state_custom_fields_init(request: &mut api::Job) { + request_state_init(request); + if request.state.as_mut().unwrap().custom_fields.is_none() { + request.state.as_mut().unwrap().custom_fields = Some(Default::default()); + } + } + + fn request_state_init(request: &mut api::Job) { + if request.state.is_none() { + request.state = Some(Default::default()); + } + } + + fn request_state_location_init(request: &mut api::Job) { + request_state_init(request); + if request.state.as_mut().unwrap().location.is_none() { + request.state.as_mut().unwrap().location = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "state.kind" => { + request_state_init(&mut request); + request.state.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "state.customer-name" => { + request_state_init(&mut request); + request.state.as_mut().unwrap().customer_name = Some(value.unwrap_or("").to_string()); + }, + "state.title" => { + request_state_init(&mut request); + request.state.as_mut().unwrap().title = Some(value.unwrap_or("").to_string()); + }, + "state.note" => { + request_state_init(&mut request); + if request.state.as_mut().unwrap().note.is_none() { + request.state.as_mut().unwrap().note = Some(Default::default()); + } + request.state.as_mut().unwrap().note.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "state.assignee" => { + request_state_init(&mut request); + request.state.as_mut().unwrap().assignee = Some(value.unwrap_or("").to_string()); + }, + "state.customer-phone-number" => { + request_state_init(&mut request); + request.state.as_mut().unwrap().customer_phone_number = Some(value.unwrap_or("").to_string()); + }, + "state.location.lat" => { + request_state_location_init(&mut request); + request.state.as_mut().unwrap().location.as_mut().unwrap().lat = Some(arg_from_str(value.unwrap_or("0.0"), err, "state.location.lat", "number")); + }, + "state.location.kind" => { + request_state_location_init(&mut request); + request.state.as_mut().unwrap().location.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "state.location.address-line" => { + request_state_location_init(&mut request); + if request.state.as_mut().unwrap().location.as_mut().unwrap().address_line.is_none() { + request.state.as_mut().unwrap().location.as_mut().unwrap().address_line = Some(Default::default()); + } + request.state.as_mut().unwrap().location.as_mut().unwrap().address_line.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "state.location.lng" => { + request_state_location_init(&mut request); + request.state.as_mut().unwrap().location.as_mut().unwrap().lng = Some(arg_from_str(value.unwrap_or("0.0"), err, "state.location.lng", "number")); + }, + "state.progress" => { + request_state_location_init(&mut request); + request.state.as_mut().unwrap().progress = Some(value.unwrap_or("").to_string()); + }, + "state.custom-fields.kind" => { + request_state_custom_fields_init(&mut request); + request.state.as_mut().unwrap().custom_fields.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _location_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.location().list(&self.opt.arg_team_id, &self.opt.arg_worker_email, &self.opt.arg_start_timestamp_ms); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _schedule_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.schedule().get(&self.opt.arg_team_id, &self.opt.arg_job_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _schedule_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request = api::Schedule::default(); + let mut call = self.hub.schedule().patch(&request, &self.opt.arg_team_id, &self.opt.arg_job_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "start-time" => { + call = call.start_time(value.unwrap_or("")); + }, + "end-time" => { + call = call.end_time(value.unwrap_or("")); + }, + "duration" => { + call = call.duration(value.unwrap_or("")); + }, + "all-day" => { + call = call.all_day(arg_from_str(value.unwrap_or("false"), err, "all-day", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "duration" => { + request.duration = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "all-day" => { + request.all_day = Some(arg_from_str(value.unwrap_or("false"), err, "all-day", "boolean")); + }, + "start-time" => { + request.start_time = Some(value.unwrap_or("").to_string()); + }, + "end-time" => { + request.end_time = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _schedule_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request = api::Schedule::default(); + let mut call = self.hub.schedule().update(&request, &self.opt.arg_team_id, &self.opt.arg_job_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "start-time" => { + call = call.start_time(value.unwrap_or("")); + }, + "end-time" => { + call = call.end_time(value.unwrap_or("")); + }, + "duration" => { + call = call.duration(value.unwrap_or("")); + }, + "all-day" => { + call = call.all_day(arg_from_str(value.unwrap_or("false"), err, "all-day", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "duration" => { + request.duration = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "all-day" => { + request.all_day = Some(arg_from_str(value.unwrap_or("false"), err, "all-day", "boolean")); + }, + "start-time" => { + request.start_time = Some(value.unwrap_or("").to_string()); + }, + "end-time" => { + request.end_time = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _team_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.team().list(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "worker" => { + call = call.worker(arg_from_str(value.unwrap_or("false"), err, "worker", "boolean")); + }, + "dispatcher" => { + call = call.dispatcher(arg_from_str(value.unwrap_or("false"), err, "dispatcher", "boolean")); + }, + "admin" => { + call = call.admin(arg_from_str(value.unwrap_or("false"), err, "admin", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _worker_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.worker().list(&self.opt.arg_team_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option<api::Error>, Option<InvalidOptionsError>) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option<api::Error>; + let mut err_opt: Option<InvalidOptionsError> = None; + + if self.opt.cmd_custom_field_def { + if self.opt.cmd_list { + call_result = self._custom_field_def_list(dry_run, &mut err); + } else { + unreachable!(); + } + } + else if self.opt.cmd_jobs { + if self.opt.cmd_get { + call_result = self._jobs_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._jobs_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._jobs_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._jobs_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._jobs_update(dry_run, &mut err); + } else { + unreachable!(); + } + } + else if self.opt.cmd_location { + if self.opt.cmd_list { + call_result = self._location_list(dry_run, &mut err); + } else { + unreachable!(); + } + } + else if self.opt.cmd_schedule { + if self.opt.cmd_get { + call_result = self._schedule_get(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._schedule_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._schedule_update(dry_run, &mut err); + } else { + unreachable!(); + } + } + else if self.opt.cmd_team { + if self.opt.cmd_list { + call_result = self._team_list(dry_run, &mut err); + } else { + unreachable!(); + } + } + else if self.opt.cmd_worker { + if self.opt.cmd_list { + call_result = self._worker_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else { + unreachable!(); + } + + if dry_run { + if err.issues.len() > 0 { + err_opt = Some(err); + } + } + (call_result, err_opt) + } + + // Please note that this call will fail if any part of the opt can't be handled + fn new(opt: Options) -> Result<Engine, InvalidOptionsError> { + let (config_dir, secret) = { + let config_dir = match cmn::assure_config_dir_exists(&opt.flag_config_dir) { + Err(e) => return Err(InvalidOptionsError::single(e, 3)), + Ok(p) => p, + }; + + match cmn::application_secret_from_directory(&config_dir, "coordinate1-secret.json", + "{\"installed\":{\"auth_uri\":\"https://accounts.google.com/o/oauth2/auth\",\"client_secret\":\"hCsslbCUyfehWMmbkG8vTYxG\",\"token_uri\":\"https://accounts.google.com/o/oauth2/token\",\"client_email\":\"\",\"redirect_uris\":[\"urn:ietf:wg:oauth:2.0:oob\",\"oob\"],\"client_x509_cert_url\":\"\",\"client_id\":\"620010449518-9ngf7o4dhs0dka470npqvor6dc5lqb9b.apps.googleusercontent.com\",\"auth_provider_x509_cert_url\":\"https://www.googleapis.com/oauth2/v1/certs\"}}") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new( &secret, DefaultAuthenticatorDelegate, + if opt.flag_debug_auth { + hyper::Client::with_connector(mock::TeeConnector { + connector: hyper::net::HttpConnector(None) + }) + } else { + hyper::Client::new() + }, + JsonTokenStorage { + program_name: "coordinate1", + db_dir: config_dir.clone(), + }, None); + + let client = + if opt.flag_debug { + hyper::Client::with_connector(mock::TeeConnector { + connector: hyper::net::HttpConnector(None) + }) + } else { + hyper::Client::new() + }; + let engine = Engine { + opt: opt, + hub: api::Coordinate::new(client, auth), + }; + + match engine._doit(true) { + (_, Some(err)) => Err(err), + _ => Ok(engine), + } + } + + // Execute the call with all the bells and whistles, informing the caller only if there was an error. + // The absense of one indicates success. + fn doit(&self) -> Option<api::Error> { + self._doit(false).0 + } +} + +fn main() { + let opts: Options = Options::docopt().decode().unwrap_or_else(|e| e.exit()); + match Engine::new(opts) { + Err(err) => { + writeln!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + writeln!(io::stderr(), "{:?}", err).ok(); + writeln!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/customsearch1-cli/Cargo.toml b/gen/customsearch1-cli/Cargo.toml new file mode 100644 index 0000000000..d5c20f93c2 --- /dev/null +++ b/gen/customsearch1-cli/Cargo.toml @@ -0,0 +1,31 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-customsearch1-cli" +version = "0.0.1+20131205" +authors = ["Sebastian Thiel <byronimo@gmail.com>"] +description = "A complete library to interact with customsearch (protocol v1)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/customsearch1-cli" +homepage = "https://developers.google.com/custom-search/v1/using_rest" +documentation = "http://byron.github.io/google-apis-rs/google_customsearch1_cli" +license = "MIT" +keywords = ["customsearch", "google", "cli"] + +[[bin]] +name = "customsearch1" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "*" +docopt_macros = "*" +rustc-serialize = "*" +yup-hyper-mock = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-customsearch1] +path = "../customsearch1" diff --git a/gen/customsearch1-cli/LICENSE.md b/gen/customsearch1-cli/LICENSE.md new file mode 100644 index 0000000000..ae22e6ec52 --- /dev/null +++ b/gen/customsearch1-cli/LICENSE.md @@ -0,0 +1,30 @@ +<!--- +DO NOT EDIT ! +This file was generated automatically from 'src/mako/LICENSE.md.mako' +DO NOT EDIT ! +--> +The MIT License (MIT) +===================== + +Copyright © `2015` `Sebastian Thiel` + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the “Software”), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. diff --git a/gen/customsearch1-cli/README.md b/gen/customsearch1-cli/README.md new file mode 100644 index 0000000000..260a95e544 --- /dev/null +++ b/gen/customsearch1-cli/README.md @@ -0,0 +1,4 @@ +# HELLO CUSTOMSEARCH:V1 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/customsearch1-cli/mkdocs.yml b/gen/customsearch1-cli/mkdocs.yml new file mode 100644 index 0000000000..4f2a14ddf7 --- /dev/null +++ b/gen/customsearch1-cli/mkdocs.yml @@ -0,0 +1,17 @@ +site_name: customsearch v0.0.1+20131205 +site_url: http://byron.github.io/google-apis-rs/google-customsearch1-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/customsearch1-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['cse_list.md', 'Cse', 'List'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/customsearch1-cli/src/cmn.rs b/gen/customsearch1-cli/src/cmn.rs new file mode 100644 index 0000000000..a8d3f46368 --- /dev/null +++ b/gen/customsearch1-cli/src/cmn.rs @@ -0,0 +1,454 @@ +// COPY OF 'src/rust/cli/cmn.rs' +// DO NOT EDIT +use oauth2::{ApplicationSecret, ConsoleApplicationSecret, TokenStorage, Token}; +use rustc_serialize::json; +use mime::Mime; + +use std::fs; +use std::env; +use std::io; +use std::fmt; +use std::path::{Path, PathBuf}; +use std::str::FromStr; +use std::string::ToString; +use std::io::{Write, Read, stdout}; + +use std::default::Default; + +const FIELD_SEP: char = '.'; + +#[derive(Clone, Default)] +pub struct FieldCursor(Vec<String>); + +impl ToString for FieldCursor { + fn to_string(&self) -> String { + self.0.connect(".") + } +} + +impl FieldCursor { + pub fn set(&mut self, value: &str) -> Result<(), CLIError> { + if value.len() == 0 { + return Err(CLIError::Field(FieldError::Empty)) + } + + let mut first_is_field_sep = false; + let mut char_count: usize = 0; + let mut last_c = FIELD_SEP; + let mut num_conscutive_field_seps = 0; + + let mut field = String::new(); + let mut fields = self.0.clone(); + + let push_field = |fs: &mut Vec<String>, f: &mut String| { + if f.len() > 0 { + fs.push(f.clone()); + f.truncate(0); + } + }; + + for (cid, c) in value.chars().enumerate() { + char_count += 1; + + if c == FIELD_SEP { + if cid == 0 { + first_is_field_sep = true; + } + num_conscutive_field_seps += 1; + if cid > 0 && last_c == FIELD_SEP { + if fields.pop().is_none() { + return Err(CLIError::Field(FieldError::PopOnEmpty(value.to_string()))) + } + } else { + push_field(&mut fields, &mut field); + } + } else { + num_conscutive_field_seps = 0; + if cid == 1 { + if first_is_field_sep { + fields.truncate(0); + } + } + field.push(c); + } + + last_c = c; + } + + push_field(&mut fields, &mut field); + + if char_count == 1 && first_is_field_sep { + fields.truncate(0); + } + if char_count > 1 && num_conscutive_field_seps == 1 { + return Err(CLIError::Field(FieldError::TrailingFieldSep(value.to_string()))) + } + + self.0 = fields; + Ok(()) + } + + pub fn num_fields(&self) -> usize { + self.0.len() + } +} + +pub fn parse_kv_arg<'a>(kv: &'a str, err: &mut InvalidOptionsError, for_hashmap: bool) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string(),for_hashmap)); + match kv.find('=') { + None => { + add_err(); + return (kv, None) + }, + Some(pos) => { + let key = &kv[..pos]; + if kv.len() <= pos + 1 { + add_err(); + return (key, None) + } + (key, Some(&kv[pos+1..])) + } + } +} + +pub fn input_file_from_opts(file_path: &str, err: &mut InvalidOptionsError) -> Option<fs::File> { + match fs::File::open(file_path) { + Ok(f) => Some(f), + Err(io_err) => { + err.issues.push(CLIError::Input(InputError::IOError((file_path.to_string(), io_err)))); + None + } + } +} + +pub fn input_mime_from_opts(mime: &str, err: &mut InvalidOptionsError) -> Option<Mime> { + match mime.parse() { + Ok(m) => Some(m), + Err(_) => { + err.issues.push(CLIError::Input(InputError::Mime(mime.to_string()))); + None + } + } +} + +// May panic if we can't open the file - this is anticipated, we can't currently communicate this +// kind of error: TODO: fix this architecture :) +pub fn writer_from_opts(flag: bool, arg: &str) -> Box<Write> { + if !flag || arg == "-" { + Box::new(stdout()) + } else { + Box::new(fs::OpenOptions::new().create(true).write(true).open(arg).unwrap()) + } +} + + +pub fn arg_from_str<T>(arg: &str, err: &mut InvalidOptionsError, + arg_name: &'static str, + arg_type: &'static 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))) + ); + Default::default() + }, + Ok(v) => v, + } +} + +pub struct JsonTokenStorage { + pub program_name: &'static str, + pub db_dir: String, +} + +impl JsonTokenStorage { + fn path(&self, scope_hash: u64) -> PathBuf { + Path::new(&self.db_dir).join(&format!("{}-token-{}.json", self.program_name, scope_hash)) + } +} + +impl TokenStorage for JsonTokenStorage { + type Error = io::Error; + + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, _: &Vec<&str>, token: Option<Token>) -> Option<io::Error> { + match token { + None => { + match fs::remove_file(self.path(scope_hash)) { + Err(err) => + match err.kind() { + io::ErrorKind::NotFound => None, + _ => Some(err) + }, + Ok(_) => None + } + } + Some(token) => { + let json_token = json::encode(&token).unwrap(); + match fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)) { + Ok(mut f) => { + match f.write(json_token.as_bytes()) { + Ok(_) => None, + Err(io_err) => Some(io_err), + } + }, + Err(io_err) => Some(io_err) + } + } + } + } + + fn get(&self, scope_hash: u64, _: &Vec<&str>) -> Result<Option<Token>, io::Error> { + match fs::File::open(&self.path(scope_hash)) { + Ok(mut f) => { + let mut json_string = String::new(); + match f.read_to_string(&mut json_string) { + Ok(_) => Ok(Some(json::decode::<Token>(&json_string).unwrap())), + Err(io_err) => Err(io_err), + } + }, + Err(io_err) => { + match io_err.kind() { + io::ErrorKind::NotFound => Ok(None), + _ => Err(io_err) + } + } + } + } +} + + +#[derive(Debug)] +pub enum ApplicationSecretError { + DecoderError((String, json::DecoderError)), + FormatError(String), +} + +impl fmt::Display for ApplicationSecretError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + match *self { + ApplicationSecretError::DecoderError((ref path, ref err)) + => writeln!(f, "Could not decode file at '{}' with error: {}", + path, err), + ApplicationSecretError::FormatError(ref path) + => writeln!(f, "'installed' field is unset in secret file at '{}'", + path), + } + } +} + +#[derive(Debug)] +pub enum ConfigurationError { + DirectoryCreationFailed((String, io::Error)), + DirectoryUnset, + HomeExpansionFailed(String), + Secret(ApplicationSecretError), + IOError((String, io::Error)), +} + +impl fmt::Display for ConfigurationError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + match *self { + ConfigurationError::DirectoryCreationFailed((ref dir, ref err)) + => writeln!(f, "Directory '{}' could not be created with error: {}", dir, err), + ConfigurationError::DirectoryUnset + => writeln!(f, "--config-dir was unset or empty"), + ConfigurationError::HomeExpansionFailed(ref dir) + => writeln!(f, "Couldn't find HOME directory of current user, failed to expand '{}'", dir), + ConfigurationError::Secret(ref err) + => writeln!(f, "Secret -> {}", err), + ConfigurationError::IOError((ref path, ref err)) + => writeln!(f, "IO operation failed on path '{}' with error: {}", path, err), + } + } +} + +#[derive(Debug)] +pub enum InputError { + IOError((String, io::Error)), + Mime(String), +} + +impl fmt::Display for InputError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + match *self { + InputError::IOError((ref file_path, ref io_err)) + => writeln!(f, "Failed to open '{}' for reading with error: {}", file_path, io_err), + InputError::Mime(ref mime) + => writeln!(f, "'{}' is not a known mime-type", mime), + } + } +} + +#[derive(Debug)] +pub enum FieldError { + PopOnEmpty(String), + TrailingFieldSep(String), + Unknown(String), + Empty, +} + + +impl fmt::Display for FieldError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + match *self { + FieldError::PopOnEmpty(ref field) + => writeln!(f, "'{}': Cannot move up on empty field cursor", field), + FieldError::TrailingFieldSep(ref field) + => writeln!(f, "'{}': Single field separator may not be last character", field), + FieldError::Unknown(ref field) + => writeln!(f, "Field '{}' does not exist", field), + FieldError::Empty + => writeln!(f, "Field names must not be empty"), + } + } +} + + +#[derive(Debug)] +pub enum CLIError { + Configuration(ConfigurationError), + ParseError((&'static str, &'static str, String, String)), + UnknownParameter(String), + InvalidKeyValueSyntax(String, bool), + Input(InputError), + Field(FieldError), +} + +impl fmt::Display for CLIError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + match *self { + CLIError::Configuration(ref err) => write!(f, "Configuration -> {}", err), + CLIError::Input(ref err) => write!(f, "Input -> {}", err), + CLIError::Field(ref err) => write!(f, "Field -> {}", err), + CLIError::ParseError((arg_name, 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) + => writeln!(f, "Parameter '{}' is unknown.", param_name), + CLIError::InvalidKeyValueSyntax(ref kv, is_hashmap) => { + let hashmap_info = if is_hashmap { "hashmap " } else { "" }; + writeln!(f, "'{}' does not match {}pattern <key>=<value>", kv, hashmap_info) + }, + } + } +} + +#[derive(Debug)] +pub struct InvalidOptionsError { + pub issues: Vec<CLIError>, + pub exit_code: i32, +} + +impl fmt::Display for InvalidOptionsError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + for issue in &self.issues { + try!(issue.fmt(f)); + } + Ok(()) + } +} + +impl InvalidOptionsError { + pub fn single(err: CLIError, exit_code: i32) -> InvalidOptionsError { + InvalidOptionsError { + issues: vec![err], + exit_code: exit_code, + } + } + + pub fn new() -> InvalidOptionsError { + InvalidOptionsError { + issues: Vec::new(), + exit_code: 1, + } + } +} + +pub fn assure_config_dir_exists(dir: &str) -> Result<String, CLIError> { + let trdir = dir.trim(); + if trdir.len() == 0 { + return Err(CLIError::Configuration(ConfigurationError::DirectoryUnset)) + } + + let expanded_config_dir = + if trdir.as_bytes()[0] == b'~' { + match env::var("HOME").ok().or(env::var("UserProfile").ok()) { + None => return Err(CLIError::Configuration(ConfigurationError::HomeExpansionFailed(trdir.to_string()))), + Some(mut user) => { + user.push_str(&trdir[1..]); + user + } + } + } else { + trdir.to_string() + }; + + if let Err(err) = fs::create_dir(&expanded_config_dir) { + if err.kind() != io::ErrorKind::AlreadyExists { + return Err(CLIError::Configuration( + ConfigurationError::DirectoryCreationFailed((expanded_config_dir, err)))) + } + } + + Ok(expanded_config_dir) +} + +pub fn application_secret_from_directory(dir: &str, + secret_basename: &str, + json_app_secret: &str) + -> Result<ApplicationSecret, CLIError> { + let secret_path = Path::new(dir).join(secret_basename); + let secret_str = || secret_path.as_path().to_str().unwrap().to_string(); + let secret_io_error = |io_err: io::Error| { + Err(CLIError::Configuration(ConfigurationError::IOError( + (secret_str(), io_err) + ))) + }; + + for _ in 0..2 { + match fs::File::open(&secret_path) { + Err(mut err) => { + if err.kind() == io::ErrorKind::NotFound { + // Write our built-in one - user may adjust the written file at will + + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_app_secret.as_bytes()) { + Err(io_err) => io_err, + Ok(_) => continue, + } + } + }; + // fall through to IO error handling + } + return secret_io_error(err) + }, + Ok(mut f) => { + let mut json_encoded_secret = String::new(); + if let Err(io_err) = f.read_to_string(&mut json_encoded_secret) { + return secret_io_error(io_err) + } + match json::decode::<ConsoleApplicationSecret>(&json_encoded_secret) { + Err(json_decode_error) => return Err(CLIError::Configuration( + ConfigurationError::Secret(ApplicationSecretError::DecoderError( + (secret_str(), json_decode_error) + )))), + Ok(console_secret) => match console_secret.installed { + Some(secret) => return Ok(secret), + None => return Err( + CLIError::Configuration( + ConfigurationError::Secret( + ApplicationSecretError::FormatError(secret_str()) + ))) + }, + } + } + } + } + unreachable!(); +} \ No newline at end of file diff --git a/gen/customsearch1-cli/src/main.rs b/gen/customsearch1-cli/src/main.rs new file mode 100644 index 0000000000..1bf36ce1fb --- /dev/null +++ b/gen/customsearch1-cli/src/main.rs @@ -0,0 +1,285 @@ +// DO NOT EDIT ! +// This file was generated automatically from 'src/mako/cli/main.rs.mako' +// DO NOT EDIT ! +#![feature(plugin, exit_status)] +#![plugin(docopt_macros)] +#![allow(unused_variables, unused_imports, dead_code, unused_mut)] + +extern crate docopt; +extern crate yup_oauth2 as oauth2; +extern crate yup_hyper_mock as mock; +extern crate rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_customsearch1 as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + customsearch1 [options] cse list <q> [-p <v>]... [-o <out>] + customsearch1 --help + +All documentation details can be found TODO: <URL to github.io docs here, see #51> + +Configuration: + --config-dir <folder> + 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] + --debug + Output all server communication to standard error. `tx` and `rx` are placed into + the same stream. + --debug-auth + Output all communication related to authentication to standard error. `tx` and `rx` are placed into + the same stream. +"); + +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}; + +use std::default::Default; +use std::str::FromStr; + +use oauth2::{Authenticator, DefaultAuthenticatorDelegate}; +use rustc_serialize::json; + +struct Engine { + opt: Options, + hub: api::Customsearch<hyper::Client, Authenticator<DefaultAuthenticatorDelegate, JsonTokenStorage, hyper::Client>>, +} + + +impl Engine { + fn _cse_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.cse().list(&self.opt.arg_q); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "start" => { + call = call.start(arg_from_str(value.unwrap_or("-0"), err, "start", "integer")); + }, + "sort" => { + call = call.sort(value.unwrap_or("")); + }, + "site-search-filter" => { + call = call.site_search_filter(value.unwrap_or("")); + }, + "site-search" => { + call = call.site_search(value.unwrap_or("")); + }, + "search-type" => { + call = call.search_type(value.unwrap_or("")); + }, + "safe" => { + call = call.safe(value.unwrap_or("")); + }, + "rights" => { + call = call.rights(value.unwrap_or("")); + }, + "related-site" => { + call = call.related_site(value.unwrap_or("")); + }, + "or-terms" => { + call = call.or_terms(value.unwrap_or("")); + }, + "num" => { + call = call.num(arg_from_str(value.unwrap_or("-0"), err, "num", "integer")); + }, + "lr" => { + call = call.lr(value.unwrap_or("")); + }, + "low-range" => { + call = call.low_range(value.unwrap_or("")); + }, + "link-site" => { + call = call.link_site(value.unwrap_or("")); + }, + "img-type" => { + call = call.img_type(value.unwrap_or("")); + }, + "img-size" => { + call = call.img_size(value.unwrap_or("")); + }, + "img-dominant-color" => { + call = call.img_dominant_color(value.unwrap_or("")); + }, + "img-color-type" => { + call = call.img_color_type(value.unwrap_or("")); + }, + "hq" => { + call = call.hq(value.unwrap_or("")); + }, + "hl" => { + call = call.hl(value.unwrap_or("")); + }, + "high-range" => { + call = call.high_range(value.unwrap_or("")); + }, + "googlehost" => { + call = call.googlehost(value.unwrap_or("")); + }, + "gl" => { + call = call.gl(value.unwrap_or("")); + }, + "filter" => { + call = call.filter(value.unwrap_or("")); + }, + "file-type" => { + call = call.file_type(value.unwrap_or("")); + }, + "exclude-terms" => { + call = call.exclude_terms(value.unwrap_or("")); + }, + "exact-terms" => { + call = call.exact_terms(value.unwrap_or("")); + }, + "date-restrict" => { + call = call.date_restrict(value.unwrap_or("")); + }, + "cx" => { + call = call.cx(value.unwrap_or("")); + }, + "cref" => { + call = call.cref(value.unwrap_or("")); + }, + "cr" => { + call = call.cr(value.unwrap_or("")); + }, + "c2coff" => { + call = call.c2coff(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option<api::Error>, Option<InvalidOptionsError>) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option<api::Error>; + let mut err_opt: Option<InvalidOptionsError> = None; + + if self.opt.cmd_cse { + if self.opt.cmd_list { + call_result = self._cse_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else { + unreachable!(); + } + + if dry_run { + if err.issues.len() > 0 { + err_opt = Some(err); + } + } + (call_result, err_opt) + } + + // Please note that this call will fail if any part of the opt can't be handled + fn new(opt: Options) -> Result<Engine, InvalidOptionsError> { + let (config_dir, secret) = { + let config_dir = match cmn::assure_config_dir_exists(&opt.flag_config_dir) { + Err(e) => return Err(InvalidOptionsError::single(e, 3)), + Ok(p) => p, + }; + + match cmn::application_secret_from_directory(&config_dir, "customsearch1-secret.json", + "{\"installed\":{\"auth_uri\":\"https://accounts.google.com/o/oauth2/auth\",\"client_secret\":\"hCsslbCUyfehWMmbkG8vTYxG\",\"token_uri\":\"https://accounts.google.com/o/oauth2/token\",\"client_email\":\"\",\"redirect_uris\":[\"urn:ietf:wg:oauth:2.0:oob\",\"oob\"],\"client_x509_cert_url\":\"\",\"client_id\":\"620010449518-9ngf7o4dhs0dka470npqvor6dc5lqb9b.apps.googleusercontent.com\",\"auth_provider_x509_cert_url\":\"https://www.googleapis.com/oauth2/v1/certs\"}}") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new( &secret, DefaultAuthenticatorDelegate, + if opt.flag_debug_auth { + hyper::Client::with_connector(mock::TeeConnector { + connector: hyper::net::HttpConnector(None) + }) + } else { + hyper::Client::new() + }, + JsonTokenStorage { + program_name: "customsearch1", + db_dir: config_dir.clone(), + }, None); + + let client = + if opt.flag_debug { + hyper::Client::with_connector(mock::TeeConnector { + connector: hyper::net::HttpConnector(None) + }) + } else { + hyper::Client::new() + }; + let engine = Engine { + opt: opt, + hub: api::Customsearch::new(client, auth), + }; + + match engine._doit(true) { + (_, Some(err)) => Err(err), + _ => Ok(engine), + } + } + + // Execute the call with all the bells and whistles, informing the caller only if there was an error. + // The absense of one indicates success. + fn doit(&self) -> Option<api::Error> { + self._doit(false).0 + } +} + +fn main() { + let opts: Options = Options::docopt().decode().unwrap_or_else(|e| e.exit()); + match Engine::new(opts) { + Err(err) => { + writeln!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + writeln!(io::stderr(), "{:?}", err).ok(); + writeln!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/drive2-cli/Cargo.toml b/gen/drive2-cli/Cargo.toml new file mode 100644 index 0000000000..f2e5ed3826 --- /dev/null +++ b/gen/drive2-cli/Cargo.toml @@ -0,0 +1,31 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-drive2-cli" +version = "0.0.1+20150326" +authors = ["Sebastian Thiel <byronimo@gmail.com>"] +description = "A complete library to interact with drive (protocol v2)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/drive2-cli" +homepage = "https://developers.google.com/drive/" +documentation = "http://byron.github.io/google-apis-rs/google_drive2_cli" +license = "MIT" +keywords = ["drive", "google", "cli"] + +[[bin]] +name = "drive2" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "*" +docopt_macros = "*" +rustc-serialize = "*" +yup-hyper-mock = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-drive2] +path = "../drive2" diff --git a/gen/drive2-cli/LICENSE.md b/gen/drive2-cli/LICENSE.md new file mode 100644 index 0000000000..ae22e6ec52 --- /dev/null +++ b/gen/drive2-cli/LICENSE.md @@ -0,0 +1,30 @@ +<!--- +DO NOT EDIT ! +This file was generated automatically from 'src/mako/LICENSE.md.mako' +DO NOT EDIT ! +--> +The MIT License (MIT) +===================== + +Copyright © `2015` `Sebastian Thiel` + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the “Software”), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. diff --git a/gen/drive2-cli/README.md b/gen/drive2-cli/README.md new file mode 100644 index 0000000000..f608701e6a --- /dev/null +++ b/gen/drive2-cli/README.md @@ -0,0 +1,4 @@ +# HELLO DRIVE:V2 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/drive2-cli/mkdocs.yml b/gen/drive2-cli/mkdocs.yml new file mode 100644 index 0000000000..37a34c2823 --- /dev/null +++ b/gen/drive2-cli/mkdocs.yml @@ -0,0 +1,75 @@ +site_name: drive v0.0.1+20150326 +site_url: http://byron.github.io/google-apis-rs/google-drive2-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/drive2-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['about_get.md', 'About', 'Get'] +- ['apps_get.md', 'Apps', 'Get'] +- ['apps_list.md', 'Apps', 'List'] +- ['changes_get.md', 'Changes', 'Get'] +- ['changes_list.md', 'Changes', 'List'] +- ['changes_watch.md', 'Changes', 'Watch'] +- ['channels_stop.md', 'Channels', 'Stop'] +- ['children_delete.md', 'Children', 'Delete'] +- ['children_get.md', 'Children', 'Get'] +- ['children_insert.md', 'Children', 'Insert'] +- ['children_list.md', 'Children', 'List'] +- ['comments_delete.md', 'Comments', 'Delete'] +- ['comments_get.md', 'Comments', 'Get'] +- ['comments_insert.md', 'Comments', 'Insert'] +- ['comments_list.md', 'Comments', 'List'] +- ['comments_patch.md', 'Comments', 'Patch'] +- ['comments_update.md', 'Comments', 'Update'] +- ['files_copy.md', 'Files', 'Copy'] +- ['files_delete.md', 'Files', 'Delete'] +- ['files_empty-trash.md', 'Files', 'Empty Trash'] +- ['files_get.md', 'Files', 'Get'] +- ['files_insert.md', 'Files', 'Insert'] +- ['files_list.md', 'Files', 'List'] +- ['files_patch.md', 'Files', 'Patch'] +- ['files_touch.md', 'Files', 'Touch'] +- ['files_trash.md', 'Files', 'Trash'] +- ['files_untrash.md', 'Files', 'Untrash'] +- ['files_update.md', 'Files', 'Update'] +- ['files_watch.md', 'Files', 'Watch'] +- ['parents_delete.md', 'Parents', 'Delete'] +- ['parents_get.md', 'Parents', 'Get'] +- ['parents_insert.md', 'Parents', 'Insert'] +- ['parents_list.md', 'Parents', 'List'] +- ['permissions_delete.md', 'Permissions', 'Delete'] +- ['permissions_get.md', 'Permissions', 'Get'] +- ['permissions_get-id-for-email.md', 'Permissions', 'Get Id For Email'] +- ['permissions_insert.md', 'Permissions', 'Insert'] +- ['permissions_list.md', 'Permissions', 'List'] +- ['permissions_patch.md', 'Permissions', 'Patch'] +- ['permissions_update.md', 'Permissions', 'Update'] +- ['properties_delete.md', 'Properties', 'Delete'] +- ['properties_get.md', 'Properties', 'Get'] +- ['properties_insert.md', 'Properties', 'Insert'] +- ['properties_list.md', 'Properties', 'List'] +- ['properties_patch.md', 'Properties', 'Patch'] +- ['properties_update.md', 'Properties', 'Update'] +- ['realtime_get.md', 'Realtime', 'Get'] +- ['realtime_update.md', 'Realtime', 'Update'] +- ['replies_delete.md', 'Replies', 'Delete'] +- ['replies_get.md', 'Replies', 'Get'] +- ['replies_insert.md', 'Replies', 'Insert'] +- ['replies_list.md', 'Replies', 'List'] +- ['replies_patch.md', 'Replies', 'Patch'] +- ['replies_update.md', 'Replies', 'Update'] +- ['revisions_delete.md', 'Revisions', 'Delete'] +- ['revisions_get.md', 'Revisions', 'Get'] +- ['revisions_list.md', 'Revisions', 'List'] +- ['revisions_patch.md', 'Revisions', 'Patch'] +- ['revisions_update.md', 'Revisions', 'Update'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/drive2-cli/src/cmn.rs b/gen/drive2-cli/src/cmn.rs new file mode 100644 index 0000000000..a8d3f46368 --- /dev/null +++ b/gen/drive2-cli/src/cmn.rs @@ -0,0 +1,454 @@ +// COPY OF 'src/rust/cli/cmn.rs' +// DO NOT EDIT +use oauth2::{ApplicationSecret, ConsoleApplicationSecret, TokenStorage, Token}; +use rustc_serialize::json; +use mime::Mime; + +use std::fs; +use std::env; +use std::io; +use std::fmt; +use std::path::{Path, PathBuf}; +use std::str::FromStr; +use std::string::ToString; +use std::io::{Write, Read, stdout}; + +use std::default::Default; + +const FIELD_SEP: char = '.'; + +#[derive(Clone, Default)] +pub struct FieldCursor(Vec<String>); + +impl ToString for FieldCursor { + fn to_string(&self) -> String { + self.0.connect(".") + } +} + +impl FieldCursor { + pub fn set(&mut self, value: &str) -> Result<(), CLIError> { + if value.len() == 0 { + return Err(CLIError::Field(FieldError::Empty)) + } + + let mut first_is_field_sep = false; + let mut char_count: usize = 0; + let mut last_c = FIELD_SEP; + let mut num_conscutive_field_seps = 0; + + let mut field = String::new(); + let mut fields = self.0.clone(); + + let push_field = |fs: &mut Vec<String>, f: &mut String| { + if f.len() > 0 { + fs.push(f.clone()); + f.truncate(0); + } + }; + + for (cid, c) in value.chars().enumerate() { + char_count += 1; + + if c == FIELD_SEP { + if cid == 0 { + first_is_field_sep = true; + } + num_conscutive_field_seps += 1; + if cid > 0 && last_c == FIELD_SEP { + if fields.pop().is_none() { + return Err(CLIError::Field(FieldError::PopOnEmpty(value.to_string()))) + } + } else { + push_field(&mut fields, &mut field); + } + } else { + num_conscutive_field_seps = 0; + if cid == 1 { + if first_is_field_sep { + fields.truncate(0); + } + } + field.push(c); + } + + last_c = c; + } + + push_field(&mut fields, &mut field); + + if char_count == 1 && first_is_field_sep { + fields.truncate(0); + } + if char_count > 1 && num_conscutive_field_seps == 1 { + return Err(CLIError::Field(FieldError::TrailingFieldSep(value.to_string()))) + } + + self.0 = fields; + Ok(()) + } + + pub fn num_fields(&self) -> usize { + self.0.len() + } +} + +pub fn parse_kv_arg<'a>(kv: &'a str, err: &mut InvalidOptionsError, for_hashmap: bool) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string(),for_hashmap)); + match kv.find('=') { + None => { + add_err(); + return (kv, None) + }, + Some(pos) => { + let key = &kv[..pos]; + if kv.len() <= pos + 1 { + add_err(); + return (key, None) + } + (key, Some(&kv[pos+1..])) + } + } +} + +pub fn input_file_from_opts(file_path: &str, err: &mut InvalidOptionsError) -> Option<fs::File> { + match fs::File::open(file_path) { + Ok(f) => Some(f), + Err(io_err) => { + err.issues.push(CLIError::Input(InputError::IOError((file_path.to_string(), io_err)))); + None + } + } +} + +pub fn input_mime_from_opts(mime: &str, err: &mut InvalidOptionsError) -> Option<Mime> { + match mime.parse() { + Ok(m) => Some(m), + Err(_) => { + err.issues.push(CLIError::Input(InputError::Mime(mime.to_string()))); + None + } + } +} + +// May panic if we can't open the file - this is anticipated, we can't currently communicate this +// kind of error: TODO: fix this architecture :) +pub fn writer_from_opts(flag: bool, arg: &str) -> Box<Write> { + if !flag || arg == "-" { + Box::new(stdout()) + } else { + Box::new(fs::OpenOptions::new().create(true).write(true).open(arg).unwrap()) + } +} + + +pub fn arg_from_str<T>(arg: &str, err: &mut InvalidOptionsError, + arg_name: &'static str, + arg_type: &'static 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))) + ); + Default::default() + }, + Ok(v) => v, + } +} + +pub struct JsonTokenStorage { + pub program_name: &'static str, + pub db_dir: String, +} + +impl JsonTokenStorage { + fn path(&self, scope_hash: u64) -> PathBuf { + Path::new(&self.db_dir).join(&format!("{}-token-{}.json", self.program_name, scope_hash)) + } +} + +impl TokenStorage for JsonTokenStorage { + type Error = io::Error; + + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, _: &Vec<&str>, token: Option<Token>) -> Option<io::Error> { + match token { + None => { + match fs::remove_file(self.path(scope_hash)) { + Err(err) => + match err.kind() { + io::ErrorKind::NotFound => None, + _ => Some(err) + }, + Ok(_) => None + } + } + Some(token) => { + let json_token = json::encode(&token).unwrap(); + match fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)) { + Ok(mut f) => { + match f.write(json_token.as_bytes()) { + Ok(_) => None, + Err(io_err) => Some(io_err), + } + }, + Err(io_err) => Some(io_err) + } + } + } + } + + fn get(&self, scope_hash: u64, _: &Vec<&str>) -> Result<Option<Token>, io::Error> { + match fs::File::open(&self.path(scope_hash)) { + Ok(mut f) => { + let mut json_string = String::new(); + match f.read_to_string(&mut json_string) { + Ok(_) => Ok(Some(json::decode::<Token>(&json_string).unwrap())), + Err(io_err) => Err(io_err), + } + }, + Err(io_err) => { + match io_err.kind() { + io::ErrorKind::NotFound => Ok(None), + _ => Err(io_err) + } + } + } + } +} + + +#[derive(Debug)] +pub enum ApplicationSecretError { + DecoderError((String, json::DecoderError)), + FormatError(String), +} + +impl fmt::Display for ApplicationSecretError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + match *self { + ApplicationSecretError::DecoderError((ref path, ref err)) + => writeln!(f, "Could not decode file at '{}' with error: {}", + path, err), + ApplicationSecretError::FormatError(ref path) + => writeln!(f, "'installed' field is unset in secret file at '{}'", + path), + } + } +} + +#[derive(Debug)] +pub enum ConfigurationError { + DirectoryCreationFailed((String, io::Error)), + DirectoryUnset, + HomeExpansionFailed(String), + Secret(ApplicationSecretError), + IOError((String, io::Error)), +} + +impl fmt::Display for ConfigurationError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + match *self { + ConfigurationError::DirectoryCreationFailed((ref dir, ref err)) + => writeln!(f, "Directory '{}' could not be created with error: {}", dir, err), + ConfigurationError::DirectoryUnset + => writeln!(f, "--config-dir was unset or empty"), + ConfigurationError::HomeExpansionFailed(ref dir) + => writeln!(f, "Couldn't find HOME directory of current user, failed to expand '{}'", dir), + ConfigurationError::Secret(ref err) + => writeln!(f, "Secret -> {}", err), + ConfigurationError::IOError((ref path, ref err)) + => writeln!(f, "IO operation failed on path '{}' with error: {}", path, err), + } + } +} + +#[derive(Debug)] +pub enum InputError { + IOError((String, io::Error)), + Mime(String), +} + +impl fmt::Display for InputError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + match *self { + InputError::IOError((ref file_path, ref io_err)) + => writeln!(f, "Failed to open '{}' for reading with error: {}", file_path, io_err), + InputError::Mime(ref mime) + => writeln!(f, "'{}' is not a known mime-type", mime), + } + } +} + +#[derive(Debug)] +pub enum FieldError { + PopOnEmpty(String), + TrailingFieldSep(String), + Unknown(String), + Empty, +} + + +impl fmt::Display for FieldError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + match *self { + FieldError::PopOnEmpty(ref field) + => writeln!(f, "'{}': Cannot move up on empty field cursor", field), + FieldError::TrailingFieldSep(ref field) + => writeln!(f, "'{}': Single field separator may not be last character", field), + FieldError::Unknown(ref field) + => writeln!(f, "Field '{}' does not exist", field), + FieldError::Empty + => writeln!(f, "Field names must not be empty"), + } + } +} + + +#[derive(Debug)] +pub enum CLIError { + Configuration(ConfigurationError), + ParseError((&'static str, &'static str, String, String)), + UnknownParameter(String), + InvalidKeyValueSyntax(String, bool), + Input(InputError), + Field(FieldError), +} + +impl fmt::Display for CLIError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + match *self { + CLIError::Configuration(ref err) => write!(f, "Configuration -> {}", err), + CLIError::Input(ref err) => write!(f, "Input -> {}", err), + CLIError::Field(ref err) => write!(f, "Field -> {}", err), + CLIError::ParseError((arg_name, 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) + => writeln!(f, "Parameter '{}' is unknown.", param_name), + CLIError::InvalidKeyValueSyntax(ref kv, is_hashmap) => { + let hashmap_info = if is_hashmap { "hashmap " } else { "" }; + writeln!(f, "'{}' does not match {}pattern <key>=<value>", kv, hashmap_info) + }, + } + } +} + +#[derive(Debug)] +pub struct InvalidOptionsError { + pub issues: Vec<CLIError>, + pub exit_code: i32, +} + +impl fmt::Display for InvalidOptionsError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + for issue in &self.issues { + try!(issue.fmt(f)); + } + Ok(()) + } +} + +impl InvalidOptionsError { + pub fn single(err: CLIError, exit_code: i32) -> InvalidOptionsError { + InvalidOptionsError { + issues: vec![err], + exit_code: exit_code, + } + } + + pub fn new() -> InvalidOptionsError { + InvalidOptionsError { + issues: Vec::new(), + exit_code: 1, + } + } +} + +pub fn assure_config_dir_exists(dir: &str) -> Result<String, CLIError> { + let trdir = dir.trim(); + if trdir.len() == 0 { + return Err(CLIError::Configuration(ConfigurationError::DirectoryUnset)) + } + + let expanded_config_dir = + if trdir.as_bytes()[0] == b'~' { + match env::var("HOME").ok().or(env::var("UserProfile").ok()) { + None => return Err(CLIError::Configuration(ConfigurationError::HomeExpansionFailed(trdir.to_string()))), + Some(mut user) => { + user.push_str(&trdir[1..]); + user + } + } + } else { + trdir.to_string() + }; + + if let Err(err) = fs::create_dir(&expanded_config_dir) { + if err.kind() != io::ErrorKind::AlreadyExists { + return Err(CLIError::Configuration( + ConfigurationError::DirectoryCreationFailed((expanded_config_dir, err)))) + } + } + + Ok(expanded_config_dir) +} + +pub fn application_secret_from_directory(dir: &str, + secret_basename: &str, + json_app_secret: &str) + -> Result<ApplicationSecret, CLIError> { + let secret_path = Path::new(dir).join(secret_basename); + let secret_str = || secret_path.as_path().to_str().unwrap().to_string(); + let secret_io_error = |io_err: io::Error| { + Err(CLIError::Configuration(ConfigurationError::IOError( + (secret_str(), io_err) + ))) + }; + + for _ in 0..2 { + match fs::File::open(&secret_path) { + Err(mut err) => { + if err.kind() == io::ErrorKind::NotFound { + // Write our built-in one - user may adjust the written file at will + + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_app_secret.as_bytes()) { + Err(io_err) => io_err, + Ok(_) => continue, + } + } + }; + // fall through to IO error handling + } + return secret_io_error(err) + }, + Ok(mut f) => { + let mut json_encoded_secret = String::new(); + if let Err(io_err) = f.read_to_string(&mut json_encoded_secret) { + return secret_io_error(io_err) + } + match json::decode::<ConsoleApplicationSecret>(&json_encoded_secret) { + Err(json_decode_error) => return Err(CLIError::Configuration( + ConfigurationError::Secret(ApplicationSecretError::DecoderError( + (secret_str(), json_decode_error) + )))), + Ok(console_secret) => match console_secret.installed { + Some(secret) => return Ok(secret), + None => return Err( + CLIError::Configuration( + ConfigurationError::Secret( + ApplicationSecretError::FormatError(secret_str()) + ))) + }, + } + } + } + } + unreachable!(); +} \ No newline at end of file diff --git a/gen/drive2-cli/src/main.rs b/gen/drive2-cli/src/main.rs new file mode 100644 index 0000000000..fe8a8773c0 --- /dev/null +++ b/gen/drive2-cli/src/main.rs @@ -0,0 +1,6468 @@ +// DO NOT EDIT ! +// This file was generated automatically from 'src/mako/cli/main.rs.mako' +// DO NOT EDIT ! +#![feature(plugin, exit_status)] +#![plugin(docopt_macros)] +#![allow(unused_variables, unused_imports, dead_code, unused_mut)] + +extern crate docopt; +extern crate yup_oauth2 as oauth2; +extern crate yup_hyper_mock as mock; +extern crate rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_drive2 as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + drive2 [options] about get [-p <v>]... [-o <out>] + drive2 [options] apps get <app-id> [-p <v>]... [-o <out>] + drive2 [options] apps list [-p <v>]... [-o <out>] + drive2 [options] changes get <change-id> [-p <v>]... [-o <out>] + drive2 [options] changes list [-p <v>]... [-o <out>] + drive2 [options] changes watch -r <kv>... [-p <v>]... [-o <out>] + drive2 [options] channels stop -r <kv>... [-p <v>]... + drive2 [options] children delete <folder-id> <child-id> [-p <v>]... + drive2 [options] children get <folder-id> <child-id> [-p <v>]... [-o <out>] + drive2 [options] children insert <folder-id> -r <kv>... [-p <v>]... [-o <out>] + drive2 [options] children list <folder-id> [-p <v>]... [-o <out>] + drive2 [options] comments delete <file-id> <comment-id> [-p <v>]... + drive2 [options] comments get <file-id> <comment-id> [-p <v>]... [-o <out>] + drive2 [options] comments insert <file-id> -r <kv>... [-p <v>]... [-o <out>] + drive2 [options] comments list <file-id> [-p <v>]... [-o <out>] + drive2 [options] comments patch <file-id> <comment-id> -r <kv>... [-p <v>]... [-o <out>] + drive2 [options] comments update <file-id> <comment-id> -r <kv>... [-p <v>]... [-o <out>] + drive2 [options] files copy <file-id> -r <kv>... [-p <v>]... [-o <out>] + drive2 [options] files delete <file-id> [-p <v>]... + drive2 [options] files empty-trash [-p <v>]... + drive2 [options] files get <file-id> [-p <v>]... [-o <out>] + drive2 [options] files insert -r <kv>... -u (simple|resumable) <file> <mime> [-p <v>]... [-o <out>] + drive2 [options] files list [-p <v>]... [-o <out>] + drive2 [options] files patch <file-id> -r <kv>... [-p <v>]... [-o <out>] + drive2 [options] files touch <file-id> [-p <v>]... [-o <out>] + drive2 [options] files trash <file-id> [-p <v>]... [-o <out>] + drive2 [options] files untrash <file-id> [-p <v>]... [-o <out>] + drive2 [options] files update <file-id> -r <kv>... -u (simple|resumable) <file> <mime> [-p <v>]... [-o <out>] + drive2 [options] files watch <file-id> -r <kv>... [-p <v>]... [-o <out>] + drive2 [options] parents delete <file-id> <parent-id> [-p <v>]... + drive2 [options] parents get <file-id> <parent-id> [-p <v>]... [-o <out>] + drive2 [options] parents insert <file-id> -r <kv>... [-p <v>]... [-o <out>] + drive2 [options] parents list <file-id> [-p <v>]... [-o <out>] + drive2 [options] permissions delete <file-id> <permission-id> [-p <v>]... + drive2 [options] permissions get <file-id> <permission-id> [-p <v>]... [-o <out>] + drive2 [options] permissions get-id-for-email <email> [-p <v>]... [-o <out>] + drive2 [options] permissions insert <file-id> -r <kv>... [-p <v>]... [-o <out>] + drive2 [options] permissions list <file-id> [-p <v>]... [-o <out>] + drive2 [options] permissions patch <file-id> <permission-id> -r <kv>... [-p <v>]... [-o <out>] + drive2 [options] permissions update <file-id> <permission-id> -r <kv>... [-p <v>]... [-o <out>] + drive2 [options] properties delete <file-id> <property-key> [-p <v>]... + drive2 [options] properties get <file-id> <property-key> [-p <v>]... [-o <out>] + drive2 [options] properties insert <file-id> -r <kv>... [-p <v>]... [-o <out>] + drive2 [options] properties list <file-id> [-p <v>]... [-o <out>] + drive2 [options] properties patch <file-id> <property-key> -r <kv>... [-p <v>]... [-o <out>] + drive2 [options] properties update <file-id> <property-key> -r <kv>... [-p <v>]... [-o <out>] + drive2 [options] realtime get <file-id> [-p <v>]... [-o <out>] + drive2 [options] realtime update <file-id> -u (simple|resumable) <file> <mime> [-p <v>]... + drive2 [options] replies delete <file-id> <comment-id> <reply-id> [-p <v>]... + drive2 [options] replies get <file-id> <comment-id> <reply-id> [-p <v>]... [-o <out>] + drive2 [options] replies insert <file-id> <comment-id> -r <kv>... [-p <v>]... [-o <out>] + drive2 [options] replies list <file-id> <comment-id> [-p <v>]... [-o <out>] + drive2 [options] replies patch <file-id> <comment-id> <reply-id> -r <kv>... [-p <v>]... [-o <out>] + drive2 [options] replies update <file-id> <comment-id> <reply-id> -r <kv>... [-p <v>]... [-o <out>] + drive2 [options] revisions delete <file-id> <revision-id> [-p <v>]... + drive2 [options] revisions get <file-id> <revision-id> [-p <v>]... [-o <out>] + drive2 [options] revisions list <file-id> [-p <v>]... [-o <out>] + drive2 [options] revisions patch <file-id> <revision-id> -r <kv>... [-p <v>]... [-o <out>] + drive2 [options] revisions update <file-id> <revision-id> -r <kv>... [-p <v>]... [-o <out>] + drive2 --help + +All documentation details can be found TODO: <URL to github.io docs here, see #51> + +Configuration: + --scope <url> + 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. + --config-dir <folder> + 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] + --debug + Output all server communication to standard error. `tx` and `rx` are placed into + the same stream. + --debug-auth + Output all communication related to authentication to standard error. `tx` and `rx` are placed into + the same stream. +"); + +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}; + +use std::default::Default; +use std::str::FromStr; + +use oauth2::{Authenticator, DefaultAuthenticatorDelegate}; +use rustc_serialize::json; + +struct Engine { + opt: Options, + hub: api::Drive<hyper::Client, Authenticator<DefaultAuthenticatorDelegate, JsonTokenStorage, hyper::Client>>, +} + + +impl Engine { + fn _about_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.about().get(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "start-change-id" => { + call = call.start_change_id(value.unwrap_or("")); + }, + "max-change-id-count" => { + call = call.max_change_id_count(arg_from_str(value.unwrap_or("-0"), err, "max-change-id-count", "int64")); + }, + "include-subscribed" => { + call = call.include_subscribed(arg_from_str(value.unwrap_or("false"), err, "include-subscribed", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _apps_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.apps().get(&self.opt.arg_app_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _apps_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.apps().list(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "language-code" => { + call = call.language_code(value.unwrap_or("")); + }, + "app-filter-mime-types" => { + call = call.app_filter_mime_types(value.unwrap_or("")); + }, + "app-filter-extensions" => { + call = call.app_filter_extensions(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _changes_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.changes().get(&self.opt.arg_change_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _changes_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.changes().list(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "start-change-id" => { + call = call.start_change_id(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "include-subscribed" => { + call = call.include_subscribed(arg_from_str(value.unwrap_or("false"), err, "include-subscribed", "boolean")); + }, + "include-deleted" => { + call = call.include_deleted(arg_from_str(value.unwrap_or("false"), err, "include-deleted", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _changes_watch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request = api::Channel::default(); + let mut call = self.hub.changes().watch(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "start-change-id" => { + call = call.start_change_id(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "include-subscribed" => { + call = call.include_subscribed(arg_from_str(value.unwrap_or("false"), err, "include-subscribed", "boolean")); + }, + "include-deleted" => { + call = call.include_deleted(arg_from_str(value.unwrap_or("false"), err, "include-deleted", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "resource-uri" => { + request.resource_uri = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "resource-id" => { + request.resource_id = Some(value.unwrap_or("").to_string()); + }, + "payload" => { + request.payload = Some(arg_from_str(value.unwrap_or("false"), err, "payload", "boolean")); + }, + "token" => { + request.token = Some(value.unwrap_or("").to_string()); + }, + "params" => { + if request.params.is_none() { + request.params = Some(Default::default()); + } + let (key, value) = parse_kv_arg(value.unwrap_or(""), err, true); + request.params.as_mut().unwrap().insert(key.to_string(), value.unwrap_or("").to_string()); + }, + "expiration" => { + request.expiration = Some(value.unwrap_or("").to_string()); + }, + "address" => { + request.address = Some(value.unwrap_or("").to_string()); + }, + "type" => { + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _channels_stop(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request = api::Channel::default(); + let mut call = self.hub.channels().stop(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "resource-uri" => { + request.resource_uri = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "resource-id" => { + request.resource_id = Some(value.unwrap_or("").to_string()); + }, + "payload" => { + request.payload = Some(arg_from_str(value.unwrap_or("false"), err, "payload", "boolean")); + }, + "token" => { + request.token = Some(value.unwrap_or("").to_string()); + }, + "params" => { + if request.params.is_none() { + request.params = Some(Default::default()); + } + let (key, value) = parse_kv_arg(value.unwrap_or(""), err, true); + request.params.as_mut().unwrap().insert(key.to_string(), value.unwrap_or("").to_string()); + }, + "expiration" => { + request.expiration = Some(value.unwrap_or("").to_string()); + }, + "address" => { + request.address = Some(value.unwrap_or("").to_string()); + }, + "type" => { + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + None + } + } + } + } + + fn _children_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.children().delete(&self.opt.arg_folder_id, &self.opt.arg_child_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + None + } + } + } + } + + fn _children_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.children().get(&self.opt.arg_folder_id, &self.opt.arg_child_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _children_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request = api::ChildReference::default(); + let mut call = self.hub.children().insert(&request, &self.opt.arg_folder_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "child-link" => { + request.child_link = 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()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _children_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.children().list(&self.opt.arg_folder_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "q" => { + call = call.q(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _comments_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.comments().delete(&self.opt.arg_file_id, &self.opt.arg_comment_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + None + } + } + } + } + + fn _comments_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.comments().get(&self.opt.arg_file_id, &self.opt.arg_comment_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "include-deleted" => { + call = call.include_deleted(arg_from_str(value.unwrap_or("false"), err, "include-deleted", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _comments_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request = api::Comment::default(); + let mut call = self.hub.comments().insert(&request, &self.opt.arg_file_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_author_init(request: &mut api::Comment) { + if request.author.is_none() { + request.author = Some(Default::default()); + } + } + + fn request_author_picture_init(request: &mut api::Comment) { + request_author_init(request); + if request.author.as_mut().unwrap().picture.is_none() { + request.author.as_mut().unwrap().picture = Some(Default::default()); + } + } + + fn request_context_init(request: &mut api::Comment) { + if request.context.is_none() { + request.context = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "status" => { + request.status = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "author.picture.url" => { + request_author_picture_init(&mut request); + request.author.as_mut().unwrap().picture.as_mut().unwrap().url = Some(value.unwrap_or("").to_string()); + }, + "author.kind" => { + request_author_picture_init(&mut request); + request.author.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "author.display-name" => { + request_author_picture_init(&mut request); + request.author.as_mut().unwrap().display_name = Some(value.unwrap_or("").to_string()); + }, + "author.permission-id" => { + request_author_picture_init(&mut request); + request.author.as_mut().unwrap().permission_id = Some(value.unwrap_or("").to_string()); + }, + "author.is-authenticated-user" => { + request_author_picture_init(&mut request); + request.author.as_mut().unwrap().is_authenticated_user = Some(arg_from_str(value.unwrap_or("false"), err, "author.is-authenticated-user", "boolean")); + }, + "author.email-address" => { + request_author_picture_init(&mut request); + request.author.as_mut().unwrap().email_address = Some(value.unwrap_or("").to_string()); + }, + "deleted" => { + request_author_init(&mut request); + request.deleted = Some(arg_from_str(value.unwrap_or("false"), err, "deleted", "boolean")); + }, + "html-content" => { + request_author_init(&mut request); + request.html_content = Some(value.unwrap_or("").to_string()); + }, + "file-title" => { + request_author_init(&mut request); + request.file_title = Some(value.unwrap_or("").to_string()); + }, + "content" => { + request_author_init(&mut request); + request.content = Some(value.unwrap_or("").to_string()); + }, + "modified-date" => { + request_author_init(&mut request); + request.modified_date = Some(value.unwrap_or("").to_string()); + }, + "context.type" => { + request_context_init(&mut request); + request.context.as_mut().unwrap().type_ = Some(value.unwrap_or("").to_string()); + }, + "context.value" => { + request_context_init(&mut request); + request.context.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "created-date" => { + request_context_init(&mut request); + request.created_date = Some(value.unwrap_or("").to_string()); + }, + "comment-id" => { + request_context_init(&mut request); + request.comment_id = Some(value.unwrap_or("").to_string()); + }, + "anchor" => { + request_context_init(&mut request); + request.anchor = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_context_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "file-id" => { + request_context_init(&mut request); + request.file_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _comments_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.comments().list(&self.opt.arg_file_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "updated-min" => { + call = call.updated_min(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "include-deleted" => { + call = call.include_deleted(arg_from_str(value.unwrap_or("false"), err, "include-deleted", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _comments_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request = api::Comment::default(); + let mut call = self.hub.comments().patch(&request, &self.opt.arg_file_id, &self.opt.arg_comment_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_author_init(request: &mut api::Comment) { + if request.author.is_none() { + request.author = Some(Default::default()); + } + } + + fn request_author_picture_init(request: &mut api::Comment) { + request_author_init(request); + if request.author.as_mut().unwrap().picture.is_none() { + request.author.as_mut().unwrap().picture = Some(Default::default()); + } + } + + fn request_context_init(request: &mut api::Comment) { + if request.context.is_none() { + request.context = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "status" => { + request.status = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "author.picture.url" => { + request_author_picture_init(&mut request); + request.author.as_mut().unwrap().picture.as_mut().unwrap().url = Some(value.unwrap_or("").to_string()); + }, + "author.kind" => { + request_author_picture_init(&mut request); + request.author.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "author.display-name" => { + request_author_picture_init(&mut request); + request.author.as_mut().unwrap().display_name = Some(value.unwrap_or("").to_string()); + }, + "author.permission-id" => { + request_author_picture_init(&mut request); + request.author.as_mut().unwrap().permission_id = Some(value.unwrap_or("").to_string()); + }, + "author.is-authenticated-user" => { + request_author_picture_init(&mut request); + request.author.as_mut().unwrap().is_authenticated_user = Some(arg_from_str(value.unwrap_or("false"), err, "author.is-authenticated-user", "boolean")); + }, + "author.email-address" => { + request_author_picture_init(&mut request); + request.author.as_mut().unwrap().email_address = Some(value.unwrap_or("").to_string()); + }, + "deleted" => { + request_author_init(&mut request); + request.deleted = Some(arg_from_str(value.unwrap_or("false"), err, "deleted", "boolean")); + }, + "html-content" => { + request_author_init(&mut request); + request.html_content = Some(value.unwrap_or("").to_string()); + }, + "file-title" => { + request_author_init(&mut request); + request.file_title = Some(value.unwrap_or("").to_string()); + }, + "content" => { + request_author_init(&mut request); + request.content = Some(value.unwrap_or("").to_string()); + }, + "modified-date" => { + request_author_init(&mut request); + request.modified_date = Some(value.unwrap_or("").to_string()); + }, + "context.type" => { + request_context_init(&mut request); + request.context.as_mut().unwrap().type_ = Some(value.unwrap_or("").to_string()); + }, + "context.value" => { + request_context_init(&mut request); + request.context.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "created-date" => { + request_context_init(&mut request); + request.created_date = Some(value.unwrap_or("").to_string()); + }, + "comment-id" => { + request_context_init(&mut request); + request.comment_id = Some(value.unwrap_or("").to_string()); + }, + "anchor" => { + request_context_init(&mut request); + request.anchor = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_context_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "file-id" => { + request_context_init(&mut request); + request.file_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _comments_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request = api::Comment::default(); + let mut call = self.hub.comments().update(&request, &self.opt.arg_file_id, &self.opt.arg_comment_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_author_init(request: &mut api::Comment) { + if request.author.is_none() { + request.author = Some(Default::default()); + } + } + + fn request_author_picture_init(request: &mut api::Comment) { + request_author_init(request); + if request.author.as_mut().unwrap().picture.is_none() { + request.author.as_mut().unwrap().picture = Some(Default::default()); + } + } + + fn request_context_init(request: &mut api::Comment) { + if request.context.is_none() { + request.context = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "status" => { + request.status = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "author.picture.url" => { + request_author_picture_init(&mut request); + request.author.as_mut().unwrap().picture.as_mut().unwrap().url = Some(value.unwrap_or("").to_string()); + }, + "author.kind" => { + request_author_picture_init(&mut request); + request.author.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "author.display-name" => { + request_author_picture_init(&mut request); + request.author.as_mut().unwrap().display_name = Some(value.unwrap_or("").to_string()); + }, + "author.permission-id" => { + request_author_picture_init(&mut request); + request.author.as_mut().unwrap().permission_id = Some(value.unwrap_or("").to_string()); + }, + "author.is-authenticated-user" => { + request_author_picture_init(&mut request); + request.author.as_mut().unwrap().is_authenticated_user = Some(arg_from_str(value.unwrap_or("false"), err, "author.is-authenticated-user", "boolean")); + }, + "author.email-address" => { + request_author_picture_init(&mut request); + request.author.as_mut().unwrap().email_address = Some(value.unwrap_or("").to_string()); + }, + "deleted" => { + request_author_init(&mut request); + request.deleted = Some(arg_from_str(value.unwrap_or("false"), err, "deleted", "boolean")); + }, + "html-content" => { + request_author_init(&mut request); + request.html_content = Some(value.unwrap_or("").to_string()); + }, + "file-title" => { + request_author_init(&mut request); + request.file_title = Some(value.unwrap_or("").to_string()); + }, + "content" => { + request_author_init(&mut request); + request.content = Some(value.unwrap_or("").to_string()); + }, + "modified-date" => { + request_author_init(&mut request); + request.modified_date = Some(value.unwrap_or("").to_string()); + }, + "context.type" => { + request_context_init(&mut request); + request.context.as_mut().unwrap().type_ = Some(value.unwrap_or("").to_string()); + }, + "context.value" => { + request_context_init(&mut request); + request.context.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "created-date" => { + request_context_init(&mut request); + request.created_date = Some(value.unwrap_or("").to_string()); + }, + "comment-id" => { + request_context_init(&mut request); + request.comment_id = Some(value.unwrap_or("").to_string()); + }, + "anchor" => { + request_context_init(&mut request); + request.anchor = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_context_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "file-id" => { + request_context_init(&mut request); + request.file_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _files_copy(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request = api::File::default(); + let mut call = self.hub.files().copy(&request, &self.opt.arg_file_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "visibility" => { + call = call.visibility(value.unwrap_or("")); + }, + "timed-text-track-name" => { + call = call.timed_text_track_name(value.unwrap_or("")); + }, + "timed-text-language" => { + call = call.timed_text_language(value.unwrap_or("")); + }, + "pinned" => { + call = call.pinned(arg_from_str(value.unwrap_or("false"), err, "pinned", "boolean")); + }, + "ocr-language" => { + call = call.ocr_language(value.unwrap_or("")); + }, + "ocr" => { + call = call.ocr(arg_from_str(value.unwrap_or("false"), err, "ocr", "boolean")); + }, + "convert" => { + call = call.convert(arg_from_str(value.unwrap_or("false"), err, "convert", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_image_media_metadata_init(request: &mut api::File) { + if request.image_media_metadata.is_none() { + request.image_media_metadata = Some(Default::default()); + } + } + + fn request_image_media_metadata_location_init(request: &mut api::File) { + request_image_media_metadata_init(request); + if request.image_media_metadata.as_mut().unwrap().location.is_none() { + request.image_media_metadata.as_mut().unwrap().location = Some(Default::default()); + } + } + + fn request_indexable_text_init(request: &mut api::File) { + if request.indexable_text.is_none() { + request.indexable_text = Some(Default::default()); + } + } + + fn request_labels_init(request: &mut api::File) { + if request.labels.is_none() { + request.labels = Some(Default::default()); + } + } + + fn request_last_modifying_user_init(request: &mut api::File) { + if request.last_modifying_user.is_none() { + request.last_modifying_user = Some(Default::default()); + } + } + + fn request_last_modifying_user_picture_init(request: &mut api::File) { + request_last_modifying_user_init(request); + if request.last_modifying_user.as_mut().unwrap().picture.is_none() { + request.last_modifying_user.as_mut().unwrap().picture = Some(Default::default()); + } + } + + fn request_sharing_user_init(request: &mut api::File) { + if request.sharing_user.is_none() { + request.sharing_user = Some(Default::default()); + } + } + + fn request_sharing_user_picture_init(request: &mut api::File) { + request_sharing_user_init(request); + if request.sharing_user.as_mut().unwrap().picture.is_none() { + request.sharing_user.as_mut().unwrap().picture = Some(Default::default()); + } + } + + fn request_thumbnail_init(request: &mut api::File) { + if request.thumbnail.is_none() { + request.thumbnail = Some(Default::default()); + } + } + + fn request_user_permission_init(request: &mut api::File) { + if request.user_permission.is_none() { + request.user_permission = Some(Default::default()); + } + } + + fn request_video_media_metadata_init(request: &mut api::File) { + if request.video_media_metadata.is_none() { + request.video_media_metadata = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "mime-type" => { + request.mime_type = Some(value.unwrap_or("").to_string()); + }, + "last-viewed-by-me-date" => { + request.last_viewed_by_me_date = Some(value.unwrap_or("").to_string()); + }, + "app-data-contents" => { + request.app_data_contents = Some(arg_from_str(value.unwrap_or("false"), err, "app-data-contents", "boolean")); + }, + "thumbnail-link" => { + request.thumbnail_link = Some(value.unwrap_or("").to_string()); + }, + "labels.restricted" => { + request_labels_init(&mut request); + request.labels.as_mut().unwrap().restricted = Some(arg_from_str(value.unwrap_or("false"), err, "labels.restricted", "boolean")); + }, + "labels.hidden" => { + request_labels_init(&mut request); + request.labels.as_mut().unwrap().hidden = Some(arg_from_str(value.unwrap_or("false"), err, "labels.hidden", "boolean")); + }, + "labels.viewed" => { + request_labels_init(&mut request); + request.labels.as_mut().unwrap().viewed = Some(arg_from_str(value.unwrap_or("false"), err, "labels.viewed", "boolean")); + }, + "labels.starred" => { + request_labels_init(&mut request); + request.labels.as_mut().unwrap().starred = Some(arg_from_str(value.unwrap_or("false"), err, "labels.starred", "boolean")); + }, + "labels.trashed" => { + request_labels_init(&mut request); + request.labels.as_mut().unwrap().trashed = Some(arg_from_str(value.unwrap_or("false"), err, "labels.trashed", "boolean")); + }, + "indexable-text.text" => { + request_indexable_text_init(&mut request); + request.indexable_text.as_mut().unwrap().text = Some(value.unwrap_or("").to_string()); + }, + "explicitly-trashed" => { + request_indexable_text_init(&mut request); + request.explicitly_trashed = Some(arg_from_str(value.unwrap_or("false"), err, "explicitly-trashed", "boolean")); + }, + "etag" => { + request_indexable_text_init(&mut request); + request.etag = Some(value.unwrap_or("").to_string()); + }, + "last-modifying-user-name" => { + request_indexable_text_init(&mut request); + request.last_modifying_user_name = Some(value.unwrap_or("").to_string()); + }, + "writers-can-share" => { + request_indexable_text_init(&mut request); + request.writers_can_share = Some(arg_from_str(value.unwrap_or("false"), err, "writers-can-share", "boolean")); + }, + "id" => { + request_indexable_text_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "sharing-user.picture.url" => { + request_sharing_user_picture_init(&mut request); + request.sharing_user.as_mut().unwrap().picture.as_mut().unwrap().url = Some(value.unwrap_or("").to_string()); + }, + "sharing-user.kind" => { + request_sharing_user_picture_init(&mut request); + request.sharing_user.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "sharing-user.display-name" => { + request_sharing_user_picture_init(&mut request); + request.sharing_user.as_mut().unwrap().display_name = Some(value.unwrap_or("").to_string()); + }, + "sharing-user.permission-id" => { + request_sharing_user_picture_init(&mut request); + request.sharing_user.as_mut().unwrap().permission_id = Some(value.unwrap_or("").to_string()); + }, + "sharing-user.is-authenticated-user" => { + request_sharing_user_picture_init(&mut request); + request.sharing_user.as_mut().unwrap().is_authenticated_user = Some(arg_from_str(value.unwrap_or("false"), err, "sharing-user.is-authenticated-user", "boolean")); + }, + "sharing-user.email-address" => { + request_sharing_user_picture_init(&mut request); + request.sharing_user.as_mut().unwrap().email_address = Some(value.unwrap_or("").to_string()); + }, + "video-media-metadata.width" => { + request_video_media_metadata_init(&mut request); + request.video_media_metadata.as_mut().unwrap().width = Some(arg_from_str(value.unwrap_or("-0"), err, "video-media-metadata.width", "integer")); + }, + "video-media-metadata.duration-millis" => { + request_video_media_metadata_init(&mut request); + request.video_media_metadata.as_mut().unwrap().duration_millis = Some(value.unwrap_or("").to_string()); + }, + "video-media-metadata.height" => { + request_video_media_metadata_init(&mut request); + request.video_media_metadata.as_mut().unwrap().height = Some(arg_from_str(value.unwrap_or("-0"), err, "video-media-metadata.height", "integer")); + }, + "last-modifying-user.picture.url" => { + request_last_modifying_user_picture_init(&mut request); + request.last_modifying_user.as_mut().unwrap().picture.as_mut().unwrap().url = Some(value.unwrap_or("").to_string()); + }, + "last-modifying-user.kind" => { + request_last_modifying_user_picture_init(&mut request); + request.last_modifying_user.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "last-modifying-user.display-name" => { + request_last_modifying_user_picture_init(&mut request); + request.last_modifying_user.as_mut().unwrap().display_name = Some(value.unwrap_or("").to_string()); + }, + "last-modifying-user.permission-id" => { + request_last_modifying_user_picture_init(&mut request); + request.last_modifying_user.as_mut().unwrap().permission_id = Some(value.unwrap_or("").to_string()); + }, + "last-modifying-user.is-authenticated-user" => { + request_last_modifying_user_picture_init(&mut request); + request.last_modifying_user.as_mut().unwrap().is_authenticated_user = Some(arg_from_str(value.unwrap_or("false"), err, "last-modifying-user.is-authenticated-user", "boolean")); + }, + "last-modifying-user.email-address" => { + request_last_modifying_user_picture_init(&mut request); + request.last_modifying_user.as_mut().unwrap().email_address = Some(value.unwrap_or("").to_string()); + }, + "copyable" => { + request_last_modifying_user_init(&mut request); + request.copyable = Some(arg_from_str(value.unwrap_or("false"), err, "copyable", "boolean")); + }, + "folder-color-rgb" => { + request_last_modifying_user_init(&mut request); + request.folder_color_rgb = Some(value.unwrap_or("").to_string()); + }, + "owner-names" => { + request_last_modifying_user_init(&mut request); + if request.owner_names.is_none() { + request.owner_names = Some(Default::default()); + } + request.owner_names.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "shared-with-me-date" => { + request_last_modifying_user_init(&mut request); + request.shared_with_me_date = Some(value.unwrap_or("").to_string()); + }, + "web-view-link" => { + request_last_modifying_user_init(&mut request); + request.web_view_link = Some(value.unwrap_or("").to_string()); + }, + "version" => { + request_last_modifying_user_init(&mut request); + request.version = Some(value.unwrap_or("").to_string()); + }, + "export-links" => { + request_last_modifying_user_init(&mut request); + if request.export_links.is_none() { + request.export_links = Some(Default::default()); + } + let (key, value) = parse_kv_arg(value.unwrap_or(""), err, true); + request.export_links.as_mut().unwrap().insert(key.to_string(), value.unwrap_or("").to_string()); + }, + "shared" => { + request_last_modifying_user_init(&mut request); + request.shared = Some(arg_from_str(value.unwrap_or("false"), err, "shared", "boolean")); + }, + "thumbnail.mime-type" => { + request_thumbnail_init(&mut request); + request.thumbnail.as_mut().unwrap().mime_type = Some(value.unwrap_or("").to_string()); + }, + "thumbnail.image" => { + request_thumbnail_init(&mut request); + request.thumbnail.as_mut().unwrap().image = Some(value.unwrap_or("").to_string()); + }, + "open-with-links" => { + request_thumbnail_init(&mut request); + if request.open_with_links.is_none() { + request.open_with_links = Some(Default::default()); + } + let (key, value) = parse_kv_arg(value.unwrap_or(""), err, true); + request.open_with_links.as_mut().unwrap().insert(key.to_string(), value.unwrap_or("").to_string()); + }, + "image-media-metadata.exposure-bias" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().exposure_bias = Some(arg_from_str(value.unwrap_or("0.0"), err, "image-media-metadata.exposure-bias", "number")); + }, + "image-media-metadata.exposure-time" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().exposure_time = Some(arg_from_str(value.unwrap_or("0.0"), err, "image-media-metadata.exposure-time", "number")); + }, + "image-media-metadata.max-aperture-value" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().max_aperture_value = Some(arg_from_str(value.unwrap_or("0.0"), err, "image-media-metadata.max-aperture-value", "number")); + }, + "image-media-metadata.width" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().width = Some(arg_from_str(value.unwrap_or("-0"), err, "image-media-metadata.width", "integer")); + }, + "image-media-metadata.focal-length" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().focal_length = Some(arg_from_str(value.unwrap_or("0.0"), err, "image-media-metadata.focal-length", "number")); + }, + "image-media-metadata.camera-make" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().camera_make = Some(value.unwrap_or("").to_string()); + }, + "image-media-metadata.exposure-mode" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().exposure_mode = Some(value.unwrap_or("").to_string()); + }, + "image-media-metadata.color-space" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().color_space = Some(value.unwrap_or("").to_string()); + }, + "image-media-metadata.location.latitude" => { + request_image_media_metadata_location_init(&mut request); + request.image_media_metadata.as_mut().unwrap().location.as_mut().unwrap().latitude = Some(arg_from_str(value.unwrap_or("0.0"), err, "image-media-metadata.location.latitude", "number")); + }, + "image-media-metadata.location.altitude" => { + request_image_media_metadata_location_init(&mut request); + request.image_media_metadata.as_mut().unwrap().location.as_mut().unwrap().altitude = Some(arg_from_str(value.unwrap_or("0.0"), err, "image-media-metadata.location.altitude", "number")); + }, + "image-media-metadata.location.longitude" => { + request_image_media_metadata_location_init(&mut request); + request.image_media_metadata.as_mut().unwrap().location.as_mut().unwrap().longitude = Some(arg_from_str(value.unwrap_or("0.0"), err, "image-media-metadata.location.longitude", "number")); + }, + "image-media-metadata.subject-distance" => { + request_image_media_metadata_location_init(&mut request); + request.image_media_metadata.as_mut().unwrap().subject_distance = Some(arg_from_str(value.unwrap_or("-0"), err, "image-media-metadata.subject-distance", "integer")); + }, + "image-media-metadata.height" => { + request_image_media_metadata_location_init(&mut request); + request.image_media_metadata.as_mut().unwrap().height = Some(arg_from_str(value.unwrap_or("-0"), err, "image-media-metadata.height", "integer")); + }, + "image-media-metadata.lens" => { + request_image_media_metadata_location_init(&mut request); + request.image_media_metadata.as_mut().unwrap().lens = Some(value.unwrap_or("").to_string()); + }, + "image-media-metadata.date" => { + request_image_media_metadata_location_init(&mut request); + request.image_media_metadata.as_mut().unwrap().date = Some(value.unwrap_or("").to_string()); + }, + "image-media-metadata.iso-speed" => { + request_image_media_metadata_location_init(&mut request); + request.image_media_metadata.as_mut().unwrap().iso_speed = Some(arg_from_str(value.unwrap_or("-0"), err, "image-media-metadata.iso-speed", "integer")); + }, + "image-media-metadata.metering-mode" => { + request_image_media_metadata_location_init(&mut request); + request.image_media_metadata.as_mut().unwrap().metering_mode = Some(value.unwrap_or("").to_string()); + }, + "image-media-metadata.flash-used" => { + request_image_media_metadata_location_init(&mut request); + request.image_media_metadata.as_mut().unwrap().flash_used = Some(arg_from_str(value.unwrap_or("false"), err, "image-media-metadata.flash-used", "boolean")); + }, + "image-media-metadata.aperture" => { + request_image_media_metadata_location_init(&mut request); + request.image_media_metadata.as_mut().unwrap().aperture = Some(arg_from_str(value.unwrap_or("0.0"), err, "image-media-metadata.aperture", "number")); + }, + "image-media-metadata.rotation" => { + request_image_media_metadata_location_init(&mut request); + request.image_media_metadata.as_mut().unwrap().rotation = Some(arg_from_str(value.unwrap_or("-0"), err, "image-media-metadata.rotation", "integer")); + }, + "image-media-metadata.sensor" => { + request_image_media_metadata_location_init(&mut request); + request.image_media_metadata.as_mut().unwrap().sensor = Some(value.unwrap_or("").to_string()); + }, + "image-media-metadata.white-balance" => { + request_image_media_metadata_location_init(&mut request); + request.image_media_metadata.as_mut().unwrap().white_balance = Some(value.unwrap_or("").to_string()); + }, + "image-media-metadata.camera-model" => { + request_image_media_metadata_location_init(&mut request); + request.image_media_metadata.as_mut().unwrap().camera_model = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request_image_media_metadata_init(&mut request); + request.description = Some(value.unwrap_or("").to_string()); + }, + "web-content-link" => { + request_image_media_metadata_init(&mut request); + request.web_content_link = Some(value.unwrap_or("").to_string()); + }, + "editable" => { + request_image_media_metadata_init(&mut request); + request.editable = Some(arg_from_str(value.unwrap_or("false"), err, "editable", "boolean")); + }, + "embed-link" => { + request_image_media_metadata_init(&mut request); + request.embed_link = Some(value.unwrap_or("").to_string()); + }, + "marked-viewed-by-me-date" => { + request_image_media_metadata_init(&mut request); + request.marked_viewed_by_me_date = Some(value.unwrap_or("").to_string()); + }, + "quota-bytes-used" => { + request_image_media_metadata_init(&mut request); + request.quota_bytes_used = Some(value.unwrap_or("").to_string()); + }, + "file-size" => { + request_image_media_metadata_init(&mut request); + request.file_size = Some(value.unwrap_or("").to_string()); + }, + "created-date" => { + request_image_media_metadata_init(&mut request); + request.created_date = Some(value.unwrap_or("").to_string()); + }, + "md5-checksum" => { + request_image_media_metadata_init(&mut request); + request.md5_checksum = Some(value.unwrap_or("").to_string()); + }, + "icon-link" => { + request_image_media_metadata_init(&mut request); + request.icon_link = Some(value.unwrap_or("").to_string()); + }, + "default-open-with-link" => { + request_image_media_metadata_init(&mut request); + request.default_open_with_link = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request_image_media_metadata_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "alternate-link" => { + request_image_media_metadata_init(&mut request); + request.alternate_link = Some(value.unwrap_or("").to_string()); + }, + "title" => { + request_image_media_metadata_init(&mut request); + request.title = Some(value.unwrap_or("").to_string()); + }, + "modified-by-me-date" => { + request_image_media_metadata_init(&mut request); + request.modified_by_me_date = Some(value.unwrap_or("").to_string()); + }, + "download-url" => { + request_image_media_metadata_init(&mut request); + request.download_url = Some(value.unwrap_or("").to_string()); + }, + "user-permission.with-link" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().with_link = Some(arg_from_str(value.unwrap_or("false"), err, "user-permission.with-link", "boolean")); + }, + "user-permission.domain" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().domain = Some(value.unwrap_or("").to_string()); + }, + "user-permission.name" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().name = Some(value.unwrap_or("").to_string()); + }, + "user-permission.kind" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "user-permission.value" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "user-permission.id" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "user-permission.auth-key" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().auth_key = Some(value.unwrap_or("").to_string()); + }, + "user-permission.etag" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "user-permission.email-address" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().email_address = Some(value.unwrap_or("").to_string()); + }, + "user-permission.photo-link" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().photo_link = Some(value.unwrap_or("").to_string()); + }, + "user-permission.role" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().role = Some(value.unwrap_or("").to_string()); + }, + "user-permission.type" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().type_ = Some(value.unwrap_or("").to_string()); + }, + "user-permission.additional-roles" => { + request_user_permission_init(&mut request); + if request.user_permission.as_mut().unwrap().additional_roles.is_none() { + request.user_permission.as_mut().unwrap().additional_roles = Some(Default::default()); + } + request.user_permission.as_mut().unwrap().additional_roles.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "user-permission.self-link" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().self_link = Some(value.unwrap_or("").to_string()); + }, + "original-filename" => { + request_user_permission_init(&mut request); + request.original_filename = Some(value.unwrap_or("").to_string()); + }, + "file-extension" => { + request_user_permission_init(&mut request); + request.file_extension = Some(value.unwrap_or("").to_string()); + }, + "head-revision-id" => { + request_user_permission_init(&mut request); + request.head_revision_id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_user_permission_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "modified-date" => { + request_user_permission_init(&mut request); + request.modified_date = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _files_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.files().delete(&self.opt.arg_file_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + None + } + } + } + } + + fn _files_empty_trash(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.files().empty_trash(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + None + } + } + } + } + + fn _files_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut download_mode = false; + let mut call = self.hub.files().get(&self.opt.arg_file_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "update-viewed-date" => { + call = call.update_viewed_date(arg_from_str(value.unwrap_or("false"), err, "update-viewed-date", "boolean")); + }, + "revision-id" => { + call = call.revision_id(value.unwrap_or("")); + }, + "projection" => { + call = call.projection(value.unwrap_or("")); + }, + "acknowledge-abuse" => { + call = call.acknowledge_abuse(arg_from_str(value.unwrap_or("false"), err, "acknowledge-abuse", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + if key == "alt" && value.unwrap_or("unset") == "media" { + download_mode = true; + } + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + if !download_mode { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + } else { + io::copy(&mut response, &mut ostream).unwrap(); + } + None + } + } + } + } + + fn _files_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request = api::File::default(); + let mut call = self.hub.files().insert(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "visibility" => { + call = call.visibility(value.unwrap_or("")); + }, + "use-content-as-indexable-text" => { + call = call.use_content_as_indexable_text(arg_from_str(value.unwrap_or("false"), err, "use-content-as-indexable-text", "boolean")); + }, + "timed-text-track-name" => { + call = call.timed_text_track_name(value.unwrap_or("")); + }, + "timed-text-language" => { + call = call.timed_text_language(value.unwrap_or("")); + }, + "pinned" => { + call = call.pinned(arg_from_str(value.unwrap_or("false"), err, "pinned", "boolean")); + }, + "ocr-language" => { + call = call.ocr_language(value.unwrap_or("")); + }, + "ocr" => { + call = call.ocr(arg_from_str(value.unwrap_or("false"), err, "ocr", "boolean")); + }, + "convert" => { + call = call.convert(arg_from_str(value.unwrap_or("false"), err, "convert", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_image_media_metadata_init(request: &mut api::File) { + if request.image_media_metadata.is_none() { + request.image_media_metadata = Some(Default::default()); + } + } + + fn request_image_media_metadata_location_init(request: &mut api::File) { + request_image_media_metadata_init(request); + if request.image_media_metadata.as_mut().unwrap().location.is_none() { + request.image_media_metadata.as_mut().unwrap().location = Some(Default::default()); + } + } + + fn request_indexable_text_init(request: &mut api::File) { + if request.indexable_text.is_none() { + request.indexable_text = Some(Default::default()); + } + } + + fn request_labels_init(request: &mut api::File) { + if request.labels.is_none() { + request.labels = Some(Default::default()); + } + } + + fn request_last_modifying_user_init(request: &mut api::File) { + if request.last_modifying_user.is_none() { + request.last_modifying_user = Some(Default::default()); + } + } + + fn request_last_modifying_user_picture_init(request: &mut api::File) { + request_last_modifying_user_init(request); + if request.last_modifying_user.as_mut().unwrap().picture.is_none() { + request.last_modifying_user.as_mut().unwrap().picture = Some(Default::default()); + } + } + + fn request_sharing_user_init(request: &mut api::File) { + if request.sharing_user.is_none() { + request.sharing_user = Some(Default::default()); + } + } + + fn request_sharing_user_picture_init(request: &mut api::File) { + request_sharing_user_init(request); + if request.sharing_user.as_mut().unwrap().picture.is_none() { + request.sharing_user.as_mut().unwrap().picture = Some(Default::default()); + } + } + + fn request_thumbnail_init(request: &mut api::File) { + if request.thumbnail.is_none() { + request.thumbnail = Some(Default::default()); + } + } + + fn request_user_permission_init(request: &mut api::File) { + if request.user_permission.is_none() { + request.user_permission = Some(Default::default()); + } + } + + fn request_video_media_metadata_init(request: &mut api::File) { + if request.video_media_metadata.is_none() { + request.video_media_metadata = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "mime-type" => { + request.mime_type = Some(value.unwrap_or("").to_string()); + }, + "last-viewed-by-me-date" => { + request.last_viewed_by_me_date = Some(value.unwrap_or("").to_string()); + }, + "app-data-contents" => { + request.app_data_contents = Some(arg_from_str(value.unwrap_or("false"), err, "app-data-contents", "boolean")); + }, + "thumbnail-link" => { + request.thumbnail_link = Some(value.unwrap_or("").to_string()); + }, + "labels.restricted" => { + request_labels_init(&mut request); + request.labels.as_mut().unwrap().restricted = Some(arg_from_str(value.unwrap_or("false"), err, "labels.restricted", "boolean")); + }, + "labels.hidden" => { + request_labels_init(&mut request); + request.labels.as_mut().unwrap().hidden = Some(arg_from_str(value.unwrap_or("false"), err, "labels.hidden", "boolean")); + }, + "labels.viewed" => { + request_labels_init(&mut request); + request.labels.as_mut().unwrap().viewed = Some(arg_from_str(value.unwrap_or("false"), err, "labels.viewed", "boolean")); + }, + "labels.starred" => { + request_labels_init(&mut request); + request.labels.as_mut().unwrap().starred = Some(arg_from_str(value.unwrap_or("false"), err, "labels.starred", "boolean")); + }, + "labels.trashed" => { + request_labels_init(&mut request); + request.labels.as_mut().unwrap().trashed = Some(arg_from_str(value.unwrap_or("false"), err, "labels.trashed", "boolean")); + }, + "indexable-text.text" => { + request_indexable_text_init(&mut request); + request.indexable_text.as_mut().unwrap().text = Some(value.unwrap_or("").to_string()); + }, + "explicitly-trashed" => { + request_indexable_text_init(&mut request); + request.explicitly_trashed = Some(arg_from_str(value.unwrap_or("false"), err, "explicitly-trashed", "boolean")); + }, + "etag" => { + request_indexable_text_init(&mut request); + request.etag = Some(value.unwrap_or("").to_string()); + }, + "last-modifying-user-name" => { + request_indexable_text_init(&mut request); + request.last_modifying_user_name = Some(value.unwrap_or("").to_string()); + }, + "writers-can-share" => { + request_indexable_text_init(&mut request); + request.writers_can_share = Some(arg_from_str(value.unwrap_or("false"), err, "writers-can-share", "boolean")); + }, + "id" => { + request_indexable_text_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "sharing-user.picture.url" => { + request_sharing_user_picture_init(&mut request); + request.sharing_user.as_mut().unwrap().picture.as_mut().unwrap().url = Some(value.unwrap_or("").to_string()); + }, + "sharing-user.kind" => { + request_sharing_user_picture_init(&mut request); + request.sharing_user.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "sharing-user.display-name" => { + request_sharing_user_picture_init(&mut request); + request.sharing_user.as_mut().unwrap().display_name = Some(value.unwrap_or("").to_string()); + }, + "sharing-user.permission-id" => { + request_sharing_user_picture_init(&mut request); + request.sharing_user.as_mut().unwrap().permission_id = Some(value.unwrap_or("").to_string()); + }, + "sharing-user.is-authenticated-user" => { + request_sharing_user_picture_init(&mut request); + request.sharing_user.as_mut().unwrap().is_authenticated_user = Some(arg_from_str(value.unwrap_or("false"), err, "sharing-user.is-authenticated-user", "boolean")); + }, + "sharing-user.email-address" => { + request_sharing_user_picture_init(&mut request); + request.sharing_user.as_mut().unwrap().email_address = Some(value.unwrap_or("").to_string()); + }, + "video-media-metadata.width" => { + request_video_media_metadata_init(&mut request); + request.video_media_metadata.as_mut().unwrap().width = Some(arg_from_str(value.unwrap_or("-0"), err, "video-media-metadata.width", "integer")); + }, + "video-media-metadata.duration-millis" => { + request_video_media_metadata_init(&mut request); + request.video_media_metadata.as_mut().unwrap().duration_millis = Some(value.unwrap_or("").to_string()); + }, + "video-media-metadata.height" => { + request_video_media_metadata_init(&mut request); + request.video_media_metadata.as_mut().unwrap().height = Some(arg_from_str(value.unwrap_or("-0"), err, "video-media-metadata.height", "integer")); + }, + "last-modifying-user.picture.url" => { + request_last_modifying_user_picture_init(&mut request); + request.last_modifying_user.as_mut().unwrap().picture.as_mut().unwrap().url = Some(value.unwrap_or("").to_string()); + }, + "last-modifying-user.kind" => { + request_last_modifying_user_picture_init(&mut request); + request.last_modifying_user.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "last-modifying-user.display-name" => { + request_last_modifying_user_picture_init(&mut request); + request.last_modifying_user.as_mut().unwrap().display_name = Some(value.unwrap_or("").to_string()); + }, + "last-modifying-user.permission-id" => { + request_last_modifying_user_picture_init(&mut request); + request.last_modifying_user.as_mut().unwrap().permission_id = Some(value.unwrap_or("").to_string()); + }, + "last-modifying-user.is-authenticated-user" => { + request_last_modifying_user_picture_init(&mut request); + request.last_modifying_user.as_mut().unwrap().is_authenticated_user = Some(arg_from_str(value.unwrap_or("false"), err, "last-modifying-user.is-authenticated-user", "boolean")); + }, + "last-modifying-user.email-address" => { + request_last_modifying_user_picture_init(&mut request); + request.last_modifying_user.as_mut().unwrap().email_address = Some(value.unwrap_or("").to_string()); + }, + "copyable" => { + request_last_modifying_user_init(&mut request); + request.copyable = Some(arg_from_str(value.unwrap_or("false"), err, "copyable", "boolean")); + }, + "folder-color-rgb" => { + request_last_modifying_user_init(&mut request); + request.folder_color_rgb = Some(value.unwrap_or("").to_string()); + }, + "owner-names" => { + request_last_modifying_user_init(&mut request); + if request.owner_names.is_none() { + request.owner_names = Some(Default::default()); + } + request.owner_names.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "shared-with-me-date" => { + request_last_modifying_user_init(&mut request); + request.shared_with_me_date = Some(value.unwrap_or("").to_string()); + }, + "web-view-link" => { + request_last_modifying_user_init(&mut request); + request.web_view_link = Some(value.unwrap_or("").to_string()); + }, + "version" => { + request_last_modifying_user_init(&mut request); + request.version = Some(value.unwrap_or("").to_string()); + }, + "export-links" => { + request_last_modifying_user_init(&mut request); + if request.export_links.is_none() { + request.export_links = Some(Default::default()); + } + let (key, value) = parse_kv_arg(value.unwrap_or(""), err, true); + request.export_links.as_mut().unwrap().insert(key.to_string(), value.unwrap_or("").to_string()); + }, + "shared" => { + request_last_modifying_user_init(&mut request); + request.shared = Some(arg_from_str(value.unwrap_or("false"), err, "shared", "boolean")); + }, + "thumbnail.mime-type" => { + request_thumbnail_init(&mut request); + request.thumbnail.as_mut().unwrap().mime_type = Some(value.unwrap_or("").to_string()); + }, + "thumbnail.image" => { + request_thumbnail_init(&mut request); + request.thumbnail.as_mut().unwrap().image = Some(value.unwrap_or("").to_string()); + }, + "open-with-links" => { + request_thumbnail_init(&mut request); + if request.open_with_links.is_none() { + request.open_with_links = Some(Default::default()); + } + let (key, value) = parse_kv_arg(value.unwrap_or(""), err, true); + request.open_with_links.as_mut().unwrap().insert(key.to_string(), value.unwrap_or("").to_string()); + }, + "image-media-metadata.exposure-bias" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().exposure_bias = Some(arg_from_str(value.unwrap_or("0.0"), err, "image-media-metadata.exposure-bias", "number")); + }, + "image-media-metadata.exposure-time" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().exposure_time = Some(arg_from_str(value.unwrap_or("0.0"), err, "image-media-metadata.exposure-time", "number")); + }, + "image-media-metadata.max-aperture-value" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().max_aperture_value = Some(arg_from_str(value.unwrap_or("0.0"), err, "image-media-metadata.max-aperture-value", "number")); + }, + "image-media-metadata.width" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().width = Some(arg_from_str(value.unwrap_or("-0"), err, "image-media-metadata.width", "integer")); + }, + "image-media-metadata.focal-length" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().focal_length = Some(arg_from_str(value.unwrap_or("0.0"), err, "image-media-metadata.focal-length", "number")); + }, + "image-media-metadata.camera-make" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().camera_make = Some(value.unwrap_or("").to_string()); + }, + "image-media-metadata.exposure-mode" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().exposure_mode = Some(value.unwrap_or("").to_string()); + }, + "image-media-metadata.color-space" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().color_space = Some(value.unwrap_or("").to_string()); + }, + "image-media-metadata.location.latitude" => { + request_image_media_metadata_location_init(&mut request); + request.image_media_metadata.as_mut().unwrap().location.as_mut().unwrap().latitude = Some(arg_from_str(value.unwrap_or("0.0"), err, "image-media-metadata.location.latitude", "number")); + }, + "image-media-metadata.location.altitude" => { + request_image_media_metadata_location_init(&mut request); + request.image_media_metadata.as_mut().unwrap().location.as_mut().unwrap().altitude = Some(arg_from_str(value.unwrap_or("0.0"), err, "image-media-metadata.location.altitude", "number")); + }, + "image-media-metadata.location.longitude" => { + request_image_media_metadata_location_init(&mut request); + request.image_media_metadata.as_mut().unwrap().location.as_mut().unwrap().longitude = Some(arg_from_str(value.unwrap_or("0.0"), err, "image-media-metadata.location.longitude", "number")); + }, + "image-media-metadata.subject-distance" => { + request_image_media_metadata_location_init(&mut request); + request.image_media_metadata.as_mut().unwrap().subject_distance = Some(arg_from_str(value.unwrap_or("-0"), err, "image-media-metadata.subject-distance", "integer")); + }, + "image-media-metadata.height" => { + request_image_media_metadata_location_init(&mut request); + request.image_media_metadata.as_mut().unwrap().height = Some(arg_from_str(value.unwrap_or("-0"), err, "image-media-metadata.height", "integer")); + }, + "image-media-metadata.lens" => { + request_image_media_metadata_location_init(&mut request); + request.image_media_metadata.as_mut().unwrap().lens = Some(value.unwrap_or("").to_string()); + }, + "image-media-metadata.date" => { + request_image_media_metadata_location_init(&mut request); + request.image_media_metadata.as_mut().unwrap().date = Some(value.unwrap_or("").to_string()); + }, + "image-media-metadata.iso-speed" => { + request_image_media_metadata_location_init(&mut request); + request.image_media_metadata.as_mut().unwrap().iso_speed = Some(arg_from_str(value.unwrap_or("-0"), err, "image-media-metadata.iso-speed", "integer")); + }, + "image-media-metadata.metering-mode" => { + request_image_media_metadata_location_init(&mut request); + request.image_media_metadata.as_mut().unwrap().metering_mode = Some(value.unwrap_or("").to_string()); + }, + "image-media-metadata.flash-used" => { + request_image_media_metadata_location_init(&mut request); + request.image_media_metadata.as_mut().unwrap().flash_used = Some(arg_from_str(value.unwrap_or("false"), err, "image-media-metadata.flash-used", "boolean")); + }, + "image-media-metadata.aperture" => { + request_image_media_metadata_location_init(&mut request); + request.image_media_metadata.as_mut().unwrap().aperture = Some(arg_from_str(value.unwrap_or("0.0"), err, "image-media-metadata.aperture", "number")); + }, + "image-media-metadata.rotation" => { + request_image_media_metadata_location_init(&mut request); + request.image_media_metadata.as_mut().unwrap().rotation = Some(arg_from_str(value.unwrap_or("-0"), err, "image-media-metadata.rotation", "integer")); + }, + "image-media-metadata.sensor" => { + request_image_media_metadata_location_init(&mut request); + request.image_media_metadata.as_mut().unwrap().sensor = Some(value.unwrap_or("").to_string()); + }, + "image-media-metadata.white-balance" => { + request_image_media_metadata_location_init(&mut request); + request.image_media_metadata.as_mut().unwrap().white_balance = Some(value.unwrap_or("").to_string()); + }, + "image-media-metadata.camera-model" => { + request_image_media_metadata_location_init(&mut request); + request.image_media_metadata.as_mut().unwrap().camera_model = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request_image_media_metadata_init(&mut request); + request.description = Some(value.unwrap_or("").to_string()); + }, + "web-content-link" => { + request_image_media_metadata_init(&mut request); + request.web_content_link = Some(value.unwrap_or("").to_string()); + }, + "editable" => { + request_image_media_metadata_init(&mut request); + request.editable = Some(arg_from_str(value.unwrap_or("false"), err, "editable", "boolean")); + }, + "embed-link" => { + request_image_media_metadata_init(&mut request); + request.embed_link = Some(value.unwrap_or("").to_string()); + }, + "marked-viewed-by-me-date" => { + request_image_media_metadata_init(&mut request); + request.marked_viewed_by_me_date = Some(value.unwrap_or("").to_string()); + }, + "quota-bytes-used" => { + request_image_media_metadata_init(&mut request); + request.quota_bytes_used = Some(value.unwrap_or("").to_string()); + }, + "file-size" => { + request_image_media_metadata_init(&mut request); + request.file_size = Some(value.unwrap_or("").to_string()); + }, + "created-date" => { + request_image_media_metadata_init(&mut request); + request.created_date = Some(value.unwrap_or("").to_string()); + }, + "md5-checksum" => { + request_image_media_metadata_init(&mut request); + request.md5_checksum = Some(value.unwrap_or("").to_string()); + }, + "icon-link" => { + request_image_media_metadata_init(&mut request); + request.icon_link = Some(value.unwrap_or("").to_string()); + }, + "default-open-with-link" => { + request_image_media_metadata_init(&mut request); + request.default_open_with_link = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request_image_media_metadata_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "alternate-link" => { + request_image_media_metadata_init(&mut request); + request.alternate_link = Some(value.unwrap_or("").to_string()); + }, + "title" => { + request_image_media_metadata_init(&mut request); + request.title = Some(value.unwrap_or("").to_string()); + }, + "modified-by-me-date" => { + request_image_media_metadata_init(&mut request); + request.modified_by_me_date = Some(value.unwrap_or("").to_string()); + }, + "download-url" => { + request_image_media_metadata_init(&mut request); + request.download_url = Some(value.unwrap_or("").to_string()); + }, + "user-permission.with-link" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().with_link = Some(arg_from_str(value.unwrap_or("false"), err, "user-permission.with-link", "boolean")); + }, + "user-permission.domain" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().domain = Some(value.unwrap_or("").to_string()); + }, + "user-permission.name" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().name = Some(value.unwrap_or("").to_string()); + }, + "user-permission.kind" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "user-permission.value" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "user-permission.id" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "user-permission.auth-key" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().auth_key = Some(value.unwrap_or("").to_string()); + }, + "user-permission.etag" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "user-permission.email-address" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().email_address = Some(value.unwrap_or("").to_string()); + }, + "user-permission.photo-link" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().photo_link = Some(value.unwrap_or("").to_string()); + }, + "user-permission.role" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().role = Some(value.unwrap_or("").to_string()); + }, + "user-permission.type" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().type_ = Some(value.unwrap_or("").to_string()); + }, + "user-permission.additional-roles" => { + request_user_permission_init(&mut request); + if request.user_permission.as_mut().unwrap().additional_roles.is_none() { + request.user_permission.as_mut().unwrap().additional_roles = Some(Default::default()); + } + request.user_permission.as_mut().unwrap().additional_roles.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "user-permission.self-link" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().self_link = Some(value.unwrap_or("").to_string()); + }, + "original-filename" => { + request_user_permission_init(&mut request); + request.original_filename = Some(value.unwrap_or("").to_string()); + }, + "file-extension" => { + request_user_permission_init(&mut request); + request.file_extension = Some(value.unwrap_or("").to_string()); + }, + "head-revision-id" => { + request_user_permission_init(&mut request); + request.head_revision_id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_user_permission_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "modified-date" => { + request_user_permission_init(&mut request); + request.modified_date = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = + if self.opt.cmd_simple { + "simple" + } else if self.opt.cmd_resumable { + "resumable" + } else { + unreachable!() + }; + let mut input_file = input_file_from_opts(&self.opt.arg_file, err); + let mime_type = input_mime_from_opts(&self.opt.arg_mime, err); + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "simple" => call.upload(input_file.unwrap(), mime_type.unwrap()), + "resumable" => call.upload_resumable(input_file.unwrap(), mime_type.unwrap()), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _files_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.files().list(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "q" => { + call = call.q(value.unwrap_or("")); + }, + "projection" => { + call = call.projection(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "corpus" => { + call = call.corpus(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _files_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request = api::File::default(); + let mut call = self.hub.files().patch(&request, &self.opt.arg_file_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "use-content-as-indexable-text" => { + call = call.use_content_as_indexable_text(arg_from_str(value.unwrap_or("false"), err, "use-content-as-indexable-text", "boolean")); + }, + "update-viewed-date" => { + call = call.update_viewed_date(arg_from_str(value.unwrap_or("false"), err, "update-viewed-date", "boolean")); + }, + "timed-text-track-name" => { + call = call.timed_text_track_name(value.unwrap_or("")); + }, + "timed-text-language" => { + call = call.timed_text_language(value.unwrap_or("")); + }, + "set-modified-date" => { + call = call.set_modified_date(arg_from_str(value.unwrap_or("false"), err, "set-modified-date", "boolean")); + }, + "remove-parents" => { + call = call.remove_parents(value.unwrap_or("")); + }, + "pinned" => { + call = call.pinned(arg_from_str(value.unwrap_or("false"), err, "pinned", "boolean")); + }, + "ocr-language" => { + call = call.ocr_language(value.unwrap_or("")); + }, + "ocr" => { + call = call.ocr(arg_from_str(value.unwrap_or("false"), err, "ocr", "boolean")); + }, + "new-revision" => { + call = call.new_revision(arg_from_str(value.unwrap_or("false"), err, "new-revision", "boolean")); + }, + "convert" => { + call = call.convert(arg_from_str(value.unwrap_or("false"), err, "convert", "boolean")); + }, + "add-parents" => { + call = call.add_parents(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_image_media_metadata_init(request: &mut api::File) { + if request.image_media_metadata.is_none() { + request.image_media_metadata = Some(Default::default()); + } + } + + fn request_image_media_metadata_location_init(request: &mut api::File) { + request_image_media_metadata_init(request); + if request.image_media_metadata.as_mut().unwrap().location.is_none() { + request.image_media_metadata.as_mut().unwrap().location = Some(Default::default()); + } + } + + fn request_indexable_text_init(request: &mut api::File) { + if request.indexable_text.is_none() { + request.indexable_text = Some(Default::default()); + } + } + + fn request_labels_init(request: &mut api::File) { + if request.labels.is_none() { + request.labels = Some(Default::default()); + } + } + + fn request_last_modifying_user_init(request: &mut api::File) { + if request.last_modifying_user.is_none() { + request.last_modifying_user = Some(Default::default()); + } + } + + fn request_last_modifying_user_picture_init(request: &mut api::File) { + request_last_modifying_user_init(request); + if request.last_modifying_user.as_mut().unwrap().picture.is_none() { + request.last_modifying_user.as_mut().unwrap().picture = Some(Default::default()); + } + } + + fn request_sharing_user_init(request: &mut api::File) { + if request.sharing_user.is_none() { + request.sharing_user = Some(Default::default()); + } + } + + fn request_sharing_user_picture_init(request: &mut api::File) { + request_sharing_user_init(request); + if request.sharing_user.as_mut().unwrap().picture.is_none() { + request.sharing_user.as_mut().unwrap().picture = Some(Default::default()); + } + } + + fn request_thumbnail_init(request: &mut api::File) { + if request.thumbnail.is_none() { + request.thumbnail = Some(Default::default()); + } + } + + fn request_user_permission_init(request: &mut api::File) { + if request.user_permission.is_none() { + request.user_permission = Some(Default::default()); + } + } + + fn request_video_media_metadata_init(request: &mut api::File) { + if request.video_media_metadata.is_none() { + request.video_media_metadata = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "mime-type" => { + request.mime_type = Some(value.unwrap_or("").to_string()); + }, + "last-viewed-by-me-date" => { + request.last_viewed_by_me_date = Some(value.unwrap_or("").to_string()); + }, + "app-data-contents" => { + request.app_data_contents = Some(arg_from_str(value.unwrap_or("false"), err, "app-data-contents", "boolean")); + }, + "thumbnail-link" => { + request.thumbnail_link = Some(value.unwrap_or("").to_string()); + }, + "labels.restricted" => { + request_labels_init(&mut request); + request.labels.as_mut().unwrap().restricted = Some(arg_from_str(value.unwrap_or("false"), err, "labels.restricted", "boolean")); + }, + "labels.hidden" => { + request_labels_init(&mut request); + request.labels.as_mut().unwrap().hidden = Some(arg_from_str(value.unwrap_or("false"), err, "labels.hidden", "boolean")); + }, + "labels.viewed" => { + request_labels_init(&mut request); + request.labels.as_mut().unwrap().viewed = Some(arg_from_str(value.unwrap_or("false"), err, "labels.viewed", "boolean")); + }, + "labels.starred" => { + request_labels_init(&mut request); + request.labels.as_mut().unwrap().starred = Some(arg_from_str(value.unwrap_or("false"), err, "labels.starred", "boolean")); + }, + "labels.trashed" => { + request_labels_init(&mut request); + request.labels.as_mut().unwrap().trashed = Some(arg_from_str(value.unwrap_or("false"), err, "labels.trashed", "boolean")); + }, + "indexable-text.text" => { + request_indexable_text_init(&mut request); + request.indexable_text.as_mut().unwrap().text = Some(value.unwrap_or("").to_string()); + }, + "explicitly-trashed" => { + request_indexable_text_init(&mut request); + request.explicitly_trashed = Some(arg_from_str(value.unwrap_or("false"), err, "explicitly-trashed", "boolean")); + }, + "etag" => { + request_indexable_text_init(&mut request); + request.etag = Some(value.unwrap_or("").to_string()); + }, + "last-modifying-user-name" => { + request_indexable_text_init(&mut request); + request.last_modifying_user_name = Some(value.unwrap_or("").to_string()); + }, + "writers-can-share" => { + request_indexable_text_init(&mut request); + request.writers_can_share = Some(arg_from_str(value.unwrap_or("false"), err, "writers-can-share", "boolean")); + }, + "id" => { + request_indexable_text_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "sharing-user.picture.url" => { + request_sharing_user_picture_init(&mut request); + request.sharing_user.as_mut().unwrap().picture.as_mut().unwrap().url = Some(value.unwrap_or("").to_string()); + }, + "sharing-user.kind" => { + request_sharing_user_picture_init(&mut request); + request.sharing_user.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "sharing-user.display-name" => { + request_sharing_user_picture_init(&mut request); + request.sharing_user.as_mut().unwrap().display_name = Some(value.unwrap_or("").to_string()); + }, + "sharing-user.permission-id" => { + request_sharing_user_picture_init(&mut request); + request.sharing_user.as_mut().unwrap().permission_id = Some(value.unwrap_or("").to_string()); + }, + "sharing-user.is-authenticated-user" => { + request_sharing_user_picture_init(&mut request); + request.sharing_user.as_mut().unwrap().is_authenticated_user = Some(arg_from_str(value.unwrap_or("false"), err, "sharing-user.is-authenticated-user", "boolean")); + }, + "sharing-user.email-address" => { + request_sharing_user_picture_init(&mut request); + request.sharing_user.as_mut().unwrap().email_address = Some(value.unwrap_or("").to_string()); + }, + "video-media-metadata.width" => { + request_video_media_metadata_init(&mut request); + request.video_media_metadata.as_mut().unwrap().width = Some(arg_from_str(value.unwrap_or("-0"), err, "video-media-metadata.width", "integer")); + }, + "video-media-metadata.duration-millis" => { + request_video_media_metadata_init(&mut request); + request.video_media_metadata.as_mut().unwrap().duration_millis = Some(value.unwrap_or("").to_string()); + }, + "video-media-metadata.height" => { + request_video_media_metadata_init(&mut request); + request.video_media_metadata.as_mut().unwrap().height = Some(arg_from_str(value.unwrap_or("-0"), err, "video-media-metadata.height", "integer")); + }, + "last-modifying-user.picture.url" => { + request_last_modifying_user_picture_init(&mut request); + request.last_modifying_user.as_mut().unwrap().picture.as_mut().unwrap().url = Some(value.unwrap_or("").to_string()); + }, + "last-modifying-user.kind" => { + request_last_modifying_user_picture_init(&mut request); + request.last_modifying_user.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "last-modifying-user.display-name" => { + request_last_modifying_user_picture_init(&mut request); + request.last_modifying_user.as_mut().unwrap().display_name = Some(value.unwrap_or("").to_string()); + }, + "last-modifying-user.permission-id" => { + request_last_modifying_user_picture_init(&mut request); + request.last_modifying_user.as_mut().unwrap().permission_id = Some(value.unwrap_or("").to_string()); + }, + "last-modifying-user.is-authenticated-user" => { + request_last_modifying_user_picture_init(&mut request); + request.last_modifying_user.as_mut().unwrap().is_authenticated_user = Some(arg_from_str(value.unwrap_or("false"), err, "last-modifying-user.is-authenticated-user", "boolean")); + }, + "last-modifying-user.email-address" => { + request_last_modifying_user_picture_init(&mut request); + request.last_modifying_user.as_mut().unwrap().email_address = Some(value.unwrap_or("").to_string()); + }, + "copyable" => { + request_last_modifying_user_init(&mut request); + request.copyable = Some(arg_from_str(value.unwrap_or("false"), err, "copyable", "boolean")); + }, + "folder-color-rgb" => { + request_last_modifying_user_init(&mut request); + request.folder_color_rgb = Some(value.unwrap_or("").to_string()); + }, + "owner-names" => { + request_last_modifying_user_init(&mut request); + if request.owner_names.is_none() { + request.owner_names = Some(Default::default()); + } + request.owner_names.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "shared-with-me-date" => { + request_last_modifying_user_init(&mut request); + request.shared_with_me_date = Some(value.unwrap_or("").to_string()); + }, + "web-view-link" => { + request_last_modifying_user_init(&mut request); + request.web_view_link = Some(value.unwrap_or("").to_string()); + }, + "version" => { + request_last_modifying_user_init(&mut request); + request.version = Some(value.unwrap_or("").to_string()); + }, + "export-links" => { + request_last_modifying_user_init(&mut request); + if request.export_links.is_none() { + request.export_links = Some(Default::default()); + } + let (key, value) = parse_kv_arg(value.unwrap_or(""), err, true); + request.export_links.as_mut().unwrap().insert(key.to_string(), value.unwrap_or("").to_string()); + }, + "shared" => { + request_last_modifying_user_init(&mut request); + request.shared = Some(arg_from_str(value.unwrap_or("false"), err, "shared", "boolean")); + }, + "thumbnail.mime-type" => { + request_thumbnail_init(&mut request); + request.thumbnail.as_mut().unwrap().mime_type = Some(value.unwrap_or("").to_string()); + }, + "thumbnail.image" => { + request_thumbnail_init(&mut request); + request.thumbnail.as_mut().unwrap().image = Some(value.unwrap_or("").to_string()); + }, + "open-with-links" => { + request_thumbnail_init(&mut request); + if request.open_with_links.is_none() { + request.open_with_links = Some(Default::default()); + } + let (key, value) = parse_kv_arg(value.unwrap_or(""), err, true); + request.open_with_links.as_mut().unwrap().insert(key.to_string(), value.unwrap_or("").to_string()); + }, + "image-media-metadata.exposure-bias" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().exposure_bias = Some(arg_from_str(value.unwrap_or("0.0"), err, "image-media-metadata.exposure-bias", "number")); + }, + "image-media-metadata.exposure-time" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().exposure_time = Some(arg_from_str(value.unwrap_or("0.0"), err, "image-media-metadata.exposure-time", "number")); + }, + "image-media-metadata.max-aperture-value" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().max_aperture_value = Some(arg_from_str(value.unwrap_or("0.0"), err, "image-media-metadata.max-aperture-value", "number")); + }, + "image-media-metadata.width" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().width = Some(arg_from_str(value.unwrap_or("-0"), err, "image-media-metadata.width", "integer")); + }, + "image-media-metadata.focal-length" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().focal_length = Some(arg_from_str(value.unwrap_or("0.0"), err, "image-media-metadata.focal-length", "number")); + }, + "image-media-metadata.camera-make" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().camera_make = Some(value.unwrap_or("").to_string()); + }, + "image-media-metadata.exposure-mode" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().exposure_mode = Some(value.unwrap_or("").to_string()); + }, + "image-media-metadata.color-space" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().color_space = Some(value.unwrap_or("").to_string()); + }, + "image-media-metadata.location.latitude" => { + request_image_media_metadata_location_init(&mut request); + request.image_media_metadata.as_mut().unwrap().location.as_mut().unwrap().latitude = Some(arg_from_str(value.unwrap_or("0.0"), err, "image-media-metadata.location.latitude", "number")); + }, + "image-media-metadata.location.altitude" => { + request_image_media_metadata_location_init(&mut request); + request.image_media_metadata.as_mut().unwrap().location.as_mut().unwrap().altitude = Some(arg_from_str(value.unwrap_or("0.0"), err, "image-media-metadata.location.altitude", "number")); + }, + "image-media-metadata.location.longitude" => { + request_image_media_metadata_location_init(&mut request); + request.image_media_metadata.as_mut().unwrap().location.as_mut().unwrap().longitude = Some(arg_from_str(value.unwrap_or("0.0"), err, "image-media-metadata.location.longitude", "number")); + }, + "image-media-metadata.subject-distance" => { + request_image_media_metadata_location_init(&mut request); + request.image_media_metadata.as_mut().unwrap().subject_distance = Some(arg_from_str(value.unwrap_or("-0"), err, "image-media-metadata.subject-distance", "integer")); + }, + "image-media-metadata.height" => { + request_image_media_metadata_location_init(&mut request); + request.image_media_metadata.as_mut().unwrap().height = Some(arg_from_str(value.unwrap_or("-0"), err, "image-media-metadata.height", "integer")); + }, + "image-media-metadata.lens" => { + request_image_media_metadata_location_init(&mut request); + request.image_media_metadata.as_mut().unwrap().lens = Some(value.unwrap_or("").to_string()); + }, + "image-media-metadata.date" => { + request_image_media_metadata_location_init(&mut request); + request.image_media_metadata.as_mut().unwrap().date = Some(value.unwrap_or("").to_string()); + }, + "image-media-metadata.iso-speed" => { + request_image_media_metadata_location_init(&mut request); + request.image_media_metadata.as_mut().unwrap().iso_speed = Some(arg_from_str(value.unwrap_or("-0"), err, "image-media-metadata.iso-speed", "integer")); + }, + "image-media-metadata.metering-mode" => { + request_image_media_metadata_location_init(&mut request); + request.image_media_metadata.as_mut().unwrap().metering_mode = Some(value.unwrap_or("").to_string()); + }, + "image-media-metadata.flash-used" => { + request_image_media_metadata_location_init(&mut request); + request.image_media_metadata.as_mut().unwrap().flash_used = Some(arg_from_str(value.unwrap_or("false"), err, "image-media-metadata.flash-used", "boolean")); + }, + "image-media-metadata.aperture" => { + request_image_media_metadata_location_init(&mut request); + request.image_media_metadata.as_mut().unwrap().aperture = Some(arg_from_str(value.unwrap_or("0.0"), err, "image-media-metadata.aperture", "number")); + }, + "image-media-metadata.rotation" => { + request_image_media_metadata_location_init(&mut request); + request.image_media_metadata.as_mut().unwrap().rotation = Some(arg_from_str(value.unwrap_or("-0"), err, "image-media-metadata.rotation", "integer")); + }, + "image-media-metadata.sensor" => { + request_image_media_metadata_location_init(&mut request); + request.image_media_metadata.as_mut().unwrap().sensor = Some(value.unwrap_or("").to_string()); + }, + "image-media-metadata.white-balance" => { + request_image_media_metadata_location_init(&mut request); + request.image_media_metadata.as_mut().unwrap().white_balance = Some(value.unwrap_or("").to_string()); + }, + "image-media-metadata.camera-model" => { + request_image_media_metadata_location_init(&mut request); + request.image_media_metadata.as_mut().unwrap().camera_model = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request_image_media_metadata_init(&mut request); + request.description = Some(value.unwrap_or("").to_string()); + }, + "web-content-link" => { + request_image_media_metadata_init(&mut request); + request.web_content_link = Some(value.unwrap_or("").to_string()); + }, + "editable" => { + request_image_media_metadata_init(&mut request); + request.editable = Some(arg_from_str(value.unwrap_or("false"), err, "editable", "boolean")); + }, + "embed-link" => { + request_image_media_metadata_init(&mut request); + request.embed_link = Some(value.unwrap_or("").to_string()); + }, + "marked-viewed-by-me-date" => { + request_image_media_metadata_init(&mut request); + request.marked_viewed_by_me_date = Some(value.unwrap_or("").to_string()); + }, + "quota-bytes-used" => { + request_image_media_metadata_init(&mut request); + request.quota_bytes_used = Some(value.unwrap_or("").to_string()); + }, + "file-size" => { + request_image_media_metadata_init(&mut request); + request.file_size = Some(value.unwrap_or("").to_string()); + }, + "created-date" => { + request_image_media_metadata_init(&mut request); + request.created_date = Some(value.unwrap_or("").to_string()); + }, + "md5-checksum" => { + request_image_media_metadata_init(&mut request); + request.md5_checksum = Some(value.unwrap_or("").to_string()); + }, + "icon-link" => { + request_image_media_metadata_init(&mut request); + request.icon_link = Some(value.unwrap_or("").to_string()); + }, + "default-open-with-link" => { + request_image_media_metadata_init(&mut request); + request.default_open_with_link = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request_image_media_metadata_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "alternate-link" => { + request_image_media_metadata_init(&mut request); + request.alternate_link = Some(value.unwrap_or("").to_string()); + }, + "title" => { + request_image_media_metadata_init(&mut request); + request.title = Some(value.unwrap_or("").to_string()); + }, + "modified-by-me-date" => { + request_image_media_metadata_init(&mut request); + request.modified_by_me_date = Some(value.unwrap_or("").to_string()); + }, + "download-url" => { + request_image_media_metadata_init(&mut request); + request.download_url = Some(value.unwrap_or("").to_string()); + }, + "user-permission.with-link" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().with_link = Some(arg_from_str(value.unwrap_or("false"), err, "user-permission.with-link", "boolean")); + }, + "user-permission.domain" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().domain = Some(value.unwrap_or("").to_string()); + }, + "user-permission.name" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().name = Some(value.unwrap_or("").to_string()); + }, + "user-permission.kind" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "user-permission.value" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "user-permission.id" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "user-permission.auth-key" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().auth_key = Some(value.unwrap_or("").to_string()); + }, + "user-permission.etag" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "user-permission.email-address" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().email_address = Some(value.unwrap_or("").to_string()); + }, + "user-permission.photo-link" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().photo_link = Some(value.unwrap_or("").to_string()); + }, + "user-permission.role" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().role = Some(value.unwrap_or("").to_string()); + }, + "user-permission.type" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().type_ = Some(value.unwrap_or("").to_string()); + }, + "user-permission.additional-roles" => { + request_user_permission_init(&mut request); + if request.user_permission.as_mut().unwrap().additional_roles.is_none() { + request.user_permission.as_mut().unwrap().additional_roles = Some(Default::default()); + } + request.user_permission.as_mut().unwrap().additional_roles.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "user-permission.self-link" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().self_link = Some(value.unwrap_or("").to_string()); + }, + "original-filename" => { + request_user_permission_init(&mut request); + request.original_filename = Some(value.unwrap_or("").to_string()); + }, + "file-extension" => { + request_user_permission_init(&mut request); + request.file_extension = Some(value.unwrap_or("").to_string()); + }, + "head-revision-id" => { + request_user_permission_init(&mut request); + request.head_revision_id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_user_permission_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "modified-date" => { + request_user_permission_init(&mut request); + request.modified_date = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _files_touch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.files().touch(&self.opt.arg_file_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _files_trash(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.files().trash(&self.opt.arg_file_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _files_untrash(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.files().untrash(&self.opt.arg_file_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _files_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request = api::File::default(); + let mut call = self.hub.files().update(&request, &self.opt.arg_file_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "use-content-as-indexable-text" => { + call = call.use_content_as_indexable_text(arg_from_str(value.unwrap_or("false"), err, "use-content-as-indexable-text", "boolean")); + }, + "update-viewed-date" => { + call = call.update_viewed_date(arg_from_str(value.unwrap_or("false"), err, "update-viewed-date", "boolean")); + }, + "timed-text-track-name" => { + call = call.timed_text_track_name(value.unwrap_or("")); + }, + "timed-text-language" => { + call = call.timed_text_language(value.unwrap_or("")); + }, + "set-modified-date" => { + call = call.set_modified_date(arg_from_str(value.unwrap_or("false"), err, "set-modified-date", "boolean")); + }, + "remove-parents" => { + call = call.remove_parents(value.unwrap_or("")); + }, + "pinned" => { + call = call.pinned(arg_from_str(value.unwrap_or("false"), err, "pinned", "boolean")); + }, + "ocr-language" => { + call = call.ocr_language(value.unwrap_or("")); + }, + "ocr" => { + call = call.ocr(arg_from_str(value.unwrap_or("false"), err, "ocr", "boolean")); + }, + "new-revision" => { + call = call.new_revision(arg_from_str(value.unwrap_or("false"), err, "new-revision", "boolean")); + }, + "convert" => { + call = call.convert(arg_from_str(value.unwrap_or("false"), err, "convert", "boolean")); + }, + "add-parents" => { + call = call.add_parents(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_image_media_metadata_init(request: &mut api::File) { + if request.image_media_metadata.is_none() { + request.image_media_metadata = Some(Default::default()); + } + } + + fn request_image_media_metadata_location_init(request: &mut api::File) { + request_image_media_metadata_init(request); + if request.image_media_metadata.as_mut().unwrap().location.is_none() { + request.image_media_metadata.as_mut().unwrap().location = Some(Default::default()); + } + } + + fn request_indexable_text_init(request: &mut api::File) { + if request.indexable_text.is_none() { + request.indexable_text = Some(Default::default()); + } + } + + fn request_labels_init(request: &mut api::File) { + if request.labels.is_none() { + request.labels = Some(Default::default()); + } + } + + fn request_last_modifying_user_init(request: &mut api::File) { + if request.last_modifying_user.is_none() { + request.last_modifying_user = Some(Default::default()); + } + } + + fn request_last_modifying_user_picture_init(request: &mut api::File) { + request_last_modifying_user_init(request); + if request.last_modifying_user.as_mut().unwrap().picture.is_none() { + request.last_modifying_user.as_mut().unwrap().picture = Some(Default::default()); + } + } + + fn request_sharing_user_init(request: &mut api::File) { + if request.sharing_user.is_none() { + request.sharing_user = Some(Default::default()); + } + } + + fn request_sharing_user_picture_init(request: &mut api::File) { + request_sharing_user_init(request); + if request.sharing_user.as_mut().unwrap().picture.is_none() { + request.sharing_user.as_mut().unwrap().picture = Some(Default::default()); + } + } + + fn request_thumbnail_init(request: &mut api::File) { + if request.thumbnail.is_none() { + request.thumbnail = Some(Default::default()); + } + } + + fn request_user_permission_init(request: &mut api::File) { + if request.user_permission.is_none() { + request.user_permission = Some(Default::default()); + } + } + + fn request_video_media_metadata_init(request: &mut api::File) { + if request.video_media_metadata.is_none() { + request.video_media_metadata = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "mime-type" => { + request.mime_type = Some(value.unwrap_or("").to_string()); + }, + "last-viewed-by-me-date" => { + request.last_viewed_by_me_date = Some(value.unwrap_or("").to_string()); + }, + "app-data-contents" => { + request.app_data_contents = Some(arg_from_str(value.unwrap_or("false"), err, "app-data-contents", "boolean")); + }, + "thumbnail-link" => { + request.thumbnail_link = Some(value.unwrap_or("").to_string()); + }, + "labels.restricted" => { + request_labels_init(&mut request); + request.labels.as_mut().unwrap().restricted = Some(arg_from_str(value.unwrap_or("false"), err, "labels.restricted", "boolean")); + }, + "labels.hidden" => { + request_labels_init(&mut request); + request.labels.as_mut().unwrap().hidden = Some(arg_from_str(value.unwrap_or("false"), err, "labels.hidden", "boolean")); + }, + "labels.viewed" => { + request_labels_init(&mut request); + request.labels.as_mut().unwrap().viewed = Some(arg_from_str(value.unwrap_or("false"), err, "labels.viewed", "boolean")); + }, + "labels.starred" => { + request_labels_init(&mut request); + request.labels.as_mut().unwrap().starred = Some(arg_from_str(value.unwrap_or("false"), err, "labels.starred", "boolean")); + }, + "labels.trashed" => { + request_labels_init(&mut request); + request.labels.as_mut().unwrap().trashed = Some(arg_from_str(value.unwrap_or("false"), err, "labels.trashed", "boolean")); + }, + "indexable-text.text" => { + request_indexable_text_init(&mut request); + request.indexable_text.as_mut().unwrap().text = Some(value.unwrap_or("").to_string()); + }, + "explicitly-trashed" => { + request_indexable_text_init(&mut request); + request.explicitly_trashed = Some(arg_from_str(value.unwrap_or("false"), err, "explicitly-trashed", "boolean")); + }, + "etag" => { + request_indexable_text_init(&mut request); + request.etag = Some(value.unwrap_or("").to_string()); + }, + "last-modifying-user-name" => { + request_indexable_text_init(&mut request); + request.last_modifying_user_name = Some(value.unwrap_or("").to_string()); + }, + "writers-can-share" => { + request_indexable_text_init(&mut request); + request.writers_can_share = Some(arg_from_str(value.unwrap_or("false"), err, "writers-can-share", "boolean")); + }, + "id" => { + request_indexable_text_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "sharing-user.picture.url" => { + request_sharing_user_picture_init(&mut request); + request.sharing_user.as_mut().unwrap().picture.as_mut().unwrap().url = Some(value.unwrap_or("").to_string()); + }, + "sharing-user.kind" => { + request_sharing_user_picture_init(&mut request); + request.sharing_user.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "sharing-user.display-name" => { + request_sharing_user_picture_init(&mut request); + request.sharing_user.as_mut().unwrap().display_name = Some(value.unwrap_or("").to_string()); + }, + "sharing-user.permission-id" => { + request_sharing_user_picture_init(&mut request); + request.sharing_user.as_mut().unwrap().permission_id = Some(value.unwrap_or("").to_string()); + }, + "sharing-user.is-authenticated-user" => { + request_sharing_user_picture_init(&mut request); + request.sharing_user.as_mut().unwrap().is_authenticated_user = Some(arg_from_str(value.unwrap_or("false"), err, "sharing-user.is-authenticated-user", "boolean")); + }, + "sharing-user.email-address" => { + request_sharing_user_picture_init(&mut request); + request.sharing_user.as_mut().unwrap().email_address = Some(value.unwrap_or("").to_string()); + }, + "video-media-metadata.width" => { + request_video_media_metadata_init(&mut request); + request.video_media_metadata.as_mut().unwrap().width = Some(arg_from_str(value.unwrap_or("-0"), err, "video-media-metadata.width", "integer")); + }, + "video-media-metadata.duration-millis" => { + request_video_media_metadata_init(&mut request); + request.video_media_metadata.as_mut().unwrap().duration_millis = Some(value.unwrap_or("").to_string()); + }, + "video-media-metadata.height" => { + request_video_media_metadata_init(&mut request); + request.video_media_metadata.as_mut().unwrap().height = Some(arg_from_str(value.unwrap_or("-0"), err, "video-media-metadata.height", "integer")); + }, + "last-modifying-user.picture.url" => { + request_last_modifying_user_picture_init(&mut request); + request.last_modifying_user.as_mut().unwrap().picture.as_mut().unwrap().url = Some(value.unwrap_or("").to_string()); + }, + "last-modifying-user.kind" => { + request_last_modifying_user_picture_init(&mut request); + request.last_modifying_user.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "last-modifying-user.display-name" => { + request_last_modifying_user_picture_init(&mut request); + request.last_modifying_user.as_mut().unwrap().display_name = Some(value.unwrap_or("").to_string()); + }, + "last-modifying-user.permission-id" => { + request_last_modifying_user_picture_init(&mut request); + request.last_modifying_user.as_mut().unwrap().permission_id = Some(value.unwrap_or("").to_string()); + }, + "last-modifying-user.is-authenticated-user" => { + request_last_modifying_user_picture_init(&mut request); + request.last_modifying_user.as_mut().unwrap().is_authenticated_user = Some(arg_from_str(value.unwrap_or("false"), err, "last-modifying-user.is-authenticated-user", "boolean")); + }, + "last-modifying-user.email-address" => { + request_last_modifying_user_picture_init(&mut request); + request.last_modifying_user.as_mut().unwrap().email_address = Some(value.unwrap_or("").to_string()); + }, + "copyable" => { + request_last_modifying_user_init(&mut request); + request.copyable = Some(arg_from_str(value.unwrap_or("false"), err, "copyable", "boolean")); + }, + "folder-color-rgb" => { + request_last_modifying_user_init(&mut request); + request.folder_color_rgb = Some(value.unwrap_or("").to_string()); + }, + "owner-names" => { + request_last_modifying_user_init(&mut request); + if request.owner_names.is_none() { + request.owner_names = Some(Default::default()); + } + request.owner_names.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "shared-with-me-date" => { + request_last_modifying_user_init(&mut request); + request.shared_with_me_date = Some(value.unwrap_or("").to_string()); + }, + "web-view-link" => { + request_last_modifying_user_init(&mut request); + request.web_view_link = Some(value.unwrap_or("").to_string()); + }, + "version" => { + request_last_modifying_user_init(&mut request); + request.version = Some(value.unwrap_or("").to_string()); + }, + "export-links" => { + request_last_modifying_user_init(&mut request); + if request.export_links.is_none() { + request.export_links = Some(Default::default()); + } + let (key, value) = parse_kv_arg(value.unwrap_or(""), err, true); + request.export_links.as_mut().unwrap().insert(key.to_string(), value.unwrap_or("").to_string()); + }, + "shared" => { + request_last_modifying_user_init(&mut request); + request.shared = Some(arg_from_str(value.unwrap_or("false"), err, "shared", "boolean")); + }, + "thumbnail.mime-type" => { + request_thumbnail_init(&mut request); + request.thumbnail.as_mut().unwrap().mime_type = Some(value.unwrap_or("").to_string()); + }, + "thumbnail.image" => { + request_thumbnail_init(&mut request); + request.thumbnail.as_mut().unwrap().image = Some(value.unwrap_or("").to_string()); + }, + "open-with-links" => { + request_thumbnail_init(&mut request); + if request.open_with_links.is_none() { + request.open_with_links = Some(Default::default()); + } + let (key, value) = parse_kv_arg(value.unwrap_or(""), err, true); + request.open_with_links.as_mut().unwrap().insert(key.to_string(), value.unwrap_or("").to_string()); + }, + "image-media-metadata.exposure-bias" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().exposure_bias = Some(arg_from_str(value.unwrap_or("0.0"), err, "image-media-metadata.exposure-bias", "number")); + }, + "image-media-metadata.exposure-time" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().exposure_time = Some(arg_from_str(value.unwrap_or("0.0"), err, "image-media-metadata.exposure-time", "number")); + }, + "image-media-metadata.max-aperture-value" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().max_aperture_value = Some(arg_from_str(value.unwrap_or("0.0"), err, "image-media-metadata.max-aperture-value", "number")); + }, + "image-media-metadata.width" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().width = Some(arg_from_str(value.unwrap_or("-0"), err, "image-media-metadata.width", "integer")); + }, + "image-media-metadata.focal-length" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().focal_length = Some(arg_from_str(value.unwrap_or("0.0"), err, "image-media-metadata.focal-length", "number")); + }, + "image-media-metadata.camera-make" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().camera_make = Some(value.unwrap_or("").to_string()); + }, + "image-media-metadata.exposure-mode" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().exposure_mode = Some(value.unwrap_or("").to_string()); + }, + "image-media-metadata.color-space" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().color_space = Some(value.unwrap_or("").to_string()); + }, + "image-media-metadata.location.latitude" => { + request_image_media_metadata_location_init(&mut request); + request.image_media_metadata.as_mut().unwrap().location.as_mut().unwrap().latitude = Some(arg_from_str(value.unwrap_or("0.0"), err, "image-media-metadata.location.latitude", "number")); + }, + "image-media-metadata.location.altitude" => { + request_image_media_metadata_location_init(&mut request); + request.image_media_metadata.as_mut().unwrap().location.as_mut().unwrap().altitude = Some(arg_from_str(value.unwrap_or("0.0"), err, "image-media-metadata.location.altitude", "number")); + }, + "image-media-metadata.location.longitude" => { + request_image_media_metadata_location_init(&mut request); + request.image_media_metadata.as_mut().unwrap().location.as_mut().unwrap().longitude = Some(arg_from_str(value.unwrap_or("0.0"), err, "image-media-metadata.location.longitude", "number")); + }, + "image-media-metadata.subject-distance" => { + request_image_media_metadata_location_init(&mut request); + request.image_media_metadata.as_mut().unwrap().subject_distance = Some(arg_from_str(value.unwrap_or("-0"), err, "image-media-metadata.subject-distance", "integer")); + }, + "image-media-metadata.height" => { + request_image_media_metadata_location_init(&mut request); + request.image_media_metadata.as_mut().unwrap().height = Some(arg_from_str(value.unwrap_or("-0"), err, "image-media-metadata.height", "integer")); + }, + "image-media-metadata.lens" => { + request_image_media_metadata_location_init(&mut request); + request.image_media_metadata.as_mut().unwrap().lens = Some(value.unwrap_or("").to_string()); + }, + "image-media-metadata.date" => { + request_image_media_metadata_location_init(&mut request); + request.image_media_metadata.as_mut().unwrap().date = Some(value.unwrap_or("").to_string()); + }, + "image-media-metadata.iso-speed" => { + request_image_media_metadata_location_init(&mut request); + request.image_media_metadata.as_mut().unwrap().iso_speed = Some(arg_from_str(value.unwrap_or("-0"), err, "image-media-metadata.iso-speed", "integer")); + }, + "image-media-metadata.metering-mode" => { + request_image_media_metadata_location_init(&mut request); + request.image_media_metadata.as_mut().unwrap().metering_mode = Some(value.unwrap_or("").to_string()); + }, + "image-media-metadata.flash-used" => { + request_image_media_metadata_location_init(&mut request); + request.image_media_metadata.as_mut().unwrap().flash_used = Some(arg_from_str(value.unwrap_or("false"), err, "image-media-metadata.flash-used", "boolean")); + }, + "image-media-metadata.aperture" => { + request_image_media_metadata_location_init(&mut request); + request.image_media_metadata.as_mut().unwrap().aperture = Some(arg_from_str(value.unwrap_or("0.0"), err, "image-media-metadata.aperture", "number")); + }, + "image-media-metadata.rotation" => { + request_image_media_metadata_location_init(&mut request); + request.image_media_metadata.as_mut().unwrap().rotation = Some(arg_from_str(value.unwrap_or("-0"), err, "image-media-metadata.rotation", "integer")); + }, + "image-media-metadata.sensor" => { + request_image_media_metadata_location_init(&mut request); + request.image_media_metadata.as_mut().unwrap().sensor = Some(value.unwrap_or("").to_string()); + }, + "image-media-metadata.white-balance" => { + request_image_media_metadata_location_init(&mut request); + request.image_media_metadata.as_mut().unwrap().white_balance = Some(value.unwrap_or("").to_string()); + }, + "image-media-metadata.camera-model" => { + request_image_media_metadata_location_init(&mut request); + request.image_media_metadata.as_mut().unwrap().camera_model = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request_image_media_metadata_init(&mut request); + request.description = Some(value.unwrap_or("").to_string()); + }, + "web-content-link" => { + request_image_media_metadata_init(&mut request); + request.web_content_link = Some(value.unwrap_or("").to_string()); + }, + "editable" => { + request_image_media_metadata_init(&mut request); + request.editable = Some(arg_from_str(value.unwrap_or("false"), err, "editable", "boolean")); + }, + "embed-link" => { + request_image_media_metadata_init(&mut request); + request.embed_link = Some(value.unwrap_or("").to_string()); + }, + "marked-viewed-by-me-date" => { + request_image_media_metadata_init(&mut request); + request.marked_viewed_by_me_date = Some(value.unwrap_or("").to_string()); + }, + "quota-bytes-used" => { + request_image_media_metadata_init(&mut request); + request.quota_bytes_used = Some(value.unwrap_or("").to_string()); + }, + "file-size" => { + request_image_media_metadata_init(&mut request); + request.file_size = Some(value.unwrap_or("").to_string()); + }, + "created-date" => { + request_image_media_metadata_init(&mut request); + request.created_date = Some(value.unwrap_or("").to_string()); + }, + "md5-checksum" => { + request_image_media_metadata_init(&mut request); + request.md5_checksum = Some(value.unwrap_or("").to_string()); + }, + "icon-link" => { + request_image_media_metadata_init(&mut request); + request.icon_link = Some(value.unwrap_or("").to_string()); + }, + "default-open-with-link" => { + request_image_media_metadata_init(&mut request); + request.default_open_with_link = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request_image_media_metadata_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "alternate-link" => { + request_image_media_metadata_init(&mut request); + request.alternate_link = Some(value.unwrap_or("").to_string()); + }, + "title" => { + request_image_media_metadata_init(&mut request); + request.title = Some(value.unwrap_or("").to_string()); + }, + "modified-by-me-date" => { + request_image_media_metadata_init(&mut request); + request.modified_by_me_date = Some(value.unwrap_or("").to_string()); + }, + "download-url" => { + request_image_media_metadata_init(&mut request); + request.download_url = Some(value.unwrap_or("").to_string()); + }, + "user-permission.with-link" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().with_link = Some(arg_from_str(value.unwrap_or("false"), err, "user-permission.with-link", "boolean")); + }, + "user-permission.domain" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().domain = Some(value.unwrap_or("").to_string()); + }, + "user-permission.name" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().name = Some(value.unwrap_or("").to_string()); + }, + "user-permission.kind" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "user-permission.value" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "user-permission.id" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "user-permission.auth-key" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().auth_key = Some(value.unwrap_or("").to_string()); + }, + "user-permission.etag" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "user-permission.email-address" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().email_address = Some(value.unwrap_or("").to_string()); + }, + "user-permission.photo-link" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().photo_link = Some(value.unwrap_or("").to_string()); + }, + "user-permission.role" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().role = Some(value.unwrap_or("").to_string()); + }, + "user-permission.type" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().type_ = Some(value.unwrap_or("").to_string()); + }, + "user-permission.additional-roles" => { + request_user_permission_init(&mut request); + if request.user_permission.as_mut().unwrap().additional_roles.is_none() { + request.user_permission.as_mut().unwrap().additional_roles = Some(Default::default()); + } + request.user_permission.as_mut().unwrap().additional_roles.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "user-permission.self-link" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().self_link = Some(value.unwrap_or("").to_string()); + }, + "original-filename" => { + request_user_permission_init(&mut request); + request.original_filename = Some(value.unwrap_or("").to_string()); + }, + "file-extension" => { + request_user_permission_init(&mut request); + request.file_extension = Some(value.unwrap_or("").to_string()); + }, + "head-revision-id" => { + request_user_permission_init(&mut request); + request.head_revision_id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_user_permission_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "modified-date" => { + request_user_permission_init(&mut request); + request.modified_date = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = + if self.opt.cmd_simple { + "simple" + } else if self.opt.cmd_resumable { + "resumable" + } else { + unreachable!() + }; + let mut input_file = input_file_from_opts(&self.opt.arg_file, err); + let mime_type = input_mime_from_opts(&self.opt.arg_mime, err); + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "simple" => call.upload(input_file.unwrap(), mime_type.unwrap()), + "resumable" => call.upload_resumable(input_file.unwrap(), mime_type.unwrap()), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _files_watch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request = api::Channel::default(); + let mut download_mode = false; + let mut call = self.hub.files().watch(&request, &self.opt.arg_file_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "update-viewed-date" => { + call = call.update_viewed_date(arg_from_str(value.unwrap_or("false"), err, "update-viewed-date", "boolean")); + }, + "revision-id" => { + call = call.revision_id(value.unwrap_or("")); + }, + "projection" => { + call = call.projection(value.unwrap_or("")); + }, + "acknowledge-abuse" => { + call = call.acknowledge_abuse(arg_from_str(value.unwrap_or("false"), err, "acknowledge-abuse", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + if key == "alt" && value.unwrap_or("unset") == "media" { + download_mode = true; + } + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "resource-uri" => { + request.resource_uri = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "resource-id" => { + request.resource_id = Some(value.unwrap_or("").to_string()); + }, + "payload" => { + request.payload = Some(arg_from_str(value.unwrap_or("false"), err, "payload", "boolean")); + }, + "token" => { + request.token = Some(value.unwrap_or("").to_string()); + }, + "params" => { + if request.params.is_none() { + request.params = Some(Default::default()); + } + let (key, value) = parse_kv_arg(value.unwrap_or(""), err, true); + request.params.as_mut().unwrap().insert(key.to_string(), value.unwrap_or("").to_string()); + }, + "expiration" => { + request.expiration = Some(value.unwrap_or("").to_string()); + }, + "address" => { + request.address = Some(value.unwrap_or("").to_string()); + }, + "type" => { + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + if !download_mode { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + } else { + io::copy(&mut response, &mut ostream).unwrap(); + } + None + } + } + } + } + + fn _parents_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.parents().delete(&self.opt.arg_file_id, &self.opt.arg_parent_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + None + } + } + } + } + + fn _parents_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.parents().get(&self.opt.arg_file_id, &self.opt.arg_parent_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _parents_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request = api::ParentReference::default(); + let mut call = self.hub.parents().insert(&request, &self.opt.arg_file_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "self-link" => { + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "is-root" => { + request.is_root = Some(arg_from_str(value.unwrap_or("false"), err, "is-root", "boolean")); + }, + "parent-link" => { + request.parent_link = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _parents_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.parents().list(&self.opt.arg_file_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _permissions_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.permissions().delete(&self.opt.arg_file_id, &self.opt.arg_permission_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + None + } + } + } + } + + fn _permissions_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.permissions().get(&self.opt.arg_file_id, &self.opt.arg_permission_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _permissions_get_id_for_email(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.permissions().get_id_for_email(&self.opt.arg_email); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _permissions_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request = api::Permission::default(); + let mut call = self.hub.permissions().insert(&request, &self.opt.arg_file_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "send-notification-emails" => { + call = call.send_notification_emails(arg_from_str(value.unwrap_or("false"), err, "send-notification-emails", "boolean")); + }, + "email-message" => { + call = call.email_message(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "with-link" => { + request.with_link = Some(arg_from_str(value.unwrap_or("false"), err, "with-link", "boolean")); + }, + "domain" => { + request.domain = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "value" => { + request.value = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "auth-key" => { + request.auth_key = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "email-address" => { + request.email_address = Some(value.unwrap_or("").to_string()); + }, + "photo-link" => { + request.photo_link = Some(value.unwrap_or("").to_string()); + }, + "role" => { + request.role = Some(value.unwrap_or("").to_string()); + }, + "type" => { + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "additional-roles" => { + if request.additional_roles.is_none() { + request.additional_roles = Some(Default::default()); + } + request.additional_roles.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "self-link" => { + request.self_link = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _permissions_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.permissions().list(&self.opt.arg_file_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _permissions_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request = api::Permission::default(); + let mut call = self.hub.permissions().patch(&request, &self.opt.arg_file_id, &self.opt.arg_permission_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "transfer-ownership" => { + call = call.transfer_ownership(arg_from_str(value.unwrap_or("false"), err, "transfer-ownership", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "with-link" => { + request.with_link = Some(arg_from_str(value.unwrap_or("false"), err, "with-link", "boolean")); + }, + "domain" => { + request.domain = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "value" => { + request.value = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "auth-key" => { + request.auth_key = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "email-address" => { + request.email_address = Some(value.unwrap_or("").to_string()); + }, + "photo-link" => { + request.photo_link = Some(value.unwrap_or("").to_string()); + }, + "role" => { + request.role = Some(value.unwrap_or("").to_string()); + }, + "type" => { + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "additional-roles" => { + if request.additional_roles.is_none() { + request.additional_roles = Some(Default::default()); + } + request.additional_roles.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "self-link" => { + request.self_link = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _permissions_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request = api::Permission::default(); + let mut call = self.hub.permissions().update(&request, &self.opt.arg_file_id, &self.opt.arg_permission_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "transfer-ownership" => { + call = call.transfer_ownership(arg_from_str(value.unwrap_or("false"), err, "transfer-ownership", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "with-link" => { + request.with_link = Some(arg_from_str(value.unwrap_or("false"), err, "with-link", "boolean")); + }, + "domain" => { + request.domain = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "value" => { + request.value = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "auth-key" => { + request.auth_key = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "email-address" => { + request.email_address = Some(value.unwrap_or("").to_string()); + }, + "photo-link" => { + request.photo_link = Some(value.unwrap_or("").to_string()); + }, + "role" => { + request.role = Some(value.unwrap_or("").to_string()); + }, + "type" => { + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "additional-roles" => { + if request.additional_roles.is_none() { + request.additional_roles = Some(Default::default()); + } + request.additional_roles.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "self-link" => { + request.self_link = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _properties_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.properties().delete(&self.opt.arg_file_id, &self.opt.arg_property_key); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "visibility" => { + call = call.visibility(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + None + } + } + } + } + + fn _properties_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.properties().get(&self.opt.arg_file_id, &self.opt.arg_property_key); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "visibility" => { + call = call.visibility(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _properties_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request = api::Property::default(); + let mut call = self.hub.properties().insert(&request, &self.opt.arg_file_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "value" => { + request.value = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "visibility" => { + request.visibility = Some(value.unwrap_or("").to_string()); + }, + "key" => { + request.key = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request.self_link = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _properties_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.properties().list(&self.opt.arg_file_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _properties_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request = api::Property::default(); + let mut call = self.hub.properties().patch(&request, &self.opt.arg_file_id, &self.opt.arg_property_key); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "visibility" => { + call = call.visibility(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "value" => { + request.value = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "visibility" => { + request.visibility = Some(value.unwrap_or("").to_string()); + }, + "key" => { + request.key = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request.self_link = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _properties_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request = api::Property::default(); + let mut call = self.hub.properties().update(&request, &self.opt.arg_file_id, &self.opt.arg_property_key); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "visibility" => { + call = call.visibility(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "value" => { + request.value = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "visibility" => { + request.visibility = Some(value.unwrap_or("").to_string()); + }, + "key" => { + request.key = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request.self_link = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _realtime_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut download_mode = false; + let mut call = self.hub.realtime().get(&self.opt.arg_file_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "revision" => { + call = call.revision(arg_from_str(value.unwrap_or("-0"), err, "revision", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + if key == "alt" && value.unwrap_or("unset") == "media" { + download_mode = true; + } + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + if !download_mode { + } else { + io::copy(&mut response, &mut ostream).unwrap(); + } + None + } + } + } + } + + fn _realtime_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.realtime().update(&self.opt.arg_file_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "base-revision" => { + call = call.base_revision(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = + if self.opt.cmd_simple { + "simple" + } else if self.opt.cmd_resumable { + "resumable" + } else { + unreachable!() + }; + let mut input_file = input_file_from_opts(&self.opt.arg_file, err); + let mime_type = input_mime_from_opts(&self.opt.arg_mime, err); + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "simple" => call.upload(input_file.unwrap(), mime_type.unwrap()), + "resumable" => call.upload_resumable(input_file.unwrap(), mime_type.unwrap()), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + None + } + } + } + } + + fn _replies_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.replies().delete(&self.opt.arg_file_id, &self.opt.arg_comment_id, &self.opt.arg_reply_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + None + } + } + } + } + + fn _replies_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.replies().get(&self.opt.arg_file_id, &self.opt.arg_comment_id, &self.opt.arg_reply_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "include-deleted" => { + call = call.include_deleted(arg_from_str(value.unwrap_or("false"), err, "include-deleted", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _replies_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request = api::CommentReply::default(); + let mut call = self.hub.replies().insert(&request, &self.opt.arg_file_id, &self.opt.arg_comment_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_author_init(request: &mut api::CommentReply) { + if request.author.is_none() { + request.author = Some(Default::default()); + } + } + + fn request_author_picture_init(request: &mut api::CommentReply) { + request_author_init(request); + if request.author.as_mut().unwrap().picture.is_none() { + request.author.as_mut().unwrap().picture = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "author.picture.url" => { + request_author_picture_init(&mut request); + request.author.as_mut().unwrap().picture.as_mut().unwrap().url = Some(value.unwrap_or("").to_string()); + }, + "author.kind" => { + request_author_picture_init(&mut request); + request.author.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "author.display-name" => { + request_author_picture_init(&mut request); + request.author.as_mut().unwrap().display_name = Some(value.unwrap_or("").to_string()); + }, + "author.permission-id" => { + request_author_picture_init(&mut request); + request.author.as_mut().unwrap().permission_id = Some(value.unwrap_or("").to_string()); + }, + "author.is-authenticated-user" => { + request_author_picture_init(&mut request); + request.author.as_mut().unwrap().is_authenticated_user = Some(arg_from_str(value.unwrap_or("false"), err, "author.is-authenticated-user", "boolean")); + }, + "author.email-address" => { + request_author_picture_init(&mut request); + request.author.as_mut().unwrap().email_address = Some(value.unwrap_or("").to_string()); + }, + "deleted" => { + request_author_init(&mut request); + request.deleted = Some(arg_from_str(value.unwrap_or("false"), err, "deleted", "boolean")); + }, + "html-content" => { + request_author_init(&mut request); + request.html_content = Some(value.unwrap_or("").to_string()); + }, + "content" => { + request_author_init(&mut request); + request.content = Some(value.unwrap_or("").to_string()); + }, + "verb" => { + request_author_init(&mut request); + request.verb = Some(value.unwrap_or("").to_string()); + }, + "reply-id" => { + request_author_init(&mut request); + request.reply_id = Some(value.unwrap_or("").to_string()); + }, + "modified-date" => { + request_author_init(&mut request); + request.modified_date = Some(value.unwrap_or("").to_string()); + }, + "created-date" => { + request_author_init(&mut request); + request.created_date = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _replies_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.replies().list(&self.opt.arg_file_id, &self.opt.arg_comment_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "include-deleted" => { + call = call.include_deleted(arg_from_str(value.unwrap_or("false"), err, "include-deleted", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _replies_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request = api::CommentReply::default(); + let mut call = self.hub.replies().patch(&request, &self.opt.arg_file_id, &self.opt.arg_comment_id, &self.opt.arg_reply_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_author_init(request: &mut api::CommentReply) { + if request.author.is_none() { + request.author = Some(Default::default()); + } + } + + fn request_author_picture_init(request: &mut api::CommentReply) { + request_author_init(request); + if request.author.as_mut().unwrap().picture.is_none() { + request.author.as_mut().unwrap().picture = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "author.picture.url" => { + request_author_picture_init(&mut request); + request.author.as_mut().unwrap().picture.as_mut().unwrap().url = Some(value.unwrap_or("").to_string()); + }, + "author.kind" => { + request_author_picture_init(&mut request); + request.author.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "author.display-name" => { + request_author_picture_init(&mut request); + request.author.as_mut().unwrap().display_name = Some(value.unwrap_or("").to_string()); + }, + "author.permission-id" => { + request_author_picture_init(&mut request); + request.author.as_mut().unwrap().permission_id = Some(value.unwrap_or("").to_string()); + }, + "author.is-authenticated-user" => { + request_author_picture_init(&mut request); + request.author.as_mut().unwrap().is_authenticated_user = Some(arg_from_str(value.unwrap_or("false"), err, "author.is-authenticated-user", "boolean")); + }, + "author.email-address" => { + request_author_picture_init(&mut request); + request.author.as_mut().unwrap().email_address = Some(value.unwrap_or("").to_string()); + }, + "deleted" => { + request_author_init(&mut request); + request.deleted = Some(arg_from_str(value.unwrap_or("false"), err, "deleted", "boolean")); + }, + "html-content" => { + request_author_init(&mut request); + request.html_content = Some(value.unwrap_or("").to_string()); + }, + "content" => { + request_author_init(&mut request); + request.content = Some(value.unwrap_or("").to_string()); + }, + "verb" => { + request_author_init(&mut request); + request.verb = Some(value.unwrap_or("").to_string()); + }, + "reply-id" => { + request_author_init(&mut request); + request.reply_id = Some(value.unwrap_or("").to_string()); + }, + "modified-date" => { + request_author_init(&mut request); + request.modified_date = Some(value.unwrap_or("").to_string()); + }, + "created-date" => { + request_author_init(&mut request); + request.created_date = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _replies_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request = api::CommentReply::default(); + let mut call = self.hub.replies().update(&request, &self.opt.arg_file_id, &self.opt.arg_comment_id, &self.opt.arg_reply_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_author_init(request: &mut api::CommentReply) { + if request.author.is_none() { + request.author = Some(Default::default()); + } + } + + fn request_author_picture_init(request: &mut api::CommentReply) { + request_author_init(request); + if request.author.as_mut().unwrap().picture.is_none() { + request.author.as_mut().unwrap().picture = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "author.picture.url" => { + request_author_picture_init(&mut request); + request.author.as_mut().unwrap().picture.as_mut().unwrap().url = Some(value.unwrap_or("").to_string()); + }, + "author.kind" => { + request_author_picture_init(&mut request); + request.author.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "author.display-name" => { + request_author_picture_init(&mut request); + request.author.as_mut().unwrap().display_name = Some(value.unwrap_or("").to_string()); + }, + "author.permission-id" => { + request_author_picture_init(&mut request); + request.author.as_mut().unwrap().permission_id = Some(value.unwrap_or("").to_string()); + }, + "author.is-authenticated-user" => { + request_author_picture_init(&mut request); + request.author.as_mut().unwrap().is_authenticated_user = Some(arg_from_str(value.unwrap_or("false"), err, "author.is-authenticated-user", "boolean")); + }, + "author.email-address" => { + request_author_picture_init(&mut request); + request.author.as_mut().unwrap().email_address = Some(value.unwrap_or("").to_string()); + }, + "deleted" => { + request_author_init(&mut request); + request.deleted = Some(arg_from_str(value.unwrap_or("false"), err, "deleted", "boolean")); + }, + "html-content" => { + request_author_init(&mut request); + request.html_content = Some(value.unwrap_or("").to_string()); + }, + "content" => { + request_author_init(&mut request); + request.content = Some(value.unwrap_or("").to_string()); + }, + "verb" => { + request_author_init(&mut request); + request.verb = Some(value.unwrap_or("").to_string()); + }, + "reply-id" => { + request_author_init(&mut request); + request.reply_id = Some(value.unwrap_or("").to_string()); + }, + "modified-date" => { + request_author_init(&mut request); + request.modified_date = Some(value.unwrap_or("").to_string()); + }, + "created-date" => { + request_author_init(&mut request); + request.created_date = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _revisions_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.revisions().delete(&self.opt.arg_file_id, &self.opt.arg_revision_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + None + } + } + } + } + + fn _revisions_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.revisions().get(&self.opt.arg_file_id, &self.opt.arg_revision_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _revisions_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.revisions().list(&self.opt.arg_file_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _revisions_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request = api::Revision::default(); + let mut call = self.hub.revisions().patch(&request, &self.opt.arg_file_id, &self.opt.arg_revision_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_last_modifying_user_init(request: &mut api::Revision) { + if request.last_modifying_user.is_none() { + request.last_modifying_user = Some(Default::default()); + } + } + + fn request_last_modifying_user_picture_init(request: &mut api::Revision) { + request_last_modifying_user_init(request); + if request.last_modifying_user.as_mut().unwrap().picture.is_none() { + request.last_modifying_user.as_mut().unwrap().picture = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "mime-type" => { + request.mime_type = Some(value.unwrap_or("").to_string()); + }, + "pinned" => { + request.pinned = Some(arg_from_str(value.unwrap_or("false"), err, "pinned", "boolean")); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "publish-auto" => { + request.publish_auto = Some(arg_from_str(value.unwrap_or("false"), err, "publish-auto", "boolean")); + }, + "published-outside-domain" => { + request.published_outside_domain = Some(arg_from_str(value.unwrap_or("false"), err, "published-outside-domain", "boolean")); + }, + "last-modifying-user.picture.url" => { + request_last_modifying_user_picture_init(&mut request); + request.last_modifying_user.as_mut().unwrap().picture.as_mut().unwrap().url = Some(value.unwrap_or("").to_string()); + }, + "last-modifying-user.kind" => { + request_last_modifying_user_picture_init(&mut request); + request.last_modifying_user.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "last-modifying-user.display-name" => { + request_last_modifying_user_picture_init(&mut request); + request.last_modifying_user.as_mut().unwrap().display_name = Some(value.unwrap_or("").to_string()); + }, + "last-modifying-user.permission-id" => { + request_last_modifying_user_picture_init(&mut request); + request.last_modifying_user.as_mut().unwrap().permission_id = Some(value.unwrap_or("").to_string()); + }, + "last-modifying-user.is-authenticated-user" => { + request_last_modifying_user_picture_init(&mut request); + request.last_modifying_user.as_mut().unwrap().is_authenticated_user = Some(arg_from_str(value.unwrap_or("false"), err, "last-modifying-user.is-authenticated-user", "boolean")); + }, + "last-modifying-user.email-address" => { + request_last_modifying_user_picture_init(&mut request); + request.last_modifying_user.as_mut().unwrap().email_address = Some(value.unwrap_or("").to_string()); + }, + "published-link" => { + request_last_modifying_user_init(&mut request); + request.published_link = Some(value.unwrap_or("").to_string()); + }, + "download-url" => { + request_last_modifying_user_init(&mut request); + request.download_url = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_last_modifying_user_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request_last_modifying_user_init(&mut request); + request.etag = Some(value.unwrap_or("").to_string()); + }, + "file-size" => { + request_last_modifying_user_init(&mut request); + request.file_size = Some(value.unwrap_or("").to_string()); + }, + "export-links" => { + request_last_modifying_user_init(&mut request); + if request.export_links.is_none() { + request.export_links = Some(Default::default()); + } + let (key, value) = parse_kv_arg(value.unwrap_or(""), err, true); + request.export_links.as_mut().unwrap().insert(key.to_string(), value.unwrap_or("").to_string()); + }, + "last-modifying-user-name" => { + request_last_modifying_user_init(&mut request); + request.last_modifying_user_name = Some(value.unwrap_or("").to_string()); + }, + "modified-date" => { + request_last_modifying_user_init(&mut request); + request.modified_date = Some(value.unwrap_or("").to_string()); + }, + "original-filename" => { + request_last_modifying_user_init(&mut request); + request.original_filename = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_last_modifying_user_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "md5-checksum" => { + request_last_modifying_user_init(&mut request); + request.md5_checksum = Some(value.unwrap_or("").to_string()); + }, + "published" => { + request_last_modifying_user_init(&mut request); + request.published = Some(arg_from_str(value.unwrap_or("false"), err, "published", "boolean")); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _revisions_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request = api::Revision::default(); + let mut call = self.hub.revisions().update(&request, &self.opt.arg_file_id, &self.opt.arg_revision_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_last_modifying_user_init(request: &mut api::Revision) { + if request.last_modifying_user.is_none() { + request.last_modifying_user = Some(Default::default()); + } + } + + fn request_last_modifying_user_picture_init(request: &mut api::Revision) { + request_last_modifying_user_init(request); + if request.last_modifying_user.as_mut().unwrap().picture.is_none() { + request.last_modifying_user.as_mut().unwrap().picture = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "mime-type" => { + request.mime_type = Some(value.unwrap_or("").to_string()); + }, + "pinned" => { + request.pinned = Some(arg_from_str(value.unwrap_or("false"), err, "pinned", "boolean")); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "publish-auto" => { + request.publish_auto = Some(arg_from_str(value.unwrap_or("false"), err, "publish-auto", "boolean")); + }, + "published-outside-domain" => { + request.published_outside_domain = Some(arg_from_str(value.unwrap_or("false"), err, "published-outside-domain", "boolean")); + }, + "last-modifying-user.picture.url" => { + request_last_modifying_user_picture_init(&mut request); + request.last_modifying_user.as_mut().unwrap().picture.as_mut().unwrap().url = Some(value.unwrap_or("").to_string()); + }, + "last-modifying-user.kind" => { + request_last_modifying_user_picture_init(&mut request); + request.last_modifying_user.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "last-modifying-user.display-name" => { + request_last_modifying_user_picture_init(&mut request); + request.last_modifying_user.as_mut().unwrap().display_name = Some(value.unwrap_or("").to_string()); + }, + "last-modifying-user.permission-id" => { + request_last_modifying_user_picture_init(&mut request); + request.last_modifying_user.as_mut().unwrap().permission_id = Some(value.unwrap_or("").to_string()); + }, + "last-modifying-user.is-authenticated-user" => { + request_last_modifying_user_picture_init(&mut request); + request.last_modifying_user.as_mut().unwrap().is_authenticated_user = Some(arg_from_str(value.unwrap_or("false"), err, "last-modifying-user.is-authenticated-user", "boolean")); + }, + "last-modifying-user.email-address" => { + request_last_modifying_user_picture_init(&mut request); + request.last_modifying_user.as_mut().unwrap().email_address = Some(value.unwrap_or("").to_string()); + }, + "published-link" => { + request_last_modifying_user_init(&mut request); + request.published_link = Some(value.unwrap_or("").to_string()); + }, + "download-url" => { + request_last_modifying_user_init(&mut request); + request.download_url = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_last_modifying_user_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request_last_modifying_user_init(&mut request); + request.etag = Some(value.unwrap_or("").to_string()); + }, + "file-size" => { + request_last_modifying_user_init(&mut request); + request.file_size = Some(value.unwrap_or("").to_string()); + }, + "export-links" => { + request_last_modifying_user_init(&mut request); + if request.export_links.is_none() { + request.export_links = Some(Default::default()); + } + let (key, value) = parse_kv_arg(value.unwrap_or(""), err, true); + request.export_links.as_mut().unwrap().insert(key.to_string(), value.unwrap_or("").to_string()); + }, + "last-modifying-user-name" => { + request_last_modifying_user_init(&mut request); + request.last_modifying_user_name = Some(value.unwrap_or("").to_string()); + }, + "modified-date" => { + request_last_modifying_user_init(&mut request); + request.modified_date = Some(value.unwrap_or("").to_string()); + }, + "original-filename" => { + request_last_modifying_user_init(&mut request); + request.original_filename = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_last_modifying_user_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "md5-checksum" => { + request_last_modifying_user_init(&mut request); + request.md5_checksum = Some(value.unwrap_or("").to_string()); + }, + "published" => { + request_last_modifying_user_init(&mut request); + request.published = Some(arg_from_str(value.unwrap_or("false"), err, "published", "boolean")); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option<api::Error>, Option<InvalidOptionsError>) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option<api::Error>; + let mut err_opt: Option<InvalidOptionsError> = None; + + if self.opt.cmd_about { + if self.opt.cmd_get { + call_result = self._about_get(dry_run, &mut err); + } else { + unreachable!(); + } + } + else if self.opt.cmd_apps { + if self.opt.cmd_get { + call_result = self._apps_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._apps_list(dry_run, &mut err); + } else { + unreachable!(); + } + } + else if self.opt.cmd_changes { + if self.opt.cmd_get { + call_result = self._changes_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._changes_list(dry_run, &mut err); + } else if self.opt.cmd_watch { + call_result = self._changes_watch(dry_run, &mut err); + } else { + unreachable!(); + } + } + else if self.opt.cmd_channels { + if self.opt.cmd_stop { + call_result = self._channels_stop(dry_run, &mut err); + } else { + unreachable!(); + } + } + else if self.opt.cmd_children { + if self.opt.cmd_delete { + call_result = self._children_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._children_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._children_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._children_list(dry_run, &mut err); + } else { + unreachable!(); + } + } + else if self.opt.cmd_comments { + if self.opt.cmd_delete { + call_result = self._comments_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._comments_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._comments_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._comments_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._comments_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._comments_update(dry_run, &mut err); + } else { + unreachable!(); + } + } + else if self.opt.cmd_files { + if self.opt.cmd_copy { + call_result = self._files_copy(dry_run, &mut err); + } else if self.opt.cmd_delete { + call_result = self._files_delete(dry_run, &mut err); + } else if self.opt.cmd_empty_trash { + call_result = self._files_empty_trash(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._files_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._files_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._files_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._files_patch(dry_run, &mut err); + } else if self.opt.cmd_touch { + call_result = self._files_touch(dry_run, &mut err); + } else if self.opt.cmd_trash { + call_result = self._files_trash(dry_run, &mut err); + } else if self.opt.cmd_untrash { + call_result = self._files_untrash(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._files_update(dry_run, &mut err); + } else if self.opt.cmd_watch { + call_result = self._files_watch(dry_run, &mut err); + } else { + unreachable!(); + } + } + else if self.opt.cmd_parents { + if self.opt.cmd_delete { + call_result = self._parents_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._parents_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._parents_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._parents_list(dry_run, &mut err); + } else { + unreachable!(); + } + } + else if self.opt.cmd_permissions { + if self.opt.cmd_delete { + call_result = self._permissions_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._permissions_get(dry_run, &mut err); + } else if self.opt.cmd_get_id_for_email { + call_result = self._permissions_get_id_for_email(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._permissions_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._permissions_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._permissions_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._permissions_update(dry_run, &mut err); + } else { + unreachable!(); + } + } + else if self.opt.cmd_properties { + if self.opt.cmd_delete { + call_result = self._properties_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._properties_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._properties_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._properties_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._properties_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._properties_update(dry_run, &mut err); + } else { + unreachable!(); + } + } + else if self.opt.cmd_realtime { + if self.opt.cmd_get { + call_result = self._realtime_get(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._realtime_update(dry_run, &mut err); + } else { + unreachable!(); + } + } + else if self.opt.cmd_replies { + if self.opt.cmd_delete { + call_result = self._replies_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._replies_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._replies_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._replies_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._replies_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._replies_update(dry_run, &mut err); + } else { + unreachable!(); + } + } + else if self.opt.cmd_revisions { + if self.opt.cmd_delete { + call_result = self._revisions_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._revisions_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._revisions_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._revisions_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._revisions_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else { + unreachable!(); + } + + if dry_run { + if err.issues.len() > 0 { + err_opt = Some(err); + } + } + (call_result, err_opt) + } + + // Please note that this call will fail if any part of the opt can't be handled + fn new(opt: Options) -> Result<Engine, InvalidOptionsError> { + let (config_dir, secret) = { + let config_dir = match cmn::assure_config_dir_exists(&opt.flag_config_dir) { + Err(e) => return Err(InvalidOptionsError::single(e, 3)), + Ok(p) => p, + }; + + match cmn::application_secret_from_directory(&config_dir, "drive2-secret.json", + "{\"installed\":{\"auth_uri\":\"https://accounts.google.com/o/oauth2/auth\",\"client_secret\":\"hCsslbCUyfehWMmbkG8vTYxG\",\"token_uri\":\"https://accounts.google.com/o/oauth2/token\",\"client_email\":\"\",\"redirect_uris\":[\"urn:ietf:wg:oauth:2.0:oob\",\"oob\"],\"client_x509_cert_url\":\"\",\"client_id\":\"620010449518-9ngf7o4dhs0dka470npqvor6dc5lqb9b.apps.googleusercontent.com\",\"auth_provider_x509_cert_url\":\"https://www.googleapis.com/oauth2/v1/certs\"}}") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new( &secret, DefaultAuthenticatorDelegate, + if opt.flag_debug_auth { + hyper::Client::with_connector(mock::TeeConnector { + connector: hyper::net::HttpConnector(None) + }) + } else { + hyper::Client::new() + }, + JsonTokenStorage { + program_name: "drive2", + db_dir: config_dir.clone(), + }, None); + + let client = + if opt.flag_debug { + hyper::Client::with_connector(mock::TeeConnector { + connector: hyper::net::HttpConnector(None) + }) + } else { + hyper::Client::new() + }; + let engine = Engine { + opt: opt, + hub: api::Drive::new(client, auth), + }; + + match engine._doit(true) { + (_, Some(err)) => Err(err), + _ => Ok(engine), + } + } + + // Execute the call with all the bells and whistles, informing the caller only if there was an error. + // The absense of one indicates success. + fn doit(&self) -> Option<api::Error> { + self._doit(false).0 + } +} + +fn main() { + let opts: Options = Options::docopt().decode().unwrap_or_else(|e| e.exit()); + match Engine::new(opts) { + Err(err) => { + writeln!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + writeln!(io::stderr(), "{:?}", err).ok(); + writeln!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/games1-cli/Cargo.toml b/gen/games1-cli/Cargo.toml new file mode 100644 index 0000000000..93fce522a9 --- /dev/null +++ b/gen/games1-cli/Cargo.toml @@ -0,0 +1,31 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-games1-cli" +version = "0.0.1+20150413" +authors = ["Sebastian Thiel <byronimo@gmail.com>"] +description = "A complete library to interact with Games (protocol v1)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/games1-cli" +homepage = "https://developers.google.com/games/services/" +documentation = "http://byron.github.io/google-apis-rs/google_games1_cli" +license = "MIT" +keywords = ["games", "google", "cli"] + +[[bin]] +name = "games1" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "*" +docopt_macros = "*" +rustc-serialize = "*" +yup-hyper-mock = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-games1] +path = "../games1" diff --git a/gen/games1-cli/LICENSE.md b/gen/games1-cli/LICENSE.md new file mode 100644 index 0000000000..ae22e6ec52 --- /dev/null +++ b/gen/games1-cli/LICENSE.md @@ -0,0 +1,30 @@ +<!--- +DO NOT EDIT ! +This file was generated automatically from 'src/mako/LICENSE.md.mako' +DO NOT EDIT ! +--> +The MIT License (MIT) +===================== + +Copyright © `2015` `Sebastian Thiel` + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the “Software”), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. diff --git a/gen/games1-cli/README.md b/gen/games1-cli/README.md new file mode 100644 index 0000000000..f03dc20a84 --- /dev/null +++ b/gen/games1-cli/README.md @@ -0,0 +1,4 @@ +# HELLO GAMES:V1 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/games1-cli/mkdocs.yml b/gen/games1-cli/mkdocs.yml new file mode 100644 index 0000000000..8d5650e179 --- /dev/null +++ b/gen/games1-cli/mkdocs.yml @@ -0,0 +1,68 @@ +site_name: Games v0.0.1+20150413 +site_url: http://byron.github.io/google-apis-rs/google-games1-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/games1-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['achievement-definitions_list.md', 'Achievement Definitions', 'List'] +- ['achievements_increment.md', 'Achievements', 'Increment'] +- ['achievements_list.md', 'Achievements', 'List'] +- ['achievements_reveal.md', 'Achievements', 'Reveal'] +- ['achievements_set-steps-at-least.md', 'Achievements', 'Set Steps At Least'] +- ['achievements_unlock.md', 'Achievements', 'Unlock'] +- ['achievements_update-multiple.md', 'Achievements', 'Update Multiple'] +- ['applications_get.md', 'Applications', 'Get'] +- ['applications_played.md', 'Applications', 'Played'] +- ['events_list-by-player.md', 'Events', 'List By Player'] +- ['events_list-definitions.md', 'Events', 'List Definitions'] +- ['events_record.md', 'Events', 'Record'] +- ['leaderboards_get.md', 'Leaderboards', 'Get'] +- ['leaderboards_list.md', 'Leaderboards', 'List'] +- ['metagame_get-metagame-config.md', 'Metagame', 'Get Metagame Config'] +- ['metagame_list-categories-by-player.md', 'Metagame', 'List Categories By Player'] +- ['players_get.md', 'Players', 'Get'] +- ['players_list.md', 'Players', 'List'] +- ['pushtokens_remove.md', 'Pushtokens', 'Remove'] +- ['pushtokens_update.md', 'Pushtokens', 'Update'] +- ['quest-milestones_claim.md', 'Quest Milestones', 'Claim'] +- ['quests_accept.md', 'Quests', 'Accept'] +- ['quests_list.md', 'Quests', 'List'] +- ['revisions_check.md', 'Revisions', 'Check'] +- ['rooms_create.md', 'Rooms', 'Create'] +- ['rooms_decline.md', 'Rooms', 'Decline'] +- ['rooms_dismiss.md', 'Rooms', 'Dismiss'] +- ['rooms_get.md', 'Rooms', 'Get'] +- ['rooms_join.md', 'Rooms', 'Join'] +- ['rooms_leave.md', 'Rooms', 'Leave'] +- ['rooms_list.md', 'Rooms', 'List'] +- ['rooms_report-status.md', 'Rooms', 'Report Status'] +- ['scores_get.md', 'Scores', 'Get'] +- ['scores_list.md', 'Scores', 'List'] +- ['scores_list-window.md', 'Scores', 'List Window'] +- ['scores_submit.md', 'Scores', 'Submit'] +- ['scores_submit-multiple.md', 'Scores', 'Submit Multiple'] +- ['snapshots_get.md', 'Snapshots', 'Get'] +- ['snapshots_list.md', 'Snapshots', 'List'] +- ['turn-based-matches_cancel.md', 'Turn Based Matches', 'Cancel'] +- ['turn-based-matches_create.md', 'Turn Based Matches', 'Create'] +- ['turn-based-matches_decline.md', 'Turn Based Matches', 'Decline'] +- ['turn-based-matches_dismiss.md', 'Turn Based Matches', 'Dismiss'] +- ['turn-based-matches_finish.md', 'Turn Based Matches', 'Finish'] +- ['turn-based-matches_get.md', 'Turn Based Matches', 'Get'] +- ['turn-based-matches_join.md', 'Turn Based Matches', 'Join'] +- ['turn-based-matches_leave.md', 'Turn Based Matches', 'Leave'] +- ['turn-based-matches_leave-turn.md', 'Turn Based Matches', 'Leave Turn'] +- ['turn-based-matches_list.md', 'Turn Based Matches', 'List'] +- ['turn-based-matches_rematch.md', 'Turn Based Matches', 'Rematch'] +- ['turn-based-matches_sync.md', 'Turn Based Matches', 'Sync'] +- ['turn-based-matches_take-turn.md', 'Turn Based Matches', 'Take Turn'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/games1-cli/src/cmn.rs b/gen/games1-cli/src/cmn.rs new file mode 100644 index 0000000000..a8d3f46368 --- /dev/null +++ b/gen/games1-cli/src/cmn.rs @@ -0,0 +1,454 @@ +// COPY OF 'src/rust/cli/cmn.rs' +// DO NOT EDIT +use oauth2::{ApplicationSecret, ConsoleApplicationSecret, TokenStorage, Token}; +use rustc_serialize::json; +use mime::Mime; + +use std::fs; +use std::env; +use std::io; +use std::fmt; +use std::path::{Path, PathBuf}; +use std::str::FromStr; +use std::string::ToString; +use std::io::{Write, Read, stdout}; + +use std::default::Default; + +const FIELD_SEP: char = '.'; + +#[derive(Clone, Default)] +pub struct FieldCursor(Vec<String>); + +impl ToString for FieldCursor { + fn to_string(&self) -> String { + self.0.connect(".") + } +} + +impl FieldCursor { + pub fn set(&mut self, value: &str) -> Result<(), CLIError> { + if value.len() == 0 { + return Err(CLIError::Field(FieldError::Empty)) + } + + let mut first_is_field_sep = false; + let mut char_count: usize = 0; + let mut last_c = FIELD_SEP; + let mut num_conscutive_field_seps = 0; + + let mut field = String::new(); + let mut fields = self.0.clone(); + + let push_field = |fs: &mut Vec<String>, f: &mut String| { + if f.len() > 0 { + fs.push(f.clone()); + f.truncate(0); + } + }; + + for (cid, c) in value.chars().enumerate() { + char_count += 1; + + if c == FIELD_SEP { + if cid == 0 { + first_is_field_sep = true; + } + num_conscutive_field_seps += 1; + if cid > 0 && last_c == FIELD_SEP { + if fields.pop().is_none() { + return Err(CLIError::Field(FieldError::PopOnEmpty(value.to_string()))) + } + } else { + push_field(&mut fields, &mut field); + } + } else { + num_conscutive_field_seps = 0; + if cid == 1 { + if first_is_field_sep { + fields.truncate(0); + } + } + field.push(c); + } + + last_c = c; + } + + push_field(&mut fields, &mut field); + + if char_count == 1 && first_is_field_sep { + fields.truncate(0); + } + if char_count > 1 && num_conscutive_field_seps == 1 { + return Err(CLIError::Field(FieldError::TrailingFieldSep(value.to_string()))) + } + + self.0 = fields; + Ok(()) + } + + pub fn num_fields(&self) -> usize { + self.0.len() + } +} + +pub fn parse_kv_arg<'a>(kv: &'a str, err: &mut InvalidOptionsError, for_hashmap: bool) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string(),for_hashmap)); + match kv.find('=') { + None => { + add_err(); + return (kv, None) + }, + Some(pos) => { + let key = &kv[..pos]; + if kv.len() <= pos + 1 { + add_err(); + return (key, None) + } + (key, Some(&kv[pos+1..])) + } + } +} + +pub fn input_file_from_opts(file_path: &str, err: &mut InvalidOptionsError) -> Option<fs::File> { + match fs::File::open(file_path) { + Ok(f) => Some(f), + Err(io_err) => { + err.issues.push(CLIError::Input(InputError::IOError((file_path.to_string(), io_err)))); + None + } + } +} + +pub fn input_mime_from_opts(mime: &str, err: &mut InvalidOptionsError) -> Option<Mime> { + match mime.parse() { + Ok(m) => Some(m), + Err(_) => { + err.issues.push(CLIError::Input(InputError::Mime(mime.to_string()))); + None + } + } +} + +// May panic if we can't open the file - this is anticipated, we can't currently communicate this +// kind of error: TODO: fix this architecture :) +pub fn writer_from_opts(flag: bool, arg: &str) -> Box<Write> { + if !flag || arg == "-" { + Box::new(stdout()) + } else { + Box::new(fs::OpenOptions::new().create(true).write(true).open(arg).unwrap()) + } +} + + +pub fn arg_from_str<T>(arg: &str, err: &mut InvalidOptionsError, + arg_name: &'static str, + arg_type: &'static 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))) + ); + Default::default() + }, + Ok(v) => v, + } +} + +pub struct JsonTokenStorage { + pub program_name: &'static str, + pub db_dir: String, +} + +impl JsonTokenStorage { + fn path(&self, scope_hash: u64) -> PathBuf { + Path::new(&self.db_dir).join(&format!("{}-token-{}.json", self.program_name, scope_hash)) + } +} + +impl TokenStorage for JsonTokenStorage { + type Error = io::Error; + + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, _: &Vec<&str>, token: Option<Token>) -> Option<io::Error> { + match token { + None => { + match fs::remove_file(self.path(scope_hash)) { + Err(err) => + match err.kind() { + io::ErrorKind::NotFound => None, + _ => Some(err) + }, + Ok(_) => None + } + } + Some(token) => { + let json_token = json::encode(&token).unwrap(); + match fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)) { + Ok(mut f) => { + match f.write(json_token.as_bytes()) { + Ok(_) => None, + Err(io_err) => Some(io_err), + } + }, + Err(io_err) => Some(io_err) + } + } + } + } + + fn get(&self, scope_hash: u64, _: &Vec<&str>) -> Result<Option<Token>, io::Error> { + match fs::File::open(&self.path(scope_hash)) { + Ok(mut f) => { + let mut json_string = String::new(); + match f.read_to_string(&mut json_string) { + Ok(_) => Ok(Some(json::decode::<Token>(&json_string).unwrap())), + Err(io_err) => Err(io_err), + } + }, + Err(io_err) => { + match io_err.kind() { + io::ErrorKind::NotFound => Ok(None), + _ => Err(io_err) + } + } + } + } +} + + +#[derive(Debug)] +pub enum ApplicationSecretError { + DecoderError((String, json::DecoderError)), + FormatError(String), +} + +impl fmt::Display for ApplicationSecretError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + match *self { + ApplicationSecretError::DecoderError((ref path, ref err)) + => writeln!(f, "Could not decode file at '{}' with error: {}", + path, err), + ApplicationSecretError::FormatError(ref path) + => writeln!(f, "'installed' field is unset in secret file at '{}'", + path), + } + } +} + +#[derive(Debug)] +pub enum ConfigurationError { + DirectoryCreationFailed((String, io::Error)), + DirectoryUnset, + HomeExpansionFailed(String), + Secret(ApplicationSecretError), + IOError((String, io::Error)), +} + +impl fmt::Display for ConfigurationError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + match *self { + ConfigurationError::DirectoryCreationFailed((ref dir, ref err)) + => writeln!(f, "Directory '{}' could not be created with error: {}", dir, err), + ConfigurationError::DirectoryUnset + => writeln!(f, "--config-dir was unset or empty"), + ConfigurationError::HomeExpansionFailed(ref dir) + => writeln!(f, "Couldn't find HOME directory of current user, failed to expand '{}'", dir), + ConfigurationError::Secret(ref err) + => writeln!(f, "Secret -> {}", err), + ConfigurationError::IOError((ref path, ref err)) + => writeln!(f, "IO operation failed on path '{}' with error: {}", path, err), + } + } +} + +#[derive(Debug)] +pub enum InputError { + IOError((String, io::Error)), + Mime(String), +} + +impl fmt::Display for InputError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + match *self { + InputError::IOError((ref file_path, ref io_err)) + => writeln!(f, "Failed to open '{}' for reading with error: {}", file_path, io_err), + InputError::Mime(ref mime) + => writeln!(f, "'{}' is not a known mime-type", mime), + } + } +} + +#[derive(Debug)] +pub enum FieldError { + PopOnEmpty(String), + TrailingFieldSep(String), + Unknown(String), + Empty, +} + + +impl fmt::Display for FieldError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + match *self { + FieldError::PopOnEmpty(ref field) + => writeln!(f, "'{}': Cannot move up on empty field cursor", field), + FieldError::TrailingFieldSep(ref field) + => writeln!(f, "'{}': Single field separator may not be last character", field), + FieldError::Unknown(ref field) + => writeln!(f, "Field '{}' does not exist", field), + FieldError::Empty + => writeln!(f, "Field names must not be empty"), + } + } +} + + +#[derive(Debug)] +pub enum CLIError { + Configuration(ConfigurationError), + ParseError((&'static str, &'static str, String, String)), + UnknownParameter(String), + InvalidKeyValueSyntax(String, bool), + Input(InputError), + Field(FieldError), +} + +impl fmt::Display for CLIError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + match *self { + CLIError::Configuration(ref err) => write!(f, "Configuration -> {}", err), + CLIError::Input(ref err) => write!(f, "Input -> {}", err), + CLIError::Field(ref err) => write!(f, "Field -> {}", err), + CLIError::ParseError((arg_name, 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) + => writeln!(f, "Parameter '{}' is unknown.", param_name), + CLIError::InvalidKeyValueSyntax(ref kv, is_hashmap) => { + let hashmap_info = if is_hashmap { "hashmap " } else { "" }; + writeln!(f, "'{}' does not match {}pattern <key>=<value>", kv, hashmap_info) + }, + } + } +} + +#[derive(Debug)] +pub struct InvalidOptionsError { + pub issues: Vec<CLIError>, + pub exit_code: i32, +} + +impl fmt::Display for InvalidOptionsError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + for issue in &self.issues { + try!(issue.fmt(f)); + } + Ok(()) + } +} + +impl InvalidOptionsError { + pub fn single(err: CLIError, exit_code: i32) -> InvalidOptionsError { + InvalidOptionsError { + issues: vec![err], + exit_code: exit_code, + } + } + + pub fn new() -> InvalidOptionsError { + InvalidOptionsError { + issues: Vec::new(), + exit_code: 1, + } + } +} + +pub fn assure_config_dir_exists(dir: &str) -> Result<String, CLIError> { + let trdir = dir.trim(); + if trdir.len() == 0 { + return Err(CLIError::Configuration(ConfigurationError::DirectoryUnset)) + } + + let expanded_config_dir = + if trdir.as_bytes()[0] == b'~' { + match env::var("HOME").ok().or(env::var("UserProfile").ok()) { + None => return Err(CLIError::Configuration(ConfigurationError::HomeExpansionFailed(trdir.to_string()))), + Some(mut user) => { + user.push_str(&trdir[1..]); + user + } + } + } else { + trdir.to_string() + }; + + if let Err(err) = fs::create_dir(&expanded_config_dir) { + if err.kind() != io::ErrorKind::AlreadyExists { + return Err(CLIError::Configuration( + ConfigurationError::DirectoryCreationFailed((expanded_config_dir, err)))) + } + } + + Ok(expanded_config_dir) +} + +pub fn application_secret_from_directory(dir: &str, + secret_basename: &str, + json_app_secret: &str) + -> Result<ApplicationSecret, CLIError> { + let secret_path = Path::new(dir).join(secret_basename); + let secret_str = || secret_path.as_path().to_str().unwrap().to_string(); + let secret_io_error = |io_err: io::Error| { + Err(CLIError::Configuration(ConfigurationError::IOError( + (secret_str(), io_err) + ))) + }; + + for _ in 0..2 { + match fs::File::open(&secret_path) { + Err(mut err) => { + if err.kind() == io::ErrorKind::NotFound { + // Write our built-in one - user may adjust the written file at will + + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_app_secret.as_bytes()) { + Err(io_err) => io_err, + Ok(_) => continue, + } + } + }; + // fall through to IO error handling + } + return secret_io_error(err) + }, + Ok(mut f) => { + let mut json_encoded_secret = String::new(); + if let Err(io_err) = f.read_to_string(&mut json_encoded_secret) { + return secret_io_error(io_err) + } + match json::decode::<ConsoleApplicationSecret>(&json_encoded_secret) { + Err(json_decode_error) => return Err(CLIError::Configuration( + ConfigurationError::Secret(ApplicationSecretError::DecoderError( + (secret_str(), json_decode_error) + )))), + Ok(console_secret) => match console_secret.installed { + Some(secret) => return Ok(secret), + None => return Err( + CLIError::Configuration( + ConfigurationError::Secret( + ApplicationSecretError::FormatError(secret_str()) + ))) + }, + } + } + } + } + unreachable!(); +} \ No newline at end of file diff --git a/gen/games1-cli/src/main.rs b/gen/games1-cli/src/main.rs new file mode 100644 index 0000000000..7a81b47593 --- /dev/null +++ b/gen/games1-cli/src/main.rs @@ -0,0 +1,3364 @@ +// DO NOT EDIT ! +// This file was generated automatically from 'src/mako/cli/main.rs.mako' +// DO NOT EDIT ! +#![feature(plugin, exit_status)] +#![plugin(docopt_macros)] +#![allow(unused_variables, unused_imports, dead_code, unused_mut)] + +extern crate docopt; +extern crate yup_oauth2 as oauth2; +extern crate yup_hyper_mock as mock; +extern crate rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_games1 as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + games1 [options] achievement-definitions list [-p <v>]... [-o <out>] + games1 [options] achievements increment <achievement-id> <steps-to-increment> [-p <v>]... [-o <out>] + games1 [options] achievements list <player-id> [-p <v>]... [-o <out>] + games1 [options] achievements reveal <achievement-id> [-p <v>]... [-o <out>] + games1 [options] achievements set-steps-at-least <achievement-id> <steps> [-p <v>]... [-o <out>] + games1 [options] achievements unlock <achievement-id> [-p <v>]... [-o <out>] + games1 [options] achievements update-multiple -r <kv>... [-p <v>]... [-o <out>] + games1 [options] applications get <application-id> [-p <v>]... [-o <out>] + games1 [options] applications played [-p <v>]... + games1 [options] events list-by-player [-p <v>]... [-o <out>] + games1 [options] events list-definitions [-p <v>]... [-o <out>] + games1 [options] events record -r <kv>... [-p <v>]... [-o <out>] + games1 [options] leaderboards get <leaderboard-id> [-p <v>]... [-o <out>] + games1 [options] leaderboards list [-p <v>]... [-o <out>] + games1 [options] metagame get-metagame-config [-p <v>]... [-o <out>] + games1 [options] metagame list-categories-by-player <player-id> <collection> [-p <v>]... [-o <out>] + games1 [options] players get <player-id> [-p <v>]... [-o <out>] + games1 [options] players list <collection> [-p <v>]... [-o <out>] + games1 [options] pushtokens remove -r <kv>... [-p <v>]... + games1 [options] pushtokens update -r <kv>... [-p <v>]... + games1 [options] quest-milestones claim <quest-id> <milestone-id> <request-id> [-p <v>]... + games1 [options] quests accept <quest-id> [-p <v>]... [-o <out>] + games1 [options] quests list <player-id> [-p <v>]... [-o <out>] + games1 [options] revisions check <client-revision> [-p <v>]... [-o <out>] + games1 [options] rooms create -r <kv>... [-p <v>]... [-o <out>] + games1 [options] rooms decline <room-id> [-p <v>]... [-o <out>] + games1 [options] rooms dismiss <room-id> [-p <v>]... + games1 [options] rooms get <room-id> [-p <v>]... [-o <out>] + games1 [options] rooms join <room-id> -r <kv>... [-p <v>]... [-o <out>] + games1 [options] rooms leave <room-id> -r <kv>... [-p <v>]... [-o <out>] + games1 [options] rooms list [-p <v>]... [-o <out>] + games1 [options] rooms report-status <room-id> -r <kv>... [-p <v>]... [-o <out>] + games1 [options] scores get <player-id> <leaderboard-id> <time-span> [-p <v>]... [-o <out>] + games1 [options] scores list <leaderboard-id> <collection> <time-span> [-p <v>]... [-o <out>] + games1 [options] scores list-window <leaderboard-id> <collection> <time-span> [-p <v>]... [-o <out>] + games1 [options] scores submit <leaderboard-id> <score> [-p <v>]... [-o <out>] + games1 [options] scores submit-multiple -r <kv>... [-p <v>]... [-o <out>] + games1 [options] snapshots get <snapshot-id> [-p <v>]... [-o <out>] + games1 [options] snapshots list <player-id> [-p <v>]... [-o <out>] + games1 [options] turn-based-matches cancel <match-id> [-p <v>]... + games1 [options] turn-based-matches create -r <kv>... [-p <v>]... [-o <out>] + games1 [options] turn-based-matches decline <match-id> [-p <v>]... [-o <out>] + games1 [options] turn-based-matches dismiss <match-id> [-p <v>]... + games1 [options] turn-based-matches finish <match-id> -r <kv>... [-p <v>]... [-o <out>] + games1 [options] turn-based-matches get <match-id> [-p <v>]... [-o <out>] + games1 [options] turn-based-matches join <match-id> [-p <v>]... [-o <out>] + games1 [options] turn-based-matches leave <match-id> [-p <v>]... [-o <out>] + games1 [options] turn-based-matches leave-turn <match-id> <match-version> [-p <v>]... [-o <out>] + games1 [options] turn-based-matches list [-p <v>]... [-o <out>] + games1 [options] turn-based-matches rematch <match-id> [-p <v>]... [-o <out>] + games1 [options] turn-based-matches sync [-p <v>]... [-o <out>] + games1 [options] turn-based-matches take-turn <match-id> -r <kv>... [-p <v>]... [-o <out>] + games1 --help + +All documentation details can be found TODO: <URL to github.io docs here, see #51> + +Configuration: + --scope <url> + 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. + --config-dir <folder> + 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] + --debug + Output all server communication to standard error. `tx` and `rx` are placed into + the same stream. + --debug-auth + Output all communication related to authentication to standard error. `tx` and `rx` are placed into + the same stream. +"); + +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}; + +use std::default::Default; +use std::str::FromStr; + +use oauth2::{Authenticator, DefaultAuthenticatorDelegate}; +use rustc_serialize::json; + +struct Engine { + opt: Options, + hub: api::Games<hyper::Client, Authenticator<DefaultAuthenticatorDelegate, JsonTokenStorage, hyper::Client>>, +} + + +impl Engine { + fn _achievement_definitions_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.achievement_definitions().list(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "language" => { + call = call.language(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _achievements_increment(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let steps_to_increment: i32 = arg_from_str(&self.opt.arg_steps_to_increment, err, "<steps-to-increment>", "integer"); + let mut call = self.hub.achievements().increment(&self.opt.arg_achievement_id, steps_to_increment); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "request-id" => { + call = call.request_id(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _achievements_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.achievements().list(&self.opt.arg_player_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "state" => { + call = call.state(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "language" => { + call = call.language(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _achievements_reveal(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.achievements().reveal(&self.opt.arg_achievement_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _achievements_set_steps_at_least(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let steps: i32 = arg_from_str(&self.opt.arg_steps, err, "<steps>", "integer"); + let mut call = self.hub.achievements().set_steps_at_least(&self.opt.arg_achievement_id, steps); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _achievements_unlock(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.achievements().unlock(&self.opt.arg_achievement_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _achievements_update_multiple(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request = api::AchievementUpdateMultipleRequest::default(); + let mut call = self.hub.achievements().update_multiple(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _applications_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.applications().get(&self.opt.arg_application_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "platform-type" => { + call = call.platform_type(value.unwrap_or("")); + }, + "language" => { + call = call.language(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _applications_played(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.applications().played(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + None + } + } + } + } + + fn _events_list_by_player(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.events().list_by_player(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "language" => { + call = call.language(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _events_list_definitions(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.events().list_definitions(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "language" => { + call = call.language(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _events_record(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request = api::EventRecordRequest::default(); + let mut call = self.hub.events().record(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "language" => { + call = call.language(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "request-id" => { + request.request_id = Some(value.unwrap_or("").to_string()); + }, + "current-time-millis" => { + request.current_time_millis = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _leaderboards_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.leaderboards().get(&self.opt.arg_leaderboard_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "language" => { + call = call.language(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _leaderboards_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.leaderboards().list(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "language" => { + call = call.language(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _metagame_get_metagame_config(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.metagame().get_metagame_config(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _metagame_list_categories_by_player(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.metagame().list_categories_by_player(&self.opt.arg_player_id, &self.opt.arg_collection); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "language" => { + call = call.language(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _players_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.players().get(&self.opt.arg_player_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "language" => { + call = call.language(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _players_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.players().list(&self.opt.arg_collection); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "language" => { + call = call.language(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _pushtokens_remove(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request = api::PushTokenId::default(); + let mut call = self.hub.pushtokens().remove(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_ios_init(request: &mut api::PushTokenId) { + if request.ios.is_none() { + request.ios = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "ios.apns-device-token" => { + request_ios_init(&mut request); + request.ios.as_mut().unwrap().apns_device_token = Some(value.unwrap_or("").to_string()); + }, + "ios.apns-environment" => { + request_ios_init(&mut request); + request.ios.as_mut().unwrap().apns_environment = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + None + } + } + } + } + + fn _pushtokens_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request = api::PushToken::default(); + let mut call = self.hub.pushtokens().update(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_id_init(request: &mut api::PushToken) { + if request.id.is_none() { + request.id = Some(Default::default()); + } + } + + fn request_id_ios_init(request: &mut api::PushToken) { + request_id_init(request); + if request.id.as_mut().unwrap().ios.is_none() { + request.id.as_mut().unwrap().ios = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "client-revision" => { + request.client_revision = Some(value.unwrap_or("").to_string()); + }, + "id.kind" => { + request_id_init(&mut request); + request.id.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "id.ios.apns-device-token" => { + request_id_ios_init(&mut request); + request.id.as_mut().unwrap().ios.as_mut().unwrap().apns_device_token = Some(value.unwrap_or("").to_string()); + }, + "id.ios.apns-environment" => { + request_id_ios_init(&mut request); + request.id.as_mut().unwrap().ios.as_mut().unwrap().apns_environment = Some(value.unwrap_or("").to_string()); + }, + "language" => { + request_id_init(&mut request); + request.language = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + None + } + } + } + } + + fn _quest_milestones_claim(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.quest_milestones().claim(&self.opt.arg_quest_id, &self.opt.arg_milestone_id, &self.opt.arg_request_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + None + } + } + } + } + + fn _quests_accept(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.quests().accept(&self.opt.arg_quest_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "language" => { + call = call.language(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _quests_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.quests().list(&self.opt.arg_player_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "language" => { + call = call.language(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _revisions_check(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.revisions().check(&self.opt.arg_client_revision); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _rooms_create(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request = api::RoomCreateRequest::default(); + let mut call = self.hub.rooms().create(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "language" => { + call = call.language(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_auto_matching_criteria_init(request: &mut api::RoomCreateRequest) { + if request.auto_matching_criteria.is_none() { + request.auto_matching_criteria = Some(Default::default()); + } + } + + fn request_client_address_init(request: &mut api::RoomCreateRequest) { + if request.client_address.is_none() { + request.client_address = Some(Default::default()); + } + } + + fn request_network_diagnostics_init(request: &mut api::RoomCreateRequest) { + if request.network_diagnostics.is_none() { + request.network_diagnostics = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "auto-matching-criteria.kind" => { + request_auto_matching_criteria_init(&mut request); + request.auto_matching_criteria.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "auto-matching-criteria.min-auto-matching-players" => { + request_auto_matching_criteria_init(&mut request); + request.auto_matching_criteria.as_mut().unwrap().min_auto_matching_players = Some(arg_from_str(value.unwrap_or("-0"), err, "auto-matching-criteria.min-auto-matching-players", "integer")); + }, + "auto-matching-criteria.exclusive-bitmask" => { + request_auto_matching_criteria_init(&mut request); + request.auto_matching_criteria.as_mut().unwrap().exclusive_bitmask = Some(value.unwrap_or("").to_string()); + }, + "auto-matching-criteria.max-auto-matching-players" => { + request_auto_matching_criteria_init(&mut request); + request.auto_matching_criteria.as_mut().unwrap().max_auto_matching_players = Some(arg_from_str(value.unwrap_or("-0"), err, "auto-matching-criteria.max-auto-matching-players", "integer")); + }, + "invited-player-ids" => { + request_auto_matching_criteria_init(&mut request); + if request.invited_player_ids.is_none() { + request.invited_player_ids = Some(Default::default()); + } + request.invited_player_ids.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "variant" => { + request_auto_matching_criteria_init(&mut request); + request.variant = Some(arg_from_str(value.unwrap_or("-0"), err, "variant", "integer")); + }, + "capabilities" => { + request_auto_matching_criteria_init(&mut request); + if request.capabilities.is_none() { + request.capabilities = Some(Default::default()); + } + request.capabilities.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "network-diagnostics.kind" => { + request_network_diagnostics_init(&mut request); + request.network_diagnostics.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "network-diagnostics.ios-network-type" => { + request_network_diagnostics_init(&mut request); + request.network_diagnostics.as_mut().unwrap().ios_network_type = Some(arg_from_str(value.unwrap_or("-0"), err, "network-diagnostics.ios-network-type", "integer")); + }, + "network-diagnostics.network-operator-code" => { + request_network_diagnostics_init(&mut request); + request.network_diagnostics.as_mut().unwrap().network_operator_code = Some(value.unwrap_or("").to_string()); + }, + "network-diagnostics.android-network-subtype" => { + request_network_diagnostics_init(&mut request); + request.network_diagnostics.as_mut().unwrap().android_network_subtype = Some(arg_from_str(value.unwrap_or("-0"), err, "network-diagnostics.android-network-subtype", "integer")); + }, + "network-diagnostics.network-operator-name" => { + request_network_diagnostics_init(&mut request); + request.network_diagnostics.as_mut().unwrap().network_operator_name = Some(value.unwrap_or("").to_string()); + }, + "network-diagnostics.registration-latency-millis" => { + request_network_diagnostics_init(&mut request); + request.network_diagnostics.as_mut().unwrap().registration_latency_millis = Some(arg_from_str(value.unwrap_or("-0"), err, "network-diagnostics.registration-latency-millis", "integer")); + }, + "network-diagnostics.android-network-type" => { + request_network_diagnostics_init(&mut request); + request.network_diagnostics.as_mut().unwrap().android_network_type = Some(arg_from_str(value.unwrap_or("-0"), err, "network-diagnostics.android-network-type", "integer")); + }, + "client-address.kind" => { + request_client_address_init(&mut request); + request.client_address.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "client-address.xmpp-address" => { + request_client_address_init(&mut request); + request.client_address.as_mut().unwrap().xmpp_address = Some(value.unwrap_or("").to_string()); + }, + "request-id" => { + request_client_address_init(&mut request); + request.request_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _rooms_decline(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.rooms().decline(&self.opt.arg_room_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "language" => { + call = call.language(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _rooms_dismiss(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.rooms().dismiss(&self.opt.arg_room_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + None + } + } + } + } + + fn _rooms_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.rooms().get(&self.opt.arg_room_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "language" => { + call = call.language(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _rooms_join(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request = api::RoomJoinRequest::default(); + let mut call = self.hub.rooms().join(&request, &self.opt.arg_room_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "language" => { + call = call.language(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_client_address_init(request: &mut api::RoomJoinRequest) { + if request.client_address.is_none() { + request.client_address = Some(Default::default()); + } + } + + fn request_network_diagnostics_init(request: &mut api::RoomJoinRequest) { + if request.network_diagnostics.is_none() { + request.network_diagnostics = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "network-diagnostics.kind" => { + request_network_diagnostics_init(&mut request); + request.network_diagnostics.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "network-diagnostics.ios-network-type" => { + request_network_diagnostics_init(&mut request); + request.network_diagnostics.as_mut().unwrap().ios_network_type = Some(arg_from_str(value.unwrap_or("-0"), err, "network-diagnostics.ios-network-type", "integer")); + }, + "network-diagnostics.network-operator-code" => { + request_network_diagnostics_init(&mut request); + request.network_diagnostics.as_mut().unwrap().network_operator_code = Some(value.unwrap_or("").to_string()); + }, + "network-diagnostics.android-network-subtype" => { + request_network_diagnostics_init(&mut request); + request.network_diagnostics.as_mut().unwrap().android_network_subtype = Some(arg_from_str(value.unwrap_or("-0"), err, "network-diagnostics.android-network-subtype", "integer")); + }, + "network-diagnostics.network-operator-name" => { + request_network_diagnostics_init(&mut request); + request.network_diagnostics.as_mut().unwrap().network_operator_name = Some(value.unwrap_or("").to_string()); + }, + "network-diagnostics.registration-latency-millis" => { + request_network_diagnostics_init(&mut request); + request.network_diagnostics.as_mut().unwrap().registration_latency_millis = Some(arg_from_str(value.unwrap_or("-0"), err, "network-diagnostics.registration-latency-millis", "integer")); + }, + "network-diagnostics.android-network-type" => { + request_network_diagnostics_init(&mut request); + request.network_diagnostics.as_mut().unwrap().android_network_type = Some(arg_from_str(value.unwrap_or("-0"), err, "network-diagnostics.android-network-type", "integer")); + }, + "client-address.kind" => { + request_client_address_init(&mut request); + request.client_address.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "client-address.xmpp-address" => { + request_client_address_init(&mut request); + request.client_address.as_mut().unwrap().xmpp_address = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request_client_address_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "capabilities" => { + request_client_address_init(&mut request); + if request.capabilities.is_none() { + request.capabilities = Some(Default::default()); + } + request.capabilities.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _rooms_leave(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request = api::RoomLeaveRequest::default(); + let mut call = self.hub.rooms().leave(&request, &self.opt.arg_room_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "language" => { + call = call.language(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_leave_diagnostics_init(request: &mut api::RoomLeaveRequest) { + if request.leave_diagnostics.is_none() { + request.leave_diagnostics = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "reason" => { + request.reason = Some(value.unwrap_or("").to_string()); + }, + "leave-diagnostics.kind" => { + request_leave_diagnostics_init(&mut request); + request.leave_diagnostics.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "leave-diagnostics.sockets-used" => { + request_leave_diagnostics_init(&mut request); + request.leave_diagnostics.as_mut().unwrap().sockets_used = Some(arg_from_str(value.unwrap_or("false"), err, "leave-diagnostics.sockets-used", "boolean")); + }, + "leave-diagnostics.ios-network-type" => { + request_leave_diagnostics_init(&mut request); + request.leave_diagnostics.as_mut().unwrap().ios_network_type = Some(arg_from_str(value.unwrap_or("-0"), err, "leave-diagnostics.ios-network-type", "integer")); + }, + "leave-diagnostics.network-operator-code" => { + request_leave_diagnostics_init(&mut request); + request.leave_diagnostics.as_mut().unwrap().network_operator_code = Some(value.unwrap_or("").to_string()); + }, + "leave-diagnostics.android-network-subtype" => { + request_leave_diagnostics_init(&mut request); + request.leave_diagnostics.as_mut().unwrap().android_network_subtype = Some(arg_from_str(value.unwrap_or("-0"), err, "leave-diagnostics.android-network-subtype", "integer")); + }, + "leave-diagnostics.network-operator-name" => { + request_leave_diagnostics_init(&mut request); + request.leave_diagnostics.as_mut().unwrap().network_operator_name = Some(value.unwrap_or("").to_string()); + }, + "leave-diagnostics.android-network-type" => { + request_leave_diagnostics_init(&mut request); + request.leave_diagnostics.as_mut().unwrap().android_network_type = Some(arg_from_str(value.unwrap_or("-0"), err, "leave-diagnostics.android-network-type", "integer")); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _rooms_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.rooms().list(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "language" => { + call = call.language(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _rooms_report_status(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request = api::RoomP2PStatuses::default(); + let mut call = self.hub.rooms().report_status(&request, &self.opt.arg_room_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "language" => { + call = call.language(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _scores_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.scores().get(&self.opt.arg_player_id, &self.opt.arg_leaderboard_id, &self.opt.arg_time_span); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "language" => { + call = call.language(value.unwrap_or("")); + }, + "include-rank-type" => { + call = call.include_rank_type(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _scores_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.scores().list(&self.opt.arg_leaderboard_id, &self.opt.arg_collection, &self.opt.arg_time_span); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "language" => { + call = call.language(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _scores_list_window(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.scores().list_window(&self.opt.arg_leaderboard_id, &self.opt.arg_collection, &self.opt.arg_time_span); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "return-top-if-absent" => { + call = call.return_top_if_absent(arg_from_str(value.unwrap_or("false"), err, "return-top-if-absent", "boolean")); + }, + "results-above" => { + call = call.results_above(arg_from_str(value.unwrap_or("-0"), err, "results-above", "integer")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "language" => { + call = call.language(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _scores_submit(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.scores().submit(&self.opt.arg_leaderboard_id, &self.opt.arg_score); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "score-tag" => { + call = call.score_tag(value.unwrap_or("")); + }, + "language" => { + call = call.language(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _scores_submit_multiple(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request = api::PlayerScoreSubmissionList::default(); + let mut call = self.hub.scores().submit_multiple(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "language" => { + call = call.language(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _snapshots_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.snapshots().get(&self.opt.arg_snapshot_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "language" => { + call = call.language(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _snapshots_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.snapshots().list(&self.opt.arg_player_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "language" => { + call = call.language(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _turn_based_matches_cancel(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.turn_based_matches().cancel(&self.opt.arg_match_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + None + } + } + } + } + + fn _turn_based_matches_create(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request = api::TurnBasedMatchCreateRequest::default(); + let mut call = self.hub.turn_based_matches().create(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "language" => { + call = call.language(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_auto_matching_criteria_init(request: &mut api::TurnBasedMatchCreateRequest) { + if request.auto_matching_criteria.is_none() { + request.auto_matching_criteria = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "invited-player-ids" => { + if request.invited_player_ids.is_none() { + request.invited_player_ids = Some(Default::default()); + } + request.invited_player_ids.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "auto-matching-criteria.kind" => { + request_auto_matching_criteria_init(&mut request); + request.auto_matching_criteria.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "auto-matching-criteria.min-auto-matching-players" => { + request_auto_matching_criteria_init(&mut request); + request.auto_matching_criteria.as_mut().unwrap().min_auto_matching_players = Some(arg_from_str(value.unwrap_or("-0"), err, "auto-matching-criteria.min-auto-matching-players", "integer")); + }, + "auto-matching-criteria.exclusive-bitmask" => { + request_auto_matching_criteria_init(&mut request); + request.auto_matching_criteria.as_mut().unwrap().exclusive_bitmask = Some(value.unwrap_or("").to_string()); + }, + "auto-matching-criteria.max-auto-matching-players" => { + request_auto_matching_criteria_init(&mut request); + request.auto_matching_criteria.as_mut().unwrap().max_auto_matching_players = Some(arg_from_str(value.unwrap_or("-0"), err, "auto-matching-criteria.max-auto-matching-players", "integer")); + }, + "variant" => { + request_auto_matching_criteria_init(&mut request); + request.variant = Some(arg_from_str(value.unwrap_or("-0"), err, "variant", "integer")); + }, + "request-id" => { + request_auto_matching_criteria_init(&mut request); + request.request_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _turn_based_matches_decline(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.turn_based_matches().decline(&self.opt.arg_match_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "language" => { + call = call.language(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _turn_based_matches_dismiss(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.turn_based_matches().dismiss(&self.opt.arg_match_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + None + } + } + } + } + + fn _turn_based_matches_finish(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request = api::TurnBasedMatchResults::default(); + let mut call = self.hub.turn_based_matches().finish(&request, &self.opt.arg_match_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "language" => { + call = call.language(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_data_init(request: &mut api::TurnBasedMatchResults) { + if request.data.is_none() { + request.data = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "data.kind" => { + request_data_init(&mut request); + request.data.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "data.data" => { + request_data_init(&mut request); + request.data.as_mut().unwrap().data = Some(value.unwrap_or("").to_string()); + }, + "match-version" => { + request_data_init(&mut request); + request.match_version = Some(arg_from_str(value.unwrap_or("-0"), err, "match-version", "integer")); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _turn_based_matches_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.turn_based_matches().get(&self.opt.arg_match_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "language" => { + call = call.language(value.unwrap_or("")); + }, + "include-match-data" => { + call = call.include_match_data(arg_from_str(value.unwrap_or("false"), err, "include-match-data", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _turn_based_matches_join(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.turn_based_matches().join(&self.opt.arg_match_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "language" => { + call = call.language(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _turn_based_matches_leave(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.turn_based_matches().leave(&self.opt.arg_match_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "language" => { + call = call.language(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _turn_based_matches_leave_turn(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let match_version: i32 = arg_from_str(&self.opt.arg_match_version, err, "<match-version>", "integer"); + let mut call = self.hub.turn_based_matches().leave_turn(&self.opt.arg_match_id, match_version); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "pending-participant-id" => { + call = call.pending_participant_id(value.unwrap_or("")); + }, + "language" => { + call = call.language(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _turn_based_matches_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.turn_based_matches().list(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "max-completed-matches" => { + call = call.max_completed_matches(arg_from_str(value.unwrap_or("-0"), err, "max-completed-matches", "integer")); + }, + "language" => { + call = call.language(value.unwrap_or("")); + }, + "include-match-data" => { + call = call.include_match_data(arg_from_str(value.unwrap_or("false"), err, "include-match-data", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _turn_based_matches_rematch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.turn_based_matches().rematch(&self.opt.arg_match_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "request-id" => { + call = call.request_id(value.unwrap_or("")); + }, + "language" => { + call = call.language(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _turn_based_matches_sync(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.turn_based_matches().sync(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "max-completed-matches" => { + call = call.max_completed_matches(arg_from_str(value.unwrap_or("-0"), err, "max-completed-matches", "integer")); + }, + "language" => { + call = call.language(value.unwrap_or("")); + }, + "include-match-data" => { + call = call.include_match_data(arg_from_str(value.unwrap_or("false"), err, "include-match-data", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _turn_based_matches_take_turn(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request = api::TurnBasedMatchTurn::default(); + let mut call = self.hub.turn_based_matches().take_turn(&request, &self.opt.arg_match_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "language" => { + call = call.language(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_data_init(request: &mut api::TurnBasedMatchTurn) { + if request.data.is_none() { + request.data = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "data.kind" => { + request_data_init(&mut request); + request.data.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "data.data" => { + request_data_init(&mut request); + request.data.as_mut().unwrap().data = Some(value.unwrap_or("").to_string()); + }, + "match-version" => { + request_data_init(&mut request); + request.match_version = Some(arg_from_str(value.unwrap_or("-0"), err, "match-version", "integer")); + }, + "pending-participant-id" => { + request_data_init(&mut request); + request.pending_participant_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option<api::Error>, Option<InvalidOptionsError>) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option<api::Error>; + let mut err_opt: Option<InvalidOptionsError> = None; + + if self.opt.cmd_achievement_definitions { + if self.opt.cmd_list { + call_result = self._achievement_definitions_list(dry_run, &mut err); + } else { + unreachable!(); + } + } + else if self.opt.cmd_achievements { + if self.opt.cmd_increment { + call_result = self._achievements_increment(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._achievements_list(dry_run, &mut err); + } else if self.opt.cmd_reveal { + call_result = self._achievements_reveal(dry_run, &mut err); + } else if self.opt.cmd_set_steps_at_least { + call_result = self._achievements_set_steps_at_least(dry_run, &mut err); + } else if self.opt.cmd_unlock { + call_result = self._achievements_unlock(dry_run, &mut err); + } else if self.opt.cmd_update_multiple { + call_result = self._achievements_update_multiple(dry_run, &mut err); + } else { + unreachable!(); + } + } + else if self.opt.cmd_applications { + if self.opt.cmd_get { + call_result = self._applications_get(dry_run, &mut err); + } else if self.opt.cmd_played { + call_result = self._applications_played(dry_run, &mut err); + } else { + unreachable!(); + } + } + else if self.opt.cmd_events { + if self.opt.cmd_list_by_player { + call_result = self._events_list_by_player(dry_run, &mut err); + } else if self.opt.cmd_list_definitions { + call_result = self._events_list_definitions(dry_run, &mut err); + } else if self.opt.cmd_record { + call_result = self._events_record(dry_run, &mut err); + } else { + unreachable!(); + } + } + else if self.opt.cmd_leaderboards { + if self.opt.cmd_get { + call_result = self._leaderboards_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._leaderboards_list(dry_run, &mut err); + } else { + unreachable!(); + } + } + else if self.opt.cmd_metagame { + if self.opt.cmd_get_metagame_config { + call_result = self._metagame_get_metagame_config(dry_run, &mut err); + } else if self.opt.cmd_list_categories_by_player { + call_result = self._metagame_list_categories_by_player(dry_run, &mut err); + } else { + unreachable!(); + } + } + else if self.opt.cmd_players { + if self.opt.cmd_get { + call_result = self._players_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._players_list(dry_run, &mut err); + } else { + unreachable!(); + } + } + else if self.opt.cmd_pushtokens { + if self.opt.cmd_remove { + call_result = self._pushtokens_remove(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._pushtokens_update(dry_run, &mut err); + } else { + unreachable!(); + } + } + else if self.opt.cmd_quest_milestones { + if self.opt.cmd_claim { + call_result = self._quest_milestones_claim(dry_run, &mut err); + } else { + unreachable!(); + } + } + else if self.opt.cmd_quests { + if self.opt.cmd_accept { + call_result = self._quests_accept(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._quests_list(dry_run, &mut err); + } else { + unreachable!(); + } + } + else if self.opt.cmd_revisions { + if self.opt.cmd_check { + call_result = self._revisions_check(dry_run, &mut err); + } else { + unreachable!(); + } + } + else if self.opt.cmd_rooms { + if self.opt.cmd_create { + call_result = self._rooms_create(dry_run, &mut err); + } else if self.opt.cmd_decline { + call_result = self._rooms_decline(dry_run, &mut err); + } else if self.opt.cmd_dismiss { + call_result = self._rooms_dismiss(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._rooms_get(dry_run, &mut err); + } else if self.opt.cmd_join { + call_result = self._rooms_join(dry_run, &mut err); + } else if self.opt.cmd_leave { + call_result = self._rooms_leave(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._rooms_list(dry_run, &mut err); + } else if self.opt.cmd_report_status { + call_result = self._rooms_report_status(dry_run, &mut err); + } else { + unreachable!(); + } + } + else if self.opt.cmd_scores { + if self.opt.cmd_get { + call_result = self._scores_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._scores_list(dry_run, &mut err); + } else if self.opt.cmd_list_window { + call_result = self._scores_list_window(dry_run, &mut err); + } else if self.opt.cmd_submit { + call_result = self._scores_submit(dry_run, &mut err); + } else if self.opt.cmd_submit_multiple { + call_result = self._scores_submit_multiple(dry_run, &mut err); + } else { + unreachable!(); + } + } + else if self.opt.cmd_snapshots { + if self.opt.cmd_get { + call_result = self._snapshots_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._snapshots_list(dry_run, &mut err); + } else { + unreachable!(); + } + } + else if self.opt.cmd_turn_based_matches { + if self.opt.cmd_cancel { + call_result = self._turn_based_matches_cancel(dry_run, &mut err); + } else if self.opt.cmd_create { + call_result = self._turn_based_matches_create(dry_run, &mut err); + } else if self.opt.cmd_decline { + call_result = self._turn_based_matches_decline(dry_run, &mut err); + } else if self.opt.cmd_dismiss { + call_result = self._turn_based_matches_dismiss(dry_run, &mut err); + } else if self.opt.cmd_finish { + call_result = self._turn_based_matches_finish(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._turn_based_matches_get(dry_run, &mut err); + } else if self.opt.cmd_join { + call_result = self._turn_based_matches_join(dry_run, &mut err); + } else if self.opt.cmd_leave { + call_result = self._turn_based_matches_leave(dry_run, &mut err); + } else if self.opt.cmd_leave_turn { + call_result = self._turn_based_matches_leave_turn(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._turn_based_matches_list(dry_run, &mut err); + } else if self.opt.cmd_rematch { + call_result = self._turn_based_matches_rematch(dry_run, &mut err); + } else if self.opt.cmd_sync { + call_result = self._turn_based_matches_sync(dry_run, &mut err); + } else if self.opt.cmd_take_turn { + call_result = self._turn_based_matches_take_turn(dry_run, &mut err); + } else { + unreachable!(); + } + } else { + unreachable!(); + } + + if dry_run { + if err.issues.len() > 0 { + err_opt = Some(err); + } + } + (call_result, err_opt) + } + + // Please note that this call will fail if any part of the opt can't be handled + fn new(opt: Options) -> Result<Engine, InvalidOptionsError> { + let (config_dir, secret) = { + let config_dir = match cmn::assure_config_dir_exists(&opt.flag_config_dir) { + Err(e) => return Err(InvalidOptionsError::single(e, 3)), + Ok(p) => p, + }; + + match cmn::application_secret_from_directory(&config_dir, "games1-secret.json", + "{\"installed\":{\"auth_uri\":\"https://accounts.google.com/o/oauth2/auth\",\"client_secret\":\"hCsslbCUyfehWMmbkG8vTYxG\",\"token_uri\":\"https://accounts.google.com/o/oauth2/token\",\"client_email\":\"\",\"redirect_uris\":[\"urn:ietf:wg:oauth:2.0:oob\",\"oob\"],\"client_x509_cert_url\":\"\",\"client_id\":\"620010449518-9ngf7o4dhs0dka470npqvor6dc5lqb9b.apps.googleusercontent.com\",\"auth_provider_x509_cert_url\":\"https://www.googleapis.com/oauth2/v1/certs\"}}") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new( &secret, DefaultAuthenticatorDelegate, + if opt.flag_debug_auth { + hyper::Client::with_connector(mock::TeeConnector { + connector: hyper::net::HttpConnector(None) + }) + } else { + hyper::Client::new() + }, + JsonTokenStorage { + program_name: "games1", + db_dir: config_dir.clone(), + }, None); + + let client = + if opt.flag_debug { + hyper::Client::with_connector(mock::TeeConnector { + connector: hyper::net::HttpConnector(None) + }) + } else { + hyper::Client::new() + }; + let engine = Engine { + opt: opt, + hub: api::Games::new(client, auth), + }; + + match engine._doit(true) { + (_, Some(err)) => Err(err), + _ => Ok(engine), + } + } + + // Execute the call with all the bells and whistles, informing the caller only if there was an error. + // The absense of one indicates success. + fn doit(&self) -> Option<api::Error> { + self._doit(false).0 + } +} + +fn main() { + let opts: Options = Options::docopt().decode().unwrap_or_else(|e| e.exit()); + match Engine::new(opts) { + Err(err) => { + writeln!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + writeln!(io::stderr(), "{:?}", err).ok(); + writeln!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/identitytoolkit3-cli/Cargo.toml b/gen/identitytoolkit3-cli/Cargo.toml new file mode 100644 index 0000000000..4edbe32ba7 --- /dev/null +++ b/gen/identitytoolkit3-cli/Cargo.toml @@ -0,0 +1,31 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-identitytoolkit3-cli" +version = "0.0.1+20150406" +authors = ["Sebastian Thiel <byronimo@gmail.com>"] +description = "A complete library to interact with Identity Toolkit (protocol v3)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/identitytoolkit3-cli" +homepage = "https://developers.google.com/identity-toolkit/v3/" +documentation = "http://byron.github.io/google-apis-rs/google_identitytoolkit3_cli" +license = "MIT" +keywords = ["identitytoolkit", "google", "cli"] + +[[bin]] +name = "identitytoolkit3" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "*" +docopt_macros = "*" +rustc-serialize = "*" +yup-hyper-mock = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-identitytoolkit3] +path = "../identitytoolkit3" diff --git a/gen/identitytoolkit3-cli/LICENSE.md b/gen/identitytoolkit3-cli/LICENSE.md new file mode 100644 index 0000000000..ae22e6ec52 --- /dev/null +++ b/gen/identitytoolkit3-cli/LICENSE.md @@ -0,0 +1,30 @@ +<!--- +DO NOT EDIT ! +This file was generated automatically from 'src/mako/LICENSE.md.mako' +DO NOT EDIT ! +--> +The MIT License (MIT) +===================== + +Copyright © `2015` `Sebastian Thiel` + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the “Software”), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. diff --git a/gen/identitytoolkit3-cli/README.md b/gen/identitytoolkit3-cli/README.md new file mode 100644 index 0000000000..e5bc6ba8ca --- /dev/null +++ b/gen/identitytoolkit3-cli/README.md @@ -0,0 +1,4 @@ +# HELLO IDENTITYTOOLKIT:V3 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/identitytoolkit3-cli/mkdocs.yml b/gen/identitytoolkit3-cli/mkdocs.yml new file mode 100644 index 0000000000..c5daaaa007 --- /dev/null +++ b/gen/identitytoolkit3-cli/mkdocs.yml @@ -0,0 +1,28 @@ +site_name: Identity Toolkit v0.0.1+20150406 +site_url: http://byron.github.io/google-apis-rs/google-identitytoolkit3-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/identitytoolkit3-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['relyingparty_create-auth-uri.md', 'Relyingparty', 'Create Auth Uri'] +- ['relyingparty_delete-account.md', 'Relyingparty', 'Delete Account'] +- ['relyingparty_download-account.md', 'Relyingparty', 'Download Account'] +- ['relyingparty_get-account-info.md', 'Relyingparty', 'Get Account Info'] +- ['relyingparty_get-oob-confirmation-code.md', 'Relyingparty', 'Get Oob Confirmation Code'] +- ['relyingparty_get-public-keys.md', 'Relyingparty', 'Get Public Keys'] +- ['relyingparty_get-recaptcha-param.md', 'Relyingparty', 'Get Recaptcha Param'] +- ['relyingparty_reset-password.md', 'Relyingparty', 'Reset Password'] +- ['relyingparty_set-account-info.md', 'Relyingparty', 'Set Account Info'] +- ['relyingparty_upload-account.md', 'Relyingparty', 'Upload Account'] +- ['relyingparty_verify-assertion.md', 'Relyingparty', 'Verify Assertion'] +- ['relyingparty_verify-password.md', 'Relyingparty', 'Verify Password'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/identitytoolkit3-cli/src/cmn.rs b/gen/identitytoolkit3-cli/src/cmn.rs new file mode 100644 index 0000000000..a8d3f46368 --- /dev/null +++ b/gen/identitytoolkit3-cli/src/cmn.rs @@ -0,0 +1,454 @@ +// COPY OF 'src/rust/cli/cmn.rs' +// DO NOT EDIT +use oauth2::{ApplicationSecret, ConsoleApplicationSecret, TokenStorage, Token}; +use rustc_serialize::json; +use mime::Mime; + +use std::fs; +use std::env; +use std::io; +use std::fmt; +use std::path::{Path, PathBuf}; +use std::str::FromStr; +use std::string::ToString; +use std::io::{Write, Read, stdout}; + +use std::default::Default; + +const FIELD_SEP: char = '.'; + +#[derive(Clone, Default)] +pub struct FieldCursor(Vec<String>); + +impl ToString for FieldCursor { + fn to_string(&self) -> String { + self.0.connect(".") + } +} + +impl FieldCursor { + pub fn set(&mut self, value: &str) -> Result<(), CLIError> { + if value.len() == 0 { + return Err(CLIError::Field(FieldError::Empty)) + } + + let mut first_is_field_sep = false; + let mut char_count: usize = 0; + let mut last_c = FIELD_SEP; + let mut num_conscutive_field_seps = 0; + + let mut field = String::new(); + let mut fields = self.0.clone(); + + let push_field = |fs: &mut Vec<String>, f: &mut String| { + if f.len() > 0 { + fs.push(f.clone()); + f.truncate(0); + } + }; + + for (cid, c) in value.chars().enumerate() { + char_count += 1; + + if c == FIELD_SEP { + if cid == 0 { + first_is_field_sep = true; + } + num_conscutive_field_seps += 1; + if cid > 0 && last_c == FIELD_SEP { + if fields.pop().is_none() { + return Err(CLIError::Field(FieldError::PopOnEmpty(value.to_string()))) + } + } else { + push_field(&mut fields, &mut field); + } + } else { + num_conscutive_field_seps = 0; + if cid == 1 { + if first_is_field_sep { + fields.truncate(0); + } + } + field.push(c); + } + + last_c = c; + } + + push_field(&mut fields, &mut field); + + if char_count == 1 && first_is_field_sep { + fields.truncate(0); + } + if char_count > 1 && num_conscutive_field_seps == 1 { + return Err(CLIError::Field(FieldError::TrailingFieldSep(value.to_string()))) + } + + self.0 = fields; + Ok(()) + } + + pub fn num_fields(&self) -> usize { + self.0.len() + } +} + +pub fn parse_kv_arg<'a>(kv: &'a str, err: &mut InvalidOptionsError, for_hashmap: bool) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string(),for_hashmap)); + match kv.find('=') { + None => { + add_err(); + return (kv, None) + }, + Some(pos) => { + let key = &kv[..pos]; + if kv.len() <= pos + 1 { + add_err(); + return (key, None) + } + (key, Some(&kv[pos+1..])) + } + } +} + +pub fn input_file_from_opts(file_path: &str, err: &mut InvalidOptionsError) -> Option<fs::File> { + match fs::File::open(file_path) { + Ok(f) => Some(f), + Err(io_err) => { + err.issues.push(CLIError::Input(InputError::IOError((file_path.to_string(), io_err)))); + None + } + } +} + +pub fn input_mime_from_opts(mime: &str, err: &mut InvalidOptionsError) -> Option<Mime> { + match mime.parse() { + Ok(m) => Some(m), + Err(_) => { + err.issues.push(CLIError::Input(InputError::Mime(mime.to_string()))); + None + } + } +} + +// May panic if we can't open the file - this is anticipated, we can't currently communicate this +// kind of error: TODO: fix this architecture :) +pub fn writer_from_opts(flag: bool, arg: &str) -> Box<Write> { + if !flag || arg == "-" { + Box::new(stdout()) + } else { + Box::new(fs::OpenOptions::new().create(true).write(true).open(arg).unwrap()) + } +} + + +pub fn arg_from_str<T>(arg: &str, err: &mut InvalidOptionsError, + arg_name: &'static str, + arg_type: &'static 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))) + ); + Default::default() + }, + Ok(v) => v, + } +} + +pub struct JsonTokenStorage { + pub program_name: &'static str, + pub db_dir: String, +} + +impl JsonTokenStorage { + fn path(&self, scope_hash: u64) -> PathBuf { + Path::new(&self.db_dir).join(&format!("{}-token-{}.json", self.program_name, scope_hash)) + } +} + +impl TokenStorage for JsonTokenStorage { + type Error = io::Error; + + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, _: &Vec<&str>, token: Option<Token>) -> Option<io::Error> { + match token { + None => { + match fs::remove_file(self.path(scope_hash)) { + Err(err) => + match err.kind() { + io::ErrorKind::NotFound => None, + _ => Some(err) + }, + Ok(_) => None + } + } + Some(token) => { + let json_token = json::encode(&token).unwrap(); + match fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)) { + Ok(mut f) => { + match f.write(json_token.as_bytes()) { + Ok(_) => None, + Err(io_err) => Some(io_err), + } + }, + Err(io_err) => Some(io_err) + } + } + } + } + + fn get(&self, scope_hash: u64, _: &Vec<&str>) -> Result<Option<Token>, io::Error> { + match fs::File::open(&self.path(scope_hash)) { + Ok(mut f) => { + let mut json_string = String::new(); + match f.read_to_string(&mut json_string) { + Ok(_) => Ok(Some(json::decode::<Token>(&json_string).unwrap())), + Err(io_err) => Err(io_err), + } + }, + Err(io_err) => { + match io_err.kind() { + io::ErrorKind::NotFound => Ok(None), + _ => Err(io_err) + } + } + } + } +} + + +#[derive(Debug)] +pub enum ApplicationSecretError { + DecoderError((String, json::DecoderError)), + FormatError(String), +} + +impl fmt::Display for ApplicationSecretError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + match *self { + ApplicationSecretError::DecoderError((ref path, ref err)) + => writeln!(f, "Could not decode file at '{}' with error: {}", + path, err), + ApplicationSecretError::FormatError(ref path) + => writeln!(f, "'installed' field is unset in secret file at '{}'", + path), + } + } +} + +#[derive(Debug)] +pub enum ConfigurationError { + DirectoryCreationFailed((String, io::Error)), + DirectoryUnset, + HomeExpansionFailed(String), + Secret(ApplicationSecretError), + IOError((String, io::Error)), +} + +impl fmt::Display for ConfigurationError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + match *self { + ConfigurationError::DirectoryCreationFailed((ref dir, ref err)) + => writeln!(f, "Directory '{}' could not be created with error: {}", dir, err), + ConfigurationError::DirectoryUnset + => writeln!(f, "--config-dir was unset or empty"), + ConfigurationError::HomeExpansionFailed(ref dir) + => writeln!(f, "Couldn't find HOME directory of current user, failed to expand '{}'", dir), + ConfigurationError::Secret(ref err) + => writeln!(f, "Secret -> {}", err), + ConfigurationError::IOError((ref path, ref err)) + => writeln!(f, "IO operation failed on path '{}' with error: {}", path, err), + } + } +} + +#[derive(Debug)] +pub enum InputError { + IOError((String, io::Error)), + Mime(String), +} + +impl fmt::Display for InputError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + match *self { + InputError::IOError((ref file_path, ref io_err)) + => writeln!(f, "Failed to open '{}' for reading with error: {}", file_path, io_err), + InputError::Mime(ref mime) + => writeln!(f, "'{}' is not a known mime-type", mime), + } + } +} + +#[derive(Debug)] +pub enum FieldError { + PopOnEmpty(String), + TrailingFieldSep(String), + Unknown(String), + Empty, +} + + +impl fmt::Display for FieldError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + match *self { + FieldError::PopOnEmpty(ref field) + => writeln!(f, "'{}': Cannot move up on empty field cursor", field), + FieldError::TrailingFieldSep(ref field) + => writeln!(f, "'{}': Single field separator may not be last character", field), + FieldError::Unknown(ref field) + => writeln!(f, "Field '{}' does not exist", field), + FieldError::Empty + => writeln!(f, "Field names must not be empty"), + } + } +} + + +#[derive(Debug)] +pub enum CLIError { + Configuration(ConfigurationError), + ParseError((&'static str, &'static str, String, String)), + UnknownParameter(String), + InvalidKeyValueSyntax(String, bool), + Input(InputError), + Field(FieldError), +} + +impl fmt::Display for CLIError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + match *self { + CLIError::Configuration(ref err) => write!(f, "Configuration -> {}", err), + CLIError::Input(ref err) => write!(f, "Input -> {}", err), + CLIError::Field(ref err) => write!(f, "Field -> {}", err), + CLIError::ParseError((arg_name, 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) + => writeln!(f, "Parameter '{}' is unknown.", param_name), + CLIError::InvalidKeyValueSyntax(ref kv, is_hashmap) => { + let hashmap_info = if is_hashmap { "hashmap " } else { "" }; + writeln!(f, "'{}' does not match {}pattern <key>=<value>", kv, hashmap_info) + }, + } + } +} + +#[derive(Debug)] +pub struct InvalidOptionsError { + pub issues: Vec<CLIError>, + pub exit_code: i32, +} + +impl fmt::Display for InvalidOptionsError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + for issue in &self.issues { + try!(issue.fmt(f)); + } + Ok(()) + } +} + +impl InvalidOptionsError { + pub fn single(err: CLIError, exit_code: i32) -> InvalidOptionsError { + InvalidOptionsError { + issues: vec![err], + exit_code: exit_code, + } + } + + pub fn new() -> InvalidOptionsError { + InvalidOptionsError { + issues: Vec::new(), + exit_code: 1, + } + } +} + +pub fn assure_config_dir_exists(dir: &str) -> Result<String, CLIError> { + let trdir = dir.trim(); + if trdir.len() == 0 { + return Err(CLIError::Configuration(ConfigurationError::DirectoryUnset)) + } + + let expanded_config_dir = + if trdir.as_bytes()[0] == b'~' { + match env::var("HOME").ok().or(env::var("UserProfile").ok()) { + None => return Err(CLIError::Configuration(ConfigurationError::HomeExpansionFailed(trdir.to_string()))), + Some(mut user) => { + user.push_str(&trdir[1..]); + user + } + } + } else { + trdir.to_string() + }; + + if let Err(err) = fs::create_dir(&expanded_config_dir) { + if err.kind() != io::ErrorKind::AlreadyExists { + return Err(CLIError::Configuration( + ConfigurationError::DirectoryCreationFailed((expanded_config_dir, err)))) + } + } + + Ok(expanded_config_dir) +} + +pub fn application_secret_from_directory(dir: &str, + secret_basename: &str, + json_app_secret: &str) + -> Result<ApplicationSecret, CLIError> { + let secret_path = Path::new(dir).join(secret_basename); + let secret_str = || secret_path.as_path().to_str().unwrap().to_string(); + let secret_io_error = |io_err: io::Error| { + Err(CLIError::Configuration(ConfigurationError::IOError( + (secret_str(), io_err) + ))) + }; + + for _ in 0..2 { + match fs::File::open(&secret_path) { + Err(mut err) => { + if err.kind() == io::ErrorKind::NotFound { + // Write our built-in one - user may adjust the written file at will + + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_app_secret.as_bytes()) { + Err(io_err) => io_err, + Ok(_) => continue, + } + } + }; + // fall through to IO error handling + } + return secret_io_error(err) + }, + Ok(mut f) => { + let mut json_encoded_secret = String::new(); + if let Err(io_err) = f.read_to_string(&mut json_encoded_secret) { + return secret_io_error(io_err) + } + match json::decode::<ConsoleApplicationSecret>(&json_encoded_secret) { + Err(json_decode_error) => return Err(CLIError::Configuration( + ConfigurationError::Secret(ApplicationSecretError::DecoderError( + (secret_str(), json_decode_error) + )))), + Ok(console_secret) => match console_secret.installed { + Some(secret) => return Ok(secret), + None => return Err( + CLIError::Configuration( + ConfigurationError::Secret( + ApplicationSecretError::FormatError(secret_str()) + ))) + }, + } + } + } + } + unreachable!(); +} \ No newline at end of file diff --git a/gen/identitytoolkit3-cli/src/main.rs b/gen/identitytoolkit3-cli/src/main.rs new file mode 100644 index 0000000000..591940e396 --- /dev/null +++ b/gen/identitytoolkit3-cli/src/main.rs @@ -0,0 +1,1006 @@ +// DO NOT EDIT ! +// This file was generated automatically from 'src/mako/cli/main.rs.mako' +// DO NOT EDIT ! +#![feature(plugin, exit_status)] +#![plugin(docopt_macros)] +#![allow(unused_variables, unused_imports, dead_code, unused_mut)] + +extern crate docopt; +extern crate yup_oauth2 as oauth2; +extern crate yup_hyper_mock as mock; +extern crate rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_identitytoolkit3 as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + identitytoolkit3 [options] relyingparty create-auth-uri -r <kv>... [-p <v>]... [-o <out>] + identitytoolkit3 [options] relyingparty delete-account -r <kv>... [-p <v>]... [-o <out>] + identitytoolkit3 [options] relyingparty download-account -r <kv>... [-p <v>]... [-o <out>] + identitytoolkit3 [options] relyingparty get-account-info -r <kv>... [-p <v>]... [-o <out>] + identitytoolkit3 [options] relyingparty get-oob-confirmation-code -r <kv>... [-p <v>]... [-o <out>] + identitytoolkit3 [options] relyingparty get-public-keys [-p <v>]... [-o <out>] + identitytoolkit3 [options] relyingparty get-recaptcha-param [-p <v>]... [-o <out>] + identitytoolkit3 [options] relyingparty reset-password -r <kv>... [-p <v>]... [-o <out>] + identitytoolkit3 [options] relyingparty set-account-info -r <kv>... [-p <v>]... [-o <out>] + identitytoolkit3 [options] relyingparty upload-account -r <kv>... [-p <v>]... [-o <out>] + identitytoolkit3 [options] relyingparty verify-assertion -r <kv>... [-p <v>]... [-o <out>] + identitytoolkit3 [options] relyingparty verify-password -r <kv>... [-p <v>]... [-o <out>] + identitytoolkit3 --help + +All documentation details can be found TODO: <URL to github.io docs here, see #51> + +Configuration: + --config-dir <folder> + 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] + --debug + Output all server communication to standard error. `tx` and `rx` are placed into + the same stream. + --debug-auth + Output all communication related to authentication to standard error. `tx` and `rx` are placed into + the same stream. +"); + +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}; + +use std::default::Default; +use std::str::FromStr; + +use oauth2::{Authenticator, DefaultAuthenticatorDelegate}; +use rustc_serialize::json; + +struct Engine { + opt: Options, + hub: api::IdentityToolkit<hyper::Client, Authenticator<DefaultAuthenticatorDelegate, JsonTokenStorage, hyper::Client>>, +} + + +impl Engine { + fn _relyingparty_create_auth_uri(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request = api::IdentitytoolkitRelyingpartyCreateAuthUriRequest::default(); + let mut call = self.hub.relyingparty().create_auth_uri(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "openid-realm" => { + request.openid_realm = Some(value.unwrap_or("").to_string()); + }, + "oauth-scope" => { + request.oauth_scope = Some(value.unwrap_or("").to_string()); + }, + "client-id" => { + request.client_id = Some(value.unwrap_or("").to_string()); + }, + "ota-app" => { + request.ota_app = Some(value.unwrap_or("").to_string()); + }, + "oauth-consumer-key" => { + request.oauth_consumer_key = Some(value.unwrap_or("").to_string()); + }, + "provider-id" => { + request.provider_id = Some(value.unwrap_or("").to_string()); + }, + "context" => { + request.context = Some(value.unwrap_or("").to_string()); + }, + "app-id" => { + request.app_id = Some(value.unwrap_or("").to_string()); + }, + "continue-uri" => { + request.continue_uri = Some(value.unwrap_or("").to_string()); + }, + "identifier" => { + request.identifier = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _relyingparty_delete_account(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request = api::IdentitytoolkitRelyingpartyDeleteAccountRequest::default(); + let mut call = self.hub.relyingparty().delete_account(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "local-id" => { + request.local_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _relyingparty_download_account(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request = api::IdentitytoolkitRelyingpartyDownloadAccountRequest::default(); + let mut call = self.hub.relyingparty().download_account(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "next-page-token" => { + request.next_page_token = Some(value.unwrap_or("").to_string()); + }, + "max-results" => { + request.max_results = Some(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _relyingparty_get_account_info(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request = api::IdentitytoolkitRelyingpartyGetAccountInfoRequest::default(); + let mut call = self.hub.relyingparty().get_account_info(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "id-token" => { + request.id_token = Some(value.unwrap_or("").to_string()); + }, + "email" => { + if request.email.is_none() { + request.email = Some(Default::default()); + } + request.email.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "local-id" => { + if request.local_id.is_none() { + request.local_id = Some(Default::default()); + } + request.local_id.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _relyingparty_get_oob_confirmation_code(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request = api::Relyingparty::default(); + let mut call = self.hub.relyingparty().get_oob_confirmation_code(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "request-type" => { + request.request_type = Some(value.unwrap_or("").to_string()); + }, + "id-token" => { + request.id_token = Some(value.unwrap_or("").to_string()); + }, + "challenge" => { + request.challenge = Some(value.unwrap_or("").to_string()); + }, + "new-email" => { + request.new_email = Some(value.unwrap_or("").to_string()); + }, + "user-ip" => { + request.user_ip = Some(value.unwrap_or("").to_string()); + }, + "email" => { + request.email = Some(value.unwrap_or("").to_string()); + }, + "captcha-resp" => { + request.captcha_resp = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _relyingparty_get_public_keys(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.relyingparty().get_public_keys(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _relyingparty_get_recaptcha_param(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.relyingparty().get_recaptcha_param(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _relyingparty_reset_password(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request = api::IdentitytoolkitRelyingpartyResetPasswordRequest::default(); + let mut call = self.hub.relyingparty().reset_password(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "new-password" => { + request.new_password = Some(value.unwrap_or("").to_string()); + }, + "old-password" => { + request.old_password = Some(value.unwrap_or("").to_string()); + }, + "oob-code" => { + request.oob_code = Some(value.unwrap_or("").to_string()); + }, + "email" => { + request.email = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _relyingparty_set_account_info(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request = api::IdentitytoolkitRelyingpartySetAccountInfoRequest::default(); + let mut call = self.hub.relyingparty().set_account_info(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "display-name" => { + request.display_name = Some(value.unwrap_or("").to_string()); + }, + "local-id" => { + request.local_id = Some(value.unwrap_or("").to_string()); + }, + "upgrade-to-federated-login" => { + request.upgrade_to_federated_login = Some(arg_from_str(value.unwrap_or("false"), err, "upgrade-to-federated-login", "boolean")); + }, + "captcha-response" => { + request.captcha_response = Some(value.unwrap_or("").to_string()); + }, + "id-token" => { + request.id_token = Some(value.unwrap_or("").to_string()); + }, + "provider" => { + if request.provider.is_none() { + request.provider = Some(Default::default()); + } + request.provider.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "captcha-challenge" => { + request.captcha_challenge = Some(value.unwrap_or("").to_string()); + }, + "email-verified" => { + request.email_verified = Some(arg_from_str(value.unwrap_or("false"), err, "email-verified", "boolean")); + }, + "oob-code" => { + request.oob_code = Some(value.unwrap_or("").to_string()); + }, + "password" => { + request.password = Some(value.unwrap_or("").to_string()); + }, + "email" => { + request.email = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _relyingparty_upload_account(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request = api::IdentitytoolkitRelyingpartyUploadAccountRequest::default(); + let mut call = self.hub.relyingparty().upload_account(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "salt-separator" => { + request.salt_separator = Some(value.unwrap_or("").to_string()); + }, + "hash-algorithm" => { + request.hash_algorithm = Some(value.unwrap_or("").to_string()); + }, + "memory-cost" => { + request.memory_cost = Some(arg_from_str(value.unwrap_or("-0"), err, "memory-cost", "integer")); + }, + "signer-key" => { + request.signer_key = Some(value.unwrap_or("").to_string()); + }, + "rounds" => { + request.rounds = Some(arg_from_str(value.unwrap_or("-0"), err, "rounds", "integer")); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _relyingparty_verify_assertion(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request = api::IdentitytoolkitRelyingpartyVerifyAssertionRequest::default(); + let mut call = self.hub.relyingparty().verify_assertion(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "request-uri" => { + request.request_uri = Some(value.unwrap_or("").to_string()); + }, + "post-body" => { + request.post_body = Some(value.unwrap_or("").to_string()); + }, + "return-refresh-token" => { + request.return_refresh_token = Some(arg_from_str(value.unwrap_or("false"), err, "return-refresh-token", "boolean")); + }, + "pending-id-token" => { + request.pending_id_token = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _relyingparty_verify_password(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request = api::IdentitytoolkitRelyingpartyVerifyPasswordRequest::default(); + let mut call = self.hub.relyingparty().verify_password(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "captcha-response" => { + request.captcha_response = Some(value.unwrap_or("").to_string()); + }, + "captcha-challenge" => { + request.captcha_challenge = Some(value.unwrap_or("").to_string()); + }, + "password" => { + request.password = Some(value.unwrap_or("").to_string()); + }, + "email" => { + request.email = Some(value.unwrap_or("").to_string()); + }, + "pending-id-token" => { + request.pending_id_token = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option<api::Error>, Option<InvalidOptionsError>) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option<api::Error>; + let mut err_opt: Option<InvalidOptionsError> = None; + + if self.opt.cmd_relyingparty { + if self.opt.cmd_create_auth_uri { + call_result = self._relyingparty_create_auth_uri(dry_run, &mut err); + } else if self.opt.cmd_delete_account { + call_result = self._relyingparty_delete_account(dry_run, &mut err); + } else if self.opt.cmd_download_account { + call_result = self._relyingparty_download_account(dry_run, &mut err); + } else if self.opt.cmd_get_account_info { + call_result = self._relyingparty_get_account_info(dry_run, &mut err); + } else if self.opt.cmd_get_oob_confirmation_code { + call_result = self._relyingparty_get_oob_confirmation_code(dry_run, &mut err); + } else if self.opt.cmd_get_public_keys { + call_result = self._relyingparty_get_public_keys(dry_run, &mut err); + } else if self.opt.cmd_get_recaptcha_param { + call_result = self._relyingparty_get_recaptcha_param(dry_run, &mut err); + } else if self.opt.cmd_reset_password { + call_result = self._relyingparty_reset_password(dry_run, &mut err); + } else if self.opt.cmd_set_account_info { + call_result = self._relyingparty_set_account_info(dry_run, &mut err); + } else if self.opt.cmd_upload_account { + call_result = self._relyingparty_upload_account(dry_run, &mut err); + } else if self.opt.cmd_verify_assertion { + call_result = self._relyingparty_verify_assertion(dry_run, &mut err); + } else if self.opt.cmd_verify_password { + call_result = self._relyingparty_verify_password(dry_run, &mut err); + } else { + unreachable!(); + } + } else { + unreachable!(); + } + + if dry_run { + if err.issues.len() > 0 { + err_opt = Some(err); + } + } + (call_result, err_opt) + } + + // Please note that this call will fail if any part of the opt can't be handled + fn new(opt: Options) -> Result<Engine, InvalidOptionsError> { + let (config_dir, secret) = { + let config_dir = match cmn::assure_config_dir_exists(&opt.flag_config_dir) { + Err(e) => return Err(InvalidOptionsError::single(e, 3)), + Ok(p) => p, + }; + + match cmn::application_secret_from_directory(&config_dir, "identitytoolkit3-secret.json", + "{\"installed\":{\"auth_uri\":\"https://accounts.google.com/o/oauth2/auth\",\"client_secret\":\"hCsslbCUyfehWMmbkG8vTYxG\",\"token_uri\":\"https://accounts.google.com/o/oauth2/token\",\"client_email\":\"\",\"redirect_uris\":[\"urn:ietf:wg:oauth:2.0:oob\",\"oob\"],\"client_x509_cert_url\":\"\",\"client_id\":\"620010449518-9ngf7o4dhs0dka470npqvor6dc5lqb9b.apps.googleusercontent.com\",\"auth_provider_x509_cert_url\":\"https://www.googleapis.com/oauth2/v1/certs\"}}") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new( &secret, DefaultAuthenticatorDelegate, + if opt.flag_debug_auth { + hyper::Client::with_connector(mock::TeeConnector { + connector: hyper::net::HttpConnector(None) + }) + } else { + hyper::Client::new() + }, + JsonTokenStorage { + program_name: "identitytoolkit3", + db_dir: config_dir.clone(), + }, None); + + let client = + if opt.flag_debug { + hyper::Client::with_connector(mock::TeeConnector { + connector: hyper::net::HttpConnector(None) + }) + } else { + hyper::Client::new() + }; + let engine = Engine { + opt: opt, + hub: api::IdentityToolkit::new(client, auth), + }; + + match engine._doit(true) { + (_, Some(err)) => Err(err), + _ => Ok(engine), + } + } + + // Execute the call with all the bells and whistles, informing the caller only if there was an error. + // The absense of one indicates success. + fn doit(&self) -> Option<api::Error> { + self._doit(false).0 + } +} + +fn main() { + let opts: Options = Options::docopt().decode().unwrap_or_else(|e| e.exit()); + match Engine::new(opts) { + Err(err) => { + writeln!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + writeln!(io::stderr(), "{:?}", err).ok(); + writeln!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/logging1_beta3-cli/Cargo.toml b/gen/logging1_beta3-cli/Cargo.toml new file mode 100644 index 0000000000..768bbcf10d --- /dev/null +++ b/gen/logging1_beta3-cli/Cargo.toml @@ -0,0 +1,30 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-logging1_beta3-cli" +version = "0.0.1+20150326" +authors = ["Sebastian Thiel <byronimo@gmail.com>"] +description = "A complete library to interact with logging (protocol v1beta3)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/logging1_beta3-cli" +documentation = "http://byron.github.io/google-apis-rs/google_logging1_beta3_cli" +license = "MIT" +keywords = ["logging", "google", "cli"] + +[[bin]] +name = "logging1-beta3" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "*" +docopt_macros = "*" +rustc-serialize = "*" +yup-hyper-mock = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-logging1_beta3] +path = "../logging1_beta3" diff --git a/gen/logging1_beta3-cli/LICENSE.md b/gen/logging1_beta3-cli/LICENSE.md new file mode 100644 index 0000000000..ae22e6ec52 --- /dev/null +++ b/gen/logging1_beta3-cli/LICENSE.md @@ -0,0 +1,30 @@ +<!--- +DO NOT EDIT ! +This file was generated automatically from 'src/mako/LICENSE.md.mako' +DO NOT EDIT ! +--> +The MIT License (MIT) +===================== + +Copyright © `2015` `Sebastian Thiel` + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the “Software”), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. diff --git a/gen/logging1_beta3-cli/README.md b/gen/logging1_beta3-cli/README.md new file mode 100644 index 0000000000..205b79138c --- /dev/null +++ b/gen/logging1_beta3-cli/README.md @@ -0,0 +1,4 @@ +# HELLO LOGGING:V1BETA3 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/logging1_beta3-cli/mkdocs.yml b/gen/logging1_beta3-cli/mkdocs.yml new file mode 100644 index 0000000000..942f91e6da --- /dev/null +++ b/gen/logging1_beta3-cli/mkdocs.yml @@ -0,0 +1,31 @@ +site_name: logging v0.0.1+20150326 +site_url: http://byron.github.io/google-apis-rs/google-logging1_beta3-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/logging1_beta3-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['projects_log-services-indexes-list.md', 'Projects', 'Log Services Indexes List'] +- ['projects_log-services-list.md', 'Projects', 'Log Services List'] +- ['projects_log-services-sinks-create.md', 'Projects', 'Log Services Sinks Create'] +- ['projects_log-services-sinks-delete.md', 'Projects', 'Log Services Sinks Delete'] +- ['projects_log-services-sinks-get.md', 'Projects', 'Log Services Sinks Get'] +- ['projects_log-services-sinks-list.md', 'Projects', 'Log Services Sinks List'] +- ['projects_log-services-sinks-update.md', 'Projects', 'Log Services Sinks Update'] +- ['projects_logs-delete.md', 'Projects', 'Logs Delete'] +- ['projects_logs-entries-write.md', 'Projects', 'Logs Entries Write'] +- ['projects_logs-list.md', 'Projects', 'Logs List'] +- ['projects_logs-sinks-create.md', 'Projects', 'Logs Sinks Create'] +- ['projects_logs-sinks-delete.md', 'Projects', 'Logs Sinks Delete'] +- ['projects_logs-sinks-get.md', 'Projects', 'Logs Sinks Get'] +- ['projects_logs-sinks-list.md', 'Projects', 'Logs Sinks List'] +- ['projects_logs-sinks-update.md', 'Projects', 'Logs Sinks Update'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/logging1_beta3-cli/src/cmn.rs b/gen/logging1_beta3-cli/src/cmn.rs new file mode 100644 index 0000000000..a8d3f46368 --- /dev/null +++ b/gen/logging1_beta3-cli/src/cmn.rs @@ -0,0 +1,454 @@ +// COPY OF 'src/rust/cli/cmn.rs' +// DO NOT EDIT +use oauth2::{ApplicationSecret, ConsoleApplicationSecret, TokenStorage, Token}; +use rustc_serialize::json; +use mime::Mime; + +use std::fs; +use std::env; +use std::io; +use std::fmt; +use std::path::{Path, PathBuf}; +use std::str::FromStr; +use std::string::ToString; +use std::io::{Write, Read, stdout}; + +use std::default::Default; + +const FIELD_SEP: char = '.'; + +#[derive(Clone, Default)] +pub struct FieldCursor(Vec<String>); + +impl ToString for FieldCursor { + fn to_string(&self) -> String { + self.0.connect(".") + } +} + +impl FieldCursor { + pub fn set(&mut self, value: &str) -> Result<(), CLIError> { + if value.len() == 0 { + return Err(CLIError::Field(FieldError::Empty)) + } + + let mut first_is_field_sep = false; + let mut char_count: usize = 0; + let mut last_c = FIELD_SEP; + let mut num_conscutive_field_seps = 0; + + let mut field = String::new(); + let mut fields = self.0.clone(); + + let push_field = |fs: &mut Vec<String>, f: &mut String| { + if f.len() > 0 { + fs.push(f.clone()); + f.truncate(0); + } + }; + + for (cid, c) in value.chars().enumerate() { + char_count += 1; + + if c == FIELD_SEP { + if cid == 0 { + first_is_field_sep = true; + } + num_conscutive_field_seps += 1; + if cid > 0 && last_c == FIELD_SEP { + if fields.pop().is_none() { + return Err(CLIError::Field(FieldError::PopOnEmpty(value.to_string()))) + } + } else { + push_field(&mut fields, &mut field); + } + } else { + num_conscutive_field_seps = 0; + if cid == 1 { + if first_is_field_sep { + fields.truncate(0); + } + } + field.push(c); + } + + last_c = c; + } + + push_field(&mut fields, &mut field); + + if char_count == 1 && first_is_field_sep { + fields.truncate(0); + } + if char_count > 1 && num_conscutive_field_seps == 1 { + return Err(CLIError::Field(FieldError::TrailingFieldSep(value.to_string()))) + } + + self.0 = fields; + Ok(()) + } + + pub fn num_fields(&self) -> usize { + self.0.len() + } +} + +pub fn parse_kv_arg<'a>(kv: &'a str, err: &mut InvalidOptionsError, for_hashmap: bool) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string(),for_hashmap)); + match kv.find('=') { + None => { + add_err(); + return (kv, None) + }, + Some(pos) => { + let key = &kv[..pos]; + if kv.len() <= pos + 1 { + add_err(); + return (key, None) + } + (key, Some(&kv[pos+1..])) + } + } +} + +pub fn input_file_from_opts(file_path: &str, err: &mut InvalidOptionsError) -> Option<fs::File> { + match fs::File::open(file_path) { + Ok(f) => Some(f), + Err(io_err) => { + err.issues.push(CLIError::Input(InputError::IOError((file_path.to_string(), io_err)))); + None + } + } +} + +pub fn input_mime_from_opts(mime: &str, err: &mut InvalidOptionsError) -> Option<Mime> { + match mime.parse() { + Ok(m) => Some(m), + Err(_) => { + err.issues.push(CLIError::Input(InputError::Mime(mime.to_string()))); + None + } + } +} + +// May panic if we can't open the file - this is anticipated, we can't currently communicate this +// kind of error: TODO: fix this architecture :) +pub fn writer_from_opts(flag: bool, arg: &str) -> Box<Write> { + if !flag || arg == "-" { + Box::new(stdout()) + } else { + Box::new(fs::OpenOptions::new().create(true).write(true).open(arg).unwrap()) + } +} + + +pub fn arg_from_str<T>(arg: &str, err: &mut InvalidOptionsError, + arg_name: &'static str, + arg_type: &'static 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))) + ); + Default::default() + }, + Ok(v) => v, + } +} + +pub struct JsonTokenStorage { + pub program_name: &'static str, + pub db_dir: String, +} + +impl JsonTokenStorage { + fn path(&self, scope_hash: u64) -> PathBuf { + Path::new(&self.db_dir).join(&format!("{}-token-{}.json", self.program_name, scope_hash)) + } +} + +impl TokenStorage for JsonTokenStorage { + type Error = io::Error; + + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, _: &Vec<&str>, token: Option<Token>) -> Option<io::Error> { + match token { + None => { + match fs::remove_file(self.path(scope_hash)) { + Err(err) => + match err.kind() { + io::ErrorKind::NotFound => None, + _ => Some(err) + }, + Ok(_) => None + } + } + Some(token) => { + let json_token = json::encode(&token).unwrap(); + match fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)) { + Ok(mut f) => { + match f.write(json_token.as_bytes()) { + Ok(_) => None, + Err(io_err) => Some(io_err), + } + }, + Err(io_err) => Some(io_err) + } + } + } + } + + fn get(&self, scope_hash: u64, _: &Vec<&str>) -> Result<Option<Token>, io::Error> { + match fs::File::open(&self.path(scope_hash)) { + Ok(mut f) => { + let mut json_string = String::new(); + match f.read_to_string(&mut json_string) { + Ok(_) => Ok(Some(json::decode::<Token>(&json_string).unwrap())), + Err(io_err) => Err(io_err), + } + }, + Err(io_err) => { + match io_err.kind() { + io::ErrorKind::NotFound => Ok(None), + _ => Err(io_err) + } + } + } + } +} + + +#[derive(Debug)] +pub enum ApplicationSecretError { + DecoderError((String, json::DecoderError)), + FormatError(String), +} + +impl fmt::Display for ApplicationSecretError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + match *self { + ApplicationSecretError::DecoderError((ref path, ref err)) + => writeln!(f, "Could not decode file at '{}' with error: {}", + path, err), + ApplicationSecretError::FormatError(ref path) + => writeln!(f, "'installed' field is unset in secret file at '{}'", + path), + } + } +} + +#[derive(Debug)] +pub enum ConfigurationError { + DirectoryCreationFailed((String, io::Error)), + DirectoryUnset, + HomeExpansionFailed(String), + Secret(ApplicationSecretError), + IOError((String, io::Error)), +} + +impl fmt::Display for ConfigurationError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + match *self { + ConfigurationError::DirectoryCreationFailed((ref dir, ref err)) + => writeln!(f, "Directory '{}' could not be created with error: {}", dir, err), + ConfigurationError::DirectoryUnset + => writeln!(f, "--config-dir was unset or empty"), + ConfigurationError::HomeExpansionFailed(ref dir) + => writeln!(f, "Couldn't find HOME directory of current user, failed to expand '{}'", dir), + ConfigurationError::Secret(ref err) + => writeln!(f, "Secret -> {}", err), + ConfigurationError::IOError((ref path, ref err)) + => writeln!(f, "IO operation failed on path '{}' with error: {}", path, err), + } + } +} + +#[derive(Debug)] +pub enum InputError { + IOError((String, io::Error)), + Mime(String), +} + +impl fmt::Display for InputError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + match *self { + InputError::IOError((ref file_path, ref io_err)) + => writeln!(f, "Failed to open '{}' for reading with error: {}", file_path, io_err), + InputError::Mime(ref mime) + => writeln!(f, "'{}' is not a known mime-type", mime), + } + } +} + +#[derive(Debug)] +pub enum FieldError { + PopOnEmpty(String), + TrailingFieldSep(String), + Unknown(String), + Empty, +} + + +impl fmt::Display for FieldError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + match *self { + FieldError::PopOnEmpty(ref field) + => writeln!(f, "'{}': Cannot move up on empty field cursor", field), + FieldError::TrailingFieldSep(ref field) + => writeln!(f, "'{}': Single field separator may not be last character", field), + FieldError::Unknown(ref field) + => writeln!(f, "Field '{}' does not exist", field), + FieldError::Empty + => writeln!(f, "Field names must not be empty"), + } + } +} + + +#[derive(Debug)] +pub enum CLIError { + Configuration(ConfigurationError), + ParseError((&'static str, &'static str, String, String)), + UnknownParameter(String), + InvalidKeyValueSyntax(String, bool), + Input(InputError), + Field(FieldError), +} + +impl fmt::Display for CLIError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + match *self { + CLIError::Configuration(ref err) => write!(f, "Configuration -> {}", err), + CLIError::Input(ref err) => write!(f, "Input -> {}", err), + CLIError::Field(ref err) => write!(f, "Field -> {}", err), + CLIError::ParseError((arg_name, 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) + => writeln!(f, "Parameter '{}' is unknown.", param_name), + CLIError::InvalidKeyValueSyntax(ref kv, is_hashmap) => { + let hashmap_info = if is_hashmap { "hashmap " } else { "" }; + writeln!(f, "'{}' does not match {}pattern <key>=<value>", kv, hashmap_info) + }, + } + } +} + +#[derive(Debug)] +pub struct InvalidOptionsError { + pub issues: Vec<CLIError>, + pub exit_code: i32, +} + +impl fmt::Display for InvalidOptionsError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + for issue in &self.issues { + try!(issue.fmt(f)); + } + Ok(()) + } +} + +impl InvalidOptionsError { + pub fn single(err: CLIError, exit_code: i32) -> InvalidOptionsError { + InvalidOptionsError { + issues: vec![err], + exit_code: exit_code, + } + } + + pub fn new() -> InvalidOptionsError { + InvalidOptionsError { + issues: Vec::new(), + exit_code: 1, + } + } +} + +pub fn assure_config_dir_exists(dir: &str) -> Result<String, CLIError> { + let trdir = dir.trim(); + if trdir.len() == 0 { + return Err(CLIError::Configuration(ConfigurationError::DirectoryUnset)) + } + + let expanded_config_dir = + if trdir.as_bytes()[0] == b'~' { + match env::var("HOME").ok().or(env::var("UserProfile").ok()) { + None => return Err(CLIError::Configuration(ConfigurationError::HomeExpansionFailed(trdir.to_string()))), + Some(mut user) => { + user.push_str(&trdir[1..]); + user + } + } + } else { + trdir.to_string() + }; + + if let Err(err) = fs::create_dir(&expanded_config_dir) { + if err.kind() != io::ErrorKind::AlreadyExists { + return Err(CLIError::Configuration( + ConfigurationError::DirectoryCreationFailed((expanded_config_dir, err)))) + } + } + + Ok(expanded_config_dir) +} + +pub fn application_secret_from_directory(dir: &str, + secret_basename: &str, + json_app_secret: &str) + -> Result<ApplicationSecret, CLIError> { + let secret_path = Path::new(dir).join(secret_basename); + let secret_str = || secret_path.as_path().to_str().unwrap().to_string(); + let secret_io_error = |io_err: io::Error| { + Err(CLIError::Configuration(ConfigurationError::IOError( + (secret_str(), io_err) + ))) + }; + + for _ in 0..2 { + match fs::File::open(&secret_path) { + Err(mut err) => { + if err.kind() == io::ErrorKind::NotFound { + // Write our built-in one - user may adjust the written file at will + + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_app_secret.as_bytes()) { + Err(io_err) => io_err, + Ok(_) => continue, + } + } + }; + // fall through to IO error handling + } + return secret_io_error(err) + }, + Ok(mut f) => { + let mut json_encoded_secret = String::new(); + if let Err(io_err) = f.read_to_string(&mut json_encoded_secret) { + return secret_io_error(io_err) + } + match json::decode::<ConsoleApplicationSecret>(&json_encoded_secret) { + Err(json_decode_error) => return Err(CLIError::Configuration( + ConfigurationError::Secret(ApplicationSecretError::DecoderError( + (secret_str(), json_decode_error) + )))), + Ok(console_secret) => match console_secret.installed { + Some(secret) => return Ok(secret), + None => return Err( + CLIError::Configuration( + ConfigurationError::Secret( + ApplicationSecretError::FormatError(secret_str()) + ))) + }, + } + } + } + } + unreachable!(); +} \ No newline at end of file diff --git a/gen/logging1_beta3-cli/src/main.rs b/gen/logging1_beta3-cli/src/main.rs new file mode 100644 index 0000000000..90723e6595 --- /dev/null +++ b/gen/logging1_beta3-cli/src/main.rs @@ -0,0 +1,1067 @@ +// DO NOT EDIT ! +// This file was generated automatically from 'src/mako/cli/main.rs.mako' +// DO NOT EDIT ! +#![feature(plugin, exit_status)] +#![plugin(docopt_macros)] +#![allow(unused_variables, unused_imports, dead_code, unused_mut)] + +extern crate docopt; +extern crate yup_oauth2 as oauth2; +extern crate yup_hyper_mock as mock; +extern crate rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_logging1_beta3 as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + logging1-beta3 [options] projects log-services-indexes-list <projects-id> <log-services-id> [-p <v>]... [-o <out>] + logging1-beta3 [options] projects log-services-list <projects-id> [-p <v>]... [-o <out>] + logging1-beta3 [options] projects log-services-sinks-create <projects-id> <log-services-id> -r <kv>... [-p <v>]... [-o <out>] + logging1-beta3 [options] projects log-services-sinks-delete <projects-id> <log-services-id> <sinks-id> [-p <v>]... [-o <out>] + logging1-beta3 [options] projects log-services-sinks-get <projects-id> <log-services-id> <sinks-id> [-p <v>]... [-o <out>] + logging1-beta3 [options] projects log-services-sinks-list <projects-id> <log-services-id> [-p <v>]... [-o <out>] + logging1-beta3 [options] projects log-services-sinks-update <projects-id> <log-services-id> <sinks-id> -r <kv>... [-p <v>]... [-o <out>] + logging1-beta3 [options] projects logs-delete <projects-id> <logs-id> [-p <v>]... [-o <out>] + logging1-beta3 [options] projects logs-entries-write <projects-id> <logs-id> -r <kv>... [-p <v>]... [-o <out>] + logging1-beta3 [options] projects logs-list <projects-id> [-p <v>]... [-o <out>] + logging1-beta3 [options] projects logs-sinks-create <projects-id> <logs-id> -r <kv>... [-p <v>]... [-o <out>] + logging1-beta3 [options] projects logs-sinks-delete <projects-id> <logs-id> <sinks-id> [-p <v>]... [-o <out>] + logging1-beta3 [options] projects logs-sinks-get <projects-id> <logs-id> <sinks-id> [-p <v>]... [-o <out>] + logging1-beta3 [options] projects logs-sinks-list <projects-id> <logs-id> [-p <v>]... [-o <out>] + logging1-beta3 [options] projects logs-sinks-update <projects-id> <logs-id> <sinks-id> -r <kv>... [-p <v>]... [-o <out>] + logging1-beta3 --help + +All documentation details can be found TODO: <URL to github.io docs here, see #51> + +Configuration: + --scope <url> + 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. + --config-dir <folder> + 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] + --debug + Output all server communication to standard error. `tx` and `rx` are placed into + the same stream. + --debug-auth + Output all communication related to authentication to standard error. `tx` and `rx` are placed into + the same stream. +"); + +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}; + +use std::default::Default; +use std::str::FromStr; + +use oauth2::{Authenticator, DefaultAuthenticatorDelegate}; +use rustc_serialize::json; + +struct Engine { + opt: Options, + hub: api::Logging<hyper::Client, Authenticator<DefaultAuthenticatorDelegate, JsonTokenStorage, hyper::Client>>, +} + + +impl Engine { + fn _projects_log_services_indexes_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.projects().log_services_indexes_list(&self.opt.arg_projects_id, &self.opt.arg_log_services_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "page-size" => { + call = call.page_size(arg_from_str(value.unwrap_or("-0"), err, "page-size", "integer")); + }, + "log" => { + call = call.log(value.unwrap_or("")); + }, + "index-prefix" => { + call = call.index_prefix(value.unwrap_or("")); + }, + "depth" => { + call = call.depth(arg_from_str(value.unwrap_or("-0"), err, "depth", "integer")); + }, + "$-xgafv" + |"access-token" + |"alt" + |"bearer-token" + |"callback" + |"fields" + |"key" + |"oauth-token" + |"pp" + |"pretty-print" + |"quota-user" => { + let map = [ + ("$-xgafv", "$.xgafv"), + ("access-token", "access_token"), + ("bearer-token", "bearer_token"), + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _projects_log_services_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.projects().log_services_list(&self.opt.arg_projects_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "page-size" => { + call = call.page_size(arg_from_str(value.unwrap_or("-0"), err, "page-size", "integer")); + }, + "log" => { + call = call.log(value.unwrap_or("")); + }, + "$-xgafv" + |"access-token" + |"alt" + |"bearer-token" + |"callback" + |"fields" + |"key" + |"oauth-token" + |"pp" + |"pretty-print" + |"quota-user" => { + let map = [ + ("$-xgafv", "$.xgafv"), + ("access-token", "access_token"), + ("bearer-token", "bearer_token"), + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _projects_log_services_sinks_create(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request = api::LogSink::default(); + let mut call = self.hub.projects().log_services_sinks_create(&request, &self.opt.arg_projects_id, &self.opt.arg_log_services_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "$-xgafv" + |"access-token" + |"alt" + |"bearer-token" + |"callback" + |"fields" + |"key" + |"oauth-token" + |"pp" + |"pretty-print" + |"quota-user" => { + let map = [ + ("$-xgafv", "$.xgafv"), + ("access-token", "access_token"), + ("bearer-token", "bearer_token"), + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "destination" => { + request.destination = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _projects_log_services_sinks_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.projects().log_services_sinks_delete(&self.opt.arg_projects_id, &self.opt.arg_log_services_id, &self.opt.arg_sinks_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "$-xgafv" + |"access-token" + |"alt" + |"bearer-token" + |"callback" + |"fields" + |"key" + |"oauth-token" + |"pp" + |"pretty-print" + |"quota-user" => { + let map = [ + ("$-xgafv", "$.xgafv"), + ("access-token", "access_token"), + ("bearer-token", "bearer_token"), + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _projects_log_services_sinks_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.projects().log_services_sinks_get(&self.opt.arg_projects_id, &self.opt.arg_log_services_id, &self.opt.arg_sinks_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "$-xgafv" + |"access-token" + |"alt" + |"bearer-token" + |"callback" + |"fields" + |"key" + |"oauth-token" + |"pp" + |"pretty-print" + |"quota-user" => { + let map = [ + ("$-xgafv", "$.xgafv"), + ("access-token", "access_token"), + ("bearer-token", "bearer_token"), + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _projects_log_services_sinks_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.projects().log_services_sinks_list(&self.opt.arg_projects_id, &self.opt.arg_log_services_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "$-xgafv" + |"access-token" + |"alt" + |"bearer-token" + |"callback" + |"fields" + |"key" + |"oauth-token" + |"pp" + |"pretty-print" + |"quota-user" => { + let map = [ + ("$-xgafv", "$.xgafv"), + ("access-token", "access_token"), + ("bearer-token", "bearer_token"), + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _projects_log_services_sinks_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request = api::LogSink::default(); + let mut call = self.hub.projects().log_services_sinks_update(&request, &self.opt.arg_projects_id, &self.opt.arg_log_services_id, &self.opt.arg_sinks_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "$-xgafv" + |"access-token" + |"alt" + |"bearer-token" + |"callback" + |"fields" + |"key" + |"oauth-token" + |"pp" + |"pretty-print" + |"quota-user" => { + let map = [ + ("$-xgafv", "$.xgafv"), + ("access-token", "access_token"), + ("bearer-token", "bearer_token"), + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "destination" => { + request.destination = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _projects_logs_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.projects().logs_delete(&self.opt.arg_projects_id, &self.opt.arg_logs_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "$-xgafv" + |"access-token" + |"alt" + |"bearer-token" + |"callback" + |"fields" + |"key" + |"oauth-token" + |"pp" + |"pretty-print" + |"quota-user" => { + let map = [ + ("$-xgafv", "$.xgafv"), + ("access-token", "access_token"), + ("bearer-token", "bearer_token"), + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _projects_logs_entries_write(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request = api::WriteLogEntriesRequest::default(); + let mut call = self.hub.projects().logs_entries_write(&request, &self.opt.arg_projects_id, &self.opt.arg_logs_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "$-xgafv" + |"access-token" + |"alt" + |"bearer-token" + |"callback" + |"fields" + |"key" + |"oauth-token" + |"pp" + |"pretty-print" + |"quota-user" => { + let map = [ + ("$-xgafv", "$.xgafv"), + ("access-token", "access_token"), + ("bearer-token", "bearer_token"), + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "common-labels" => { + if request.common_labels.is_none() { + request.common_labels = Some(Default::default()); + } + let (key, value) = parse_kv_arg(value.unwrap_or(""), err, true); + request.common_labels.as_mut().unwrap().insert(key.to_string(), value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _projects_logs_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.projects().logs_list(&self.opt.arg_projects_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "service-name" => { + call = call.service_name(value.unwrap_or("")); + }, + "service-index-prefix" => { + call = call.service_index_prefix(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "page-size" => { + call = call.page_size(arg_from_str(value.unwrap_or("-0"), err, "page-size", "integer")); + }, + "$-xgafv" + |"access-token" + |"alt" + |"bearer-token" + |"callback" + |"fields" + |"key" + |"oauth-token" + |"pp" + |"pretty-print" + |"quota-user" => { + let map = [ + ("$-xgafv", "$.xgafv"), + ("access-token", "access_token"), + ("bearer-token", "bearer_token"), + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _projects_logs_sinks_create(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request = api::LogSink::default(); + let mut call = self.hub.projects().logs_sinks_create(&request, &self.opt.arg_projects_id, &self.opt.arg_logs_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "$-xgafv" + |"access-token" + |"alt" + |"bearer-token" + |"callback" + |"fields" + |"key" + |"oauth-token" + |"pp" + |"pretty-print" + |"quota-user" => { + let map = [ + ("$-xgafv", "$.xgafv"), + ("access-token", "access_token"), + ("bearer-token", "bearer_token"), + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "destination" => { + request.destination = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _projects_logs_sinks_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.projects().logs_sinks_delete(&self.opt.arg_projects_id, &self.opt.arg_logs_id, &self.opt.arg_sinks_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "$-xgafv" + |"access-token" + |"alt" + |"bearer-token" + |"callback" + |"fields" + |"key" + |"oauth-token" + |"pp" + |"pretty-print" + |"quota-user" => { + let map = [ + ("$-xgafv", "$.xgafv"), + ("access-token", "access_token"), + ("bearer-token", "bearer_token"), + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _projects_logs_sinks_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.projects().logs_sinks_get(&self.opt.arg_projects_id, &self.opt.arg_logs_id, &self.opt.arg_sinks_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "$-xgafv" + |"access-token" + |"alt" + |"bearer-token" + |"callback" + |"fields" + |"key" + |"oauth-token" + |"pp" + |"pretty-print" + |"quota-user" => { + let map = [ + ("$-xgafv", "$.xgafv"), + ("access-token", "access_token"), + ("bearer-token", "bearer_token"), + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _projects_logs_sinks_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.projects().logs_sinks_list(&self.opt.arg_projects_id, &self.opt.arg_logs_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "$-xgafv" + |"access-token" + |"alt" + |"bearer-token" + |"callback" + |"fields" + |"key" + |"oauth-token" + |"pp" + |"pretty-print" + |"quota-user" => { + let map = [ + ("$-xgafv", "$.xgafv"), + ("access-token", "access_token"), + ("bearer-token", "bearer_token"), + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _projects_logs_sinks_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request = api::LogSink::default(); + let mut call = self.hub.projects().logs_sinks_update(&request, &self.opt.arg_projects_id, &self.opt.arg_logs_id, &self.opt.arg_sinks_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "$-xgafv" + |"access-token" + |"alt" + |"bearer-token" + |"callback" + |"fields" + |"key" + |"oauth-token" + |"pp" + |"pretty-print" + |"quota-user" => { + let map = [ + ("$-xgafv", "$.xgafv"), + ("access-token", "access_token"), + ("bearer-token", "bearer_token"), + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "destination" => { + request.destination = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option<api::Error>, Option<InvalidOptionsError>) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option<api::Error>; + let mut err_opt: Option<InvalidOptionsError> = None; + + if self.opt.cmd_projects { + if self.opt.cmd_log_services_indexes_list { + call_result = self._projects_log_services_indexes_list(dry_run, &mut err); + } else if self.opt.cmd_log_services_list { + call_result = self._projects_log_services_list(dry_run, &mut err); + } else if self.opt.cmd_log_services_sinks_create { + call_result = self._projects_log_services_sinks_create(dry_run, &mut err); + } else if self.opt.cmd_log_services_sinks_delete { + call_result = self._projects_log_services_sinks_delete(dry_run, &mut err); + } else if self.opt.cmd_log_services_sinks_get { + call_result = self._projects_log_services_sinks_get(dry_run, &mut err); + } else if self.opt.cmd_log_services_sinks_list { + call_result = self._projects_log_services_sinks_list(dry_run, &mut err); + } else if self.opt.cmd_log_services_sinks_update { + call_result = self._projects_log_services_sinks_update(dry_run, &mut err); + } else if self.opt.cmd_logs_delete { + call_result = self._projects_logs_delete(dry_run, &mut err); + } else if self.opt.cmd_logs_entries_write { + call_result = self._projects_logs_entries_write(dry_run, &mut err); + } else if self.opt.cmd_logs_list { + call_result = self._projects_logs_list(dry_run, &mut err); + } else if self.opt.cmd_logs_sinks_create { + call_result = self._projects_logs_sinks_create(dry_run, &mut err); + } else if self.opt.cmd_logs_sinks_delete { + call_result = self._projects_logs_sinks_delete(dry_run, &mut err); + } else if self.opt.cmd_logs_sinks_get { + call_result = self._projects_logs_sinks_get(dry_run, &mut err); + } else if self.opt.cmd_logs_sinks_list { + call_result = self._projects_logs_sinks_list(dry_run, &mut err); + } else if self.opt.cmd_logs_sinks_update { + call_result = self._projects_logs_sinks_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else { + unreachable!(); + } + + if dry_run { + if err.issues.len() > 0 { + err_opt = Some(err); + } + } + (call_result, err_opt) + } + + // Please note that this call will fail if any part of the opt can't be handled + fn new(opt: Options) -> Result<Engine, InvalidOptionsError> { + let (config_dir, secret) = { + let config_dir = match cmn::assure_config_dir_exists(&opt.flag_config_dir) { + Err(e) => return Err(InvalidOptionsError::single(e, 3)), + Ok(p) => p, + }; + + match cmn::application_secret_from_directory(&config_dir, "logging1-beta3-secret.json", + "{\"installed\":{\"auth_uri\":\"https://accounts.google.com/o/oauth2/auth\",\"client_secret\":\"hCsslbCUyfehWMmbkG8vTYxG\",\"token_uri\":\"https://accounts.google.com/o/oauth2/token\",\"client_email\":\"\",\"redirect_uris\":[\"urn:ietf:wg:oauth:2.0:oob\",\"oob\"],\"client_x509_cert_url\":\"\",\"client_id\":\"620010449518-9ngf7o4dhs0dka470npqvor6dc5lqb9b.apps.googleusercontent.com\",\"auth_provider_x509_cert_url\":\"https://www.googleapis.com/oauth2/v1/certs\"}}") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new( &secret, DefaultAuthenticatorDelegate, + if opt.flag_debug_auth { + hyper::Client::with_connector(mock::TeeConnector { + connector: hyper::net::HttpConnector(None) + }) + } else { + hyper::Client::new() + }, + JsonTokenStorage { + program_name: "logging1-beta3", + db_dir: config_dir.clone(), + }, None); + + let client = + if opt.flag_debug { + hyper::Client::with_connector(mock::TeeConnector { + connector: hyper::net::HttpConnector(None) + }) + } else { + hyper::Client::new() + }; + let engine = Engine { + opt: opt, + hub: api::Logging::new(client, auth), + }; + + match engine._doit(true) { + (_, Some(err)) => Err(err), + _ => Ok(engine), + } + } + + // Execute the call with all the bells and whistles, informing the caller only if there was an error. + // The absense of one indicates success. + fn doit(&self) -> Option<api::Error> { + self._doit(false).0 + } +} + +fn main() { + let opts: Options = Options::docopt().decode().unwrap_or_else(|e| e.exit()); + match Engine::new(opts) { + Err(err) => { + writeln!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + writeln!(io::stderr(), "{:?}", err).ok(); + writeln!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/reseller1_sandbox-cli/Cargo.toml b/gen/reseller1_sandbox-cli/Cargo.toml new file mode 100644 index 0000000000..c77e365f6f --- /dev/null +++ b/gen/reseller1_sandbox-cli/Cargo.toml @@ -0,0 +1,31 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-reseller1_sandbox-cli" +version = "0.0.1+20141112" +authors = ["Sebastian Thiel <byronimo@gmail.com>"] +description = "A complete library to interact with reseller (protocol v1sandbox)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/reseller1_sandbox-cli" +homepage = "https://developers.google.com/google-apps/reseller/" +documentation = "http://byron.github.io/google-apis-rs/google_reseller1_sandbox_cli" +license = "MIT" +keywords = ["reseller", "google", "cli"] + +[[bin]] +name = "reseller1-sandbox" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "*" +docopt_macros = "*" +rustc-serialize = "*" +yup-hyper-mock = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-reseller1_sandbox] +path = "../reseller1_sandbox" diff --git a/gen/reseller1_sandbox-cli/LICENSE.md b/gen/reseller1_sandbox-cli/LICENSE.md new file mode 100644 index 0000000000..ae22e6ec52 --- /dev/null +++ b/gen/reseller1_sandbox-cli/LICENSE.md @@ -0,0 +1,30 @@ +<!--- +DO NOT EDIT ! +This file was generated automatically from 'src/mako/LICENSE.md.mako' +DO NOT EDIT ! +--> +The MIT License (MIT) +===================== + +Copyright © `2015` `Sebastian Thiel` + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the “Software”), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. diff --git a/gen/reseller1_sandbox-cli/README.md b/gen/reseller1_sandbox-cli/README.md new file mode 100644 index 0000000000..9039e1ee49 --- /dev/null +++ b/gen/reseller1_sandbox-cli/README.md @@ -0,0 +1,4 @@ +# HELLO RESELLER:V1SANDBOX + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/reseller1_sandbox-cli/mkdocs.yml b/gen/reseller1_sandbox-cli/mkdocs.yml new file mode 100644 index 0000000000..a19e710f66 --- /dev/null +++ b/gen/reseller1_sandbox-cli/mkdocs.yml @@ -0,0 +1,30 @@ +site_name: reseller v0.0.1+20141112 +site_url: http://byron.github.io/google-apis-rs/google-reseller1_sandbox-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/reseller1_sandbox-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['customers_get.md', 'Customers', 'Get'] +- ['customers_insert.md', 'Customers', 'Insert'] +- ['customers_patch.md', 'Customers', 'Patch'] +- ['customers_update.md', 'Customers', 'Update'] +- ['subscriptions_activate.md', 'Subscriptions', 'Activate'] +- ['subscriptions_change-plan.md', 'Subscriptions', 'Change Plan'] +- ['subscriptions_change-renewal-settings.md', 'Subscriptions', 'Change Renewal Settings'] +- ['subscriptions_change-seats.md', 'Subscriptions', 'Change Seats'] +- ['subscriptions_delete.md', 'Subscriptions', 'Delete'] +- ['subscriptions_get.md', 'Subscriptions', 'Get'] +- ['subscriptions_insert.md', 'Subscriptions', 'Insert'] +- ['subscriptions_list.md', 'Subscriptions', 'List'] +- ['subscriptions_start-paid-service.md', 'Subscriptions', 'Start Paid Service'] +- ['subscriptions_suspend.md', 'Subscriptions', 'Suspend'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/reseller1_sandbox-cli/src/cmn.rs b/gen/reseller1_sandbox-cli/src/cmn.rs new file mode 100644 index 0000000000..a8d3f46368 --- /dev/null +++ b/gen/reseller1_sandbox-cli/src/cmn.rs @@ -0,0 +1,454 @@ +// COPY OF 'src/rust/cli/cmn.rs' +// DO NOT EDIT +use oauth2::{ApplicationSecret, ConsoleApplicationSecret, TokenStorage, Token}; +use rustc_serialize::json; +use mime::Mime; + +use std::fs; +use std::env; +use std::io; +use std::fmt; +use std::path::{Path, PathBuf}; +use std::str::FromStr; +use std::string::ToString; +use std::io::{Write, Read, stdout}; + +use std::default::Default; + +const FIELD_SEP: char = '.'; + +#[derive(Clone, Default)] +pub struct FieldCursor(Vec<String>); + +impl ToString for FieldCursor { + fn to_string(&self) -> String { + self.0.connect(".") + } +} + +impl FieldCursor { + pub fn set(&mut self, value: &str) -> Result<(), CLIError> { + if value.len() == 0 { + return Err(CLIError::Field(FieldError::Empty)) + } + + let mut first_is_field_sep = false; + let mut char_count: usize = 0; + let mut last_c = FIELD_SEP; + let mut num_conscutive_field_seps = 0; + + let mut field = String::new(); + let mut fields = self.0.clone(); + + let push_field = |fs: &mut Vec<String>, f: &mut String| { + if f.len() > 0 { + fs.push(f.clone()); + f.truncate(0); + } + }; + + for (cid, c) in value.chars().enumerate() { + char_count += 1; + + if c == FIELD_SEP { + if cid == 0 { + first_is_field_sep = true; + } + num_conscutive_field_seps += 1; + if cid > 0 && last_c == FIELD_SEP { + if fields.pop().is_none() { + return Err(CLIError::Field(FieldError::PopOnEmpty(value.to_string()))) + } + } else { + push_field(&mut fields, &mut field); + } + } else { + num_conscutive_field_seps = 0; + if cid == 1 { + if first_is_field_sep { + fields.truncate(0); + } + } + field.push(c); + } + + last_c = c; + } + + push_field(&mut fields, &mut field); + + if char_count == 1 && first_is_field_sep { + fields.truncate(0); + } + if char_count > 1 && num_conscutive_field_seps == 1 { + return Err(CLIError::Field(FieldError::TrailingFieldSep(value.to_string()))) + } + + self.0 = fields; + Ok(()) + } + + pub fn num_fields(&self) -> usize { + self.0.len() + } +} + +pub fn parse_kv_arg<'a>(kv: &'a str, err: &mut InvalidOptionsError, for_hashmap: bool) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string(),for_hashmap)); + match kv.find('=') { + None => { + add_err(); + return (kv, None) + }, + Some(pos) => { + let key = &kv[..pos]; + if kv.len() <= pos + 1 { + add_err(); + return (key, None) + } + (key, Some(&kv[pos+1..])) + } + } +} + +pub fn input_file_from_opts(file_path: &str, err: &mut InvalidOptionsError) -> Option<fs::File> { + match fs::File::open(file_path) { + Ok(f) => Some(f), + Err(io_err) => { + err.issues.push(CLIError::Input(InputError::IOError((file_path.to_string(), io_err)))); + None + } + } +} + +pub fn input_mime_from_opts(mime: &str, err: &mut InvalidOptionsError) -> Option<Mime> { + match mime.parse() { + Ok(m) => Some(m), + Err(_) => { + err.issues.push(CLIError::Input(InputError::Mime(mime.to_string()))); + None + } + } +} + +// May panic if we can't open the file - this is anticipated, we can't currently communicate this +// kind of error: TODO: fix this architecture :) +pub fn writer_from_opts(flag: bool, arg: &str) -> Box<Write> { + if !flag || arg == "-" { + Box::new(stdout()) + } else { + Box::new(fs::OpenOptions::new().create(true).write(true).open(arg).unwrap()) + } +} + + +pub fn arg_from_str<T>(arg: &str, err: &mut InvalidOptionsError, + arg_name: &'static str, + arg_type: &'static 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))) + ); + Default::default() + }, + Ok(v) => v, + } +} + +pub struct JsonTokenStorage { + pub program_name: &'static str, + pub db_dir: String, +} + +impl JsonTokenStorage { + fn path(&self, scope_hash: u64) -> PathBuf { + Path::new(&self.db_dir).join(&format!("{}-token-{}.json", self.program_name, scope_hash)) + } +} + +impl TokenStorage for JsonTokenStorage { + type Error = io::Error; + + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, _: &Vec<&str>, token: Option<Token>) -> Option<io::Error> { + match token { + None => { + match fs::remove_file(self.path(scope_hash)) { + Err(err) => + match err.kind() { + io::ErrorKind::NotFound => None, + _ => Some(err) + }, + Ok(_) => None + } + } + Some(token) => { + let json_token = json::encode(&token).unwrap(); + match fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)) { + Ok(mut f) => { + match f.write(json_token.as_bytes()) { + Ok(_) => None, + Err(io_err) => Some(io_err), + } + }, + Err(io_err) => Some(io_err) + } + } + } + } + + fn get(&self, scope_hash: u64, _: &Vec<&str>) -> Result<Option<Token>, io::Error> { + match fs::File::open(&self.path(scope_hash)) { + Ok(mut f) => { + let mut json_string = String::new(); + match f.read_to_string(&mut json_string) { + Ok(_) => Ok(Some(json::decode::<Token>(&json_string).unwrap())), + Err(io_err) => Err(io_err), + } + }, + Err(io_err) => { + match io_err.kind() { + io::ErrorKind::NotFound => Ok(None), + _ => Err(io_err) + } + } + } + } +} + + +#[derive(Debug)] +pub enum ApplicationSecretError { + DecoderError((String, json::DecoderError)), + FormatError(String), +} + +impl fmt::Display for ApplicationSecretError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + match *self { + ApplicationSecretError::DecoderError((ref path, ref err)) + => writeln!(f, "Could not decode file at '{}' with error: {}", + path, err), + ApplicationSecretError::FormatError(ref path) + => writeln!(f, "'installed' field is unset in secret file at '{}'", + path), + } + } +} + +#[derive(Debug)] +pub enum ConfigurationError { + DirectoryCreationFailed((String, io::Error)), + DirectoryUnset, + HomeExpansionFailed(String), + Secret(ApplicationSecretError), + IOError((String, io::Error)), +} + +impl fmt::Display for ConfigurationError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + match *self { + ConfigurationError::DirectoryCreationFailed((ref dir, ref err)) + => writeln!(f, "Directory '{}' could not be created with error: {}", dir, err), + ConfigurationError::DirectoryUnset + => writeln!(f, "--config-dir was unset or empty"), + ConfigurationError::HomeExpansionFailed(ref dir) + => writeln!(f, "Couldn't find HOME directory of current user, failed to expand '{}'", dir), + ConfigurationError::Secret(ref err) + => writeln!(f, "Secret -> {}", err), + ConfigurationError::IOError((ref path, ref err)) + => writeln!(f, "IO operation failed on path '{}' with error: {}", path, err), + } + } +} + +#[derive(Debug)] +pub enum InputError { + IOError((String, io::Error)), + Mime(String), +} + +impl fmt::Display for InputError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + match *self { + InputError::IOError((ref file_path, ref io_err)) + => writeln!(f, "Failed to open '{}' for reading with error: {}", file_path, io_err), + InputError::Mime(ref mime) + => writeln!(f, "'{}' is not a known mime-type", mime), + } + } +} + +#[derive(Debug)] +pub enum FieldError { + PopOnEmpty(String), + TrailingFieldSep(String), + Unknown(String), + Empty, +} + + +impl fmt::Display for FieldError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + match *self { + FieldError::PopOnEmpty(ref field) + => writeln!(f, "'{}': Cannot move up on empty field cursor", field), + FieldError::TrailingFieldSep(ref field) + => writeln!(f, "'{}': Single field separator may not be last character", field), + FieldError::Unknown(ref field) + => writeln!(f, "Field '{}' does not exist", field), + FieldError::Empty + => writeln!(f, "Field names must not be empty"), + } + } +} + + +#[derive(Debug)] +pub enum CLIError { + Configuration(ConfigurationError), + ParseError((&'static str, &'static str, String, String)), + UnknownParameter(String), + InvalidKeyValueSyntax(String, bool), + Input(InputError), + Field(FieldError), +} + +impl fmt::Display for CLIError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + match *self { + CLIError::Configuration(ref err) => write!(f, "Configuration -> {}", err), + CLIError::Input(ref err) => write!(f, "Input -> {}", err), + CLIError::Field(ref err) => write!(f, "Field -> {}", err), + CLIError::ParseError((arg_name, 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) + => writeln!(f, "Parameter '{}' is unknown.", param_name), + CLIError::InvalidKeyValueSyntax(ref kv, is_hashmap) => { + let hashmap_info = if is_hashmap { "hashmap " } else { "" }; + writeln!(f, "'{}' does not match {}pattern <key>=<value>", kv, hashmap_info) + }, + } + } +} + +#[derive(Debug)] +pub struct InvalidOptionsError { + pub issues: Vec<CLIError>, + pub exit_code: i32, +} + +impl fmt::Display for InvalidOptionsError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + for issue in &self.issues { + try!(issue.fmt(f)); + } + Ok(()) + } +} + +impl InvalidOptionsError { + pub fn single(err: CLIError, exit_code: i32) -> InvalidOptionsError { + InvalidOptionsError { + issues: vec![err], + exit_code: exit_code, + } + } + + pub fn new() -> InvalidOptionsError { + InvalidOptionsError { + issues: Vec::new(), + exit_code: 1, + } + } +} + +pub fn assure_config_dir_exists(dir: &str) -> Result<String, CLIError> { + let trdir = dir.trim(); + if trdir.len() == 0 { + return Err(CLIError::Configuration(ConfigurationError::DirectoryUnset)) + } + + let expanded_config_dir = + if trdir.as_bytes()[0] == b'~' { + match env::var("HOME").ok().or(env::var("UserProfile").ok()) { + None => return Err(CLIError::Configuration(ConfigurationError::HomeExpansionFailed(trdir.to_string()))), + Some(mut user) => { + user.push_str(&trdir[1..]); + user + } + } + } else { + trdir.to_string() + }; + + if let Err(err) = fs::create_dir(&expanded_config_dir) { + if err.kind() != io::ErrorKind::AlreadyExists { + return Err(CLIError::Configuration( + ConfigurationError::DirectoryCreationFailed((expanded_config_dir, err)))) + } + } + + Ok(expanded_config_dir) +} + +pub fn application_secret_from_directory(dir: &str, + secret_basename: &str, + json_app_secret: &str) + -> Result<ApplicationSecret, CLIError> { + let secret_path = Path::new(dir).join(secret_basename); + let secret_str = || secret_path.as_path().to_str().unwrap().to_string(); + let secret_io_error = |io_err: io::Error| { + Err(CLIError::Configuration(ConfigurationError::IOError( + (secret_str(), io_err) + ))) + }; + + for _ in 0..2 { + match fs::File::open(&secret_path) { + Err(mut err) => { + if err.kind() == io::ErrorKind::NotFound { + // Write our built-in one - user may adjust the written file at will + + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_app_secret.as_bytes()) { + Err(io_err) => io_err, + Ok(_) => continue, + } + } + }; + // fall through to IO error handling + } + return secret_io_error(err) + }, + Ok(mut f) => { + let mut json_encoded_secret = String::new(); + if let Err(io_err) = f.read_to_string(&mut json_encoded_secret) { + return secret_io_error(io_err) + } + match json::decode::<ConsoleApplicationSecret>(&json_encoded_secret) { + Err(json_decode_error) => return Err(CLIError::Configuration( + ConfigurationError::Secret(ApplicationSecretError::DecoderError( + (secret_str(), json_decode_error) + )))), + Ok(console_secret) => match console_secret.installed { + Some(secret) => return Ok(secret), + None => return Err( + CLIError::Configuration( + ConfigurationError::Secret( + ApplicationSecretError::FormatError(secret_str()) + ))) + }, + } + } + } + } + unreachable!(); +} \ No newline at end of file diff --git a/gen/reseller1_sandbox-cli/src/main.rs b/gen/reseller1_sandbox-cli/src/main.rs new file mode 100644 index 0000000000..ae24f54e40 --- /dev/null +++ b/gen/reseller1_sandbox-cli/src/main.rs @@ -0,0 +1,1290 @@ +// DO NOT EDIT ! +// This file was generated automatically from 'src/mako/cli/main.rs.mako' +// DO NOT EDIT ! +#![feature(plugin, exit_status)] +#![plugin(docopt_macros)] +#![allow(unused_variables, unused_imports, dead_code, unused_mut)] + +extern crate docopt; +extern crate yup_oauth2 as oauth2; +extern crate yup_hyper_mock as mock; +extern crate rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_reseller1_sandbox as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + reseller1-sandbox [options] customers get <customer-id> [-p <v>]... [-o <out>] + reseller1-sandbox [options] customers insert -r <kv>... [-p <v>]... [-o <out>] + reseller1-sandbox [options] customers patch <customer-id> -r <kv>... [-p <v>]... [-o <out>] + reseller1-sandbox [options] customers update <customer-id> -r <kv>... [-p <v>]... [-o <out>] + reseller1-sandbox [options] subscriptions activate <customer-id> <subscription-id> [-p <v>]... [-o <out>] + reseller1-sandbox [options] subscriptions change-plan <customer-id> <subscription-id> -r <kv>... [-p <v>]... [-o <out>] + reseller1-sandbox [options] subscriptions change-renewal-settings <customer-id> <subscription-id> -r <kv>... [-p <v>]... [-o <out>] + reseller1-sandbox [options] subscriptions change-seats <customer-id> <subscription-id> -r <kv>... [-p <v>]... [-o <out>] + reseller1-sandbox [options] subscriptions delete <customer-id> <subscription-id> <deletion-type> [-p <v>]... + reseller1-sandbox [options] subscriptions get <customer-id> <subscription-id> [-p <v>]... [-o <out>] + reseller1-sandbox [options] subscriptions insert <customer-id> -r <kv>... [-p <v>]... [-o <out>] + reseller1-sandbox [options] subscriptions list [-p <v>]... [-o <out>] + reseller1-sandbox [options] subscriptions start-paid-service <customer-id> <subscription-id> [-p <v>]... [-o <out>] + reseller1-sandbox [options] subscriptions suspend <customer-id> <subscription-id> [-p <v>]... [-o <out>] + reseller1-sandbox --help + +All documentation details can be found TODO: <URL to github.io docs here, see #51> + +Configuration: + --scope <url> + 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. + --config-dir <folder> + 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] + --debug + Output all server communication to standard error. `tx` and `rx` are placed into + the same stream. + --debug-auth + Output all communication related to authentication to standard error. `tx` and `rx` are placed into + the same stream. +"); + +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}; + +use std::default::Default; +use std::str::FromStr; + +use oauth2::{Authenticator, DefaultAuthenticatorDelegate}; +use rustc_serialize::json; + +struct Engine { + opt: Options, + hub: api::Reseller<hyper::Client, Authenticator<DefaultAuthenticatorDelegate, JsonTokenStorage, hyper::Client>>, +} + + +impl Engine { + fn _customers_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.customers().get(&self.opt.arg_customer_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _customers_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request = api::Customer::default(); + let mut call = self.hub.customers().insert(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "customer-auth-token" => { + call = call.customer_auth_token(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_postal_address_init(request: &mut api::Customer) { + if request.postal_address.is_none() { + request.postal_address = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "customer-domain" => { + request.customer_domain = Some(value.unwrap_or("").to_string()); + }, + "alternate-email" => { + request.alternate_email = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "resource-ui-url" => { + request.resource_ui_url = Some(value.unwrap_or("").to_string()); + }, + "phone-number" => { + request.phone_number = Some(value.unwrap_or("").to_string()); + }, + "postal-address.kind" => { + request_postal_address_init(&mut request); + request.postal_address.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "postal-address.organization-name" => { + request_postal_address_init(&mut request); + request.postal_address.as_mut().unwrap().organization_name = Some(value.unwrap_or("").to_string()); + }, + "postal-address.country-code" => { + request_postal_address_init(&mut request); + request.postal_address.as_mut().unwrap().country_code = Some(value.unwrap_or("").to_string()); + }, + "postal-address.locality" => { + request_postal_address_init(&mut request); + request.postal_address.as_mut().unwrap().locality = Some(value.unwrap_or("").to_string()); + }, + "postal-address.region" => { + request_postal_address_init(&mut request); + request.postal_address.as_mut().unwrap().region = Some(value.unwrap_or("").to_string()); + }, + "postal-address.address-line2" => { + request_postal_address_init(&mut request); + request.postal_address.as_mut().unwrap().address_line2 = Some(value.unwrap_or("").to_string()); + }, + "postal-address.address-line3" => { + request_postal_address_init(&mut request); + request.postal_address.as_mut().unwrap().address_line3 = Some(value.unwrap_or("").to_string()); + }, + "postal-address.contact-name" => { + request_postal_address_init(&mut request); + request.postal_address.as_mut().unwrap().contact_name = Some(value.unwrap_or("").to_string()); + }, + "postal-address.address-line1" => { + request_postal_address_init(&mut request); + request.postal_address.as_mut().unwrap().address_line1 = Some(value.unwrap_or("").to_string()); + }, + "postal-address.postal-code" => { + request_postal_address_init(&mut request); + request.postal_address.as_mut().unwrap().postal_code = Some(value.unwrap_or("").to_string()); + }, + "customer-id" => { + request_postal_address_init(&mut request); + request.customer_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _customers_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request = api::Customer::default(); + let mut call = self.hub.customers().patch(&request, &self.opt.arg_customer_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_postal_address_init(request: &mut api::Customer) { + if request.postal_address.is_none() { + request.postal_address = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "customer-domain" => { + request.customer_domain = Some(value.unwrap_or("").to_string()); + }, + "alternate-email" => { + request.alternate_email = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "resource-ui-url" => { + request.resource_ui_url = Some(value.unwrap_or("").to_string()); + }, + "phone-number" => { + request.phone_number = Some(value.unwrap_or("").to_string()); + }, + "postal-address.kind" => { + request_postal_address_init(&mut request); + request.postal_address.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "postal-address.organization-name" => { + request_postal_address_init(&mut request); + request.postal_address.as_mut().unwrap().organization_name = Some(value.unwrap_or("").to_string()); + }, + "postal-address.country-code" => { + request_postal_address_init(&mut request); + request.postal_address.as_mut().unwrap().country_code = Some(value.unwrap_or("").to_string()); + }, + "postal-address.locality" => { + request_postal_address_init(&mut request); + request.postal_address.as_mut().unwrap().locality = Some(value.unwrap_or("").to_string()); + }, + "postal-address.region" => { + request_postal_address_init(&mut request); + request.postal_address.as_mut().unwrap().region = Some(value.unwrap_or("").to_string()); + }, + "postal-address.address-line2" => { + request_postal_address_init(&mut request); + request.postal_address.as_mut().unwrap().address_line2 = Some(value.unwrap_or("").to_string()); + }, + "postal-address.address-line3" => { + request_postal_address_init(&mut request); + request.postal_address.as_mut().unwrap().address_line3 = Some(value.unwrap_or("").to_string()); + }, + "postal-address.contact-name" => { + request_postal_address_init(&mut request); + request.postal_address.as_mut().unwrap().contact_name = Some(value.unwrap_or("").to_string()); + }, + "postal-address.address-line1" => { + request_postal_address_init(&mut request); + request.postal_address.as_mut().unwrap().address_line1 = Some(value.unwrap_or("").to_string()); + }, + "postal-address.postal-code" => { + request_postal_address_init(&mut request); + request.postal_address.as_mut().unwrap().postal_code = Some(value.unwrap_or("").to_string()); + }, + "customer-id" => { + request_postal_address_init(&mut request); + request.customer_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _customers_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request = api::Customer::default(); + let mut call = self.hub.customers().update(&request, &self.opt.arg_customer_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_postal_address_init(request: &mut api::Customer) { + if request.postal_address.is_none() { + request.postal_address = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "customer-domain" => { + request.customer_domain = Some(value.unwrap_or("").to_string()); + }, + "alternate-email" => { + request.alternate_email = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "resource-ui-url" => { + request.resource_ui_url = Some(value.unwrap_or("").to_string()); + }, + "phone-number" => { + request.phone_number = Some(value.unwrap_or("").to_string()); + }, + "postal-address.kind" => { + request_postal_address_init(&mut request); + request.postal_address.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "postal-address.organization-name" => { + request_postal_address_init(&mut request); + request.postal_address.as_mut().unwrap().organization_name = Some(value.unwrap_or("").to_string()); + }, + "postal-address.country-code" => { + request_postal_address_init(&mut request); + request.postal_address.as_mut().unwrap().country_code = Some(value.unwrap_or("").to_string()); + }, + "postal-address.locality" => { + request_postal_address_init(&mut request); + request.postal_address.as_mut().unwrap().locality = Some(value.unwrap_or("").to_string()); + }, + "postal-address.region" => { + request_postal_address_init(&mut request); + request.postal_address.as_mut().unwrap().region = Some(value.unwrap_or("").to_string()); + }, + "postal-address.address-line2" => { + request_postal_address_init(&mut request); + request.postal_address.as_mut().unwrap().address_line2 = Some(value.unwrap_or("").to_string()); + }, + "postal-address.address-line3" => { + request_postal_address_init(&mut request); + request.postal_address.as_mut().unwrap().address_line3 = Some(value.unwrap_or("").to_string()); + }, + "postal-address.contact-name" => { + request_postal_address_init(&mut request); + request.postal_address.as_mut().unwrap().contact_name = Some(value.unwrap_or("").to_string()); + }, + "postal-address.address-line1" => { + request_postal_address_init(&mut request); + request.postal_address.as_mut().unwrap().address_line1 = Some(value.unwrap_or("").to_string()); + }, + "postal-address.postal-code" => { + request_postal_address_init(&mut request); + request.postal_address.as_mut().unwrap().postal_code = Some(value.unwrap_or("").to_string()); + }, + "customer-id" => { + request_postal_address_init(&mut request); + request.customer_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _subscriptions_activate(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.subscriptions().activate(&self.opt.arg_customer_id, &self.opt.arg_subscription_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _subscriptions_change_plan(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request = api::ChangePlanRequest::default(); + let mut call = self.hub.subscriptions().change_plan(&request, &self.opt.arg_customer_id, &self.opt.arg_subscription_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_seats_init(request: &mut api::ChangePlanRequest) { + if request.seats.is_none() { + request.seats = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "plan-name" => { + request.plan_name = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "seats.kind" => { + request_seats_init(&mut request); + request.seats.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "seats.number-of-seats" => { + request_seats_init(&mut request); + request.seats.as_mut().unwrap().number_of_seats = Some(arg_from_str(value.unwrap_or("-0"), err, "seats.number-of-seats", "integer")); + }, + "seats.maximum-number-of-seats" => { + request_seats_init(&mut request); + request.seats.as_mut().unwrap().maximum_number_of_seats = Some(arg_from_str(value.unwrap_or("-0"), err, "seats.maximum-number-of-seats", "integer")); + }, + "seats.licensed-number-of-seats" => { + request_seats_init(&mut request); + request.seats.as_mut().unwrap().licensed_number_of_seats = Some(arg_from_str(value.unwrap_or("-0"), err, "seats.licensed-number-of-seats", "integer")); + }, + "purchase-order-id" => { + request_seats_init(&mut request); + request.purchase_order_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _subscriptions_change_renewal_settings(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request = api::RenewalSettings::default(); + let mut call = self.hub.subscriptions().change_renewal_settings(&request, &self.opt.arg_customer_id, &self.opt.arg_subscription_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "renewal-type" => { + request.renewal_type = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _subscriptions_change_seats(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request = api::Seats::default(); + let mut call = self.hub.subscriptions().change_seats(&request, &self.opt.arg_customer_id, &self.opt.arg_subscription_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "number-of-seats" => { + request.number_of_seats = Some(arg_from_str(value.unwrap_or("-0"), err, "number-of-seats", "integer")); + }, + "maximum-number-of-seats" => { + request.maximum_number_of_seats = Some(arg_from_str(value.unwrap_or("-0"), err, "maximum-number-of-seats", "integer")); + }, + "licensed-number-of-seats" => { + request.licensed_number_of_seats = Some(arg_from_str(value.unwrap_or("-0"), err, "licensed-number-of-seats", "integer")); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _subscriptions_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.subscriptions().delete(&self.opt.arg_customer_id, &self.opt.arg_subscription_id, &self.opt.arg_deletion_type); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + None + } + } + } + } + + fn _subscriptions_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.subscriptions().get(&self.opt.arg_customer_id, &self.opt.arg_subscription_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _subscriptions_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request = api::Subscription::default(); + let mut call = self.hub.subscriptions().insert(&request, &self.opt.arg_customer_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "customer-auth-token" => { + call = call.customer_auth_token(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_plan_commitment_interval_init(request: &mut api::Subscription) { + request_plan_init(request); + if request.plan.as_mut().unwrap().commitment_interval.is_none() { + request.plan.as_mut().unwrap().commitment_interval = Some(Default::default()); + } + } + + fn request_plan_init(request: &mut api::Subscription) { + if request.plan.is_none() { + request.plan = Some(Default::default()); + } + } + + fn request_renewal_settings_init(request: &mut api::Subscription) { + if request.renewal_settings.is_none() { + request.renewal_settings = Some(Default::default()); + } + } + + fn request_seats_init(request: &mut api::Subscription) { + if request.seats.is_none() { + request.seats = Some(Default::default()); + } + } + + fn request_transfer_info_init(request: &mut api::Subscription) { + if request.transfer_info.is_none() { + request.transfer_info = Some(Default::default()); + } + } + + fn request_trial_settings_init(request: &mut api::Subscription) { + if request.trial_settings.is_none() { + request.trial_settings = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "renewal-settings.kind" => { + request_renewal_settings_init(&mut request); + request.renewal_settings.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "renewal-settings.renewal-type" => { + request_renewal_settings_init(&mut request); + request.renewal_settings.as_mut().unwrap().renewal_type = Some(value.unwrap_or("").to_string()); + }, + "sku-id" => { + request_renewal_settings_init(&mut request); + request.sku_id = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request_renewal_settings_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "trial-settings.trial-end-time" => { + request_trial_settings_init(&mut request); + request.trial_settings.as_mut().unwrap().trial_end_time = Some(value.unwrap_or("").to_string()); + }, + "trial-settings.is-in-trial" => { + request_trial_settings_init(&mut request); + request.trial_settings.as_mut().unwrap().is_in_trial = Some(arg_from_str(value.unwrap_or("false"), err, "trial-settings.is-in-trial", "boolean")); + }, + "transfer-info.transferability-expiration-time" => { + request_transfer_info_init(&mut request); + request.transfer_info.as_mut().unwrap().transferability_expiration_time = Some(value.unwrap_or("").to_string()); + }, + "transfer-info.minimum-transferable-seats" => { + request_transfer_info_init(&mut request); + request.transfer_info.as_mut().unwrap().minimum_transferable_seats = Some(arg_from_str(value.unwrap_or("-0"), err, "transfer-info.minimum-transferable-seats", "integer")); + }, + "resource-ui-url" => { + request_transfer_info_init(&mut request); + request.resource_ui_url = Some(value.unwrap_or("").to_string()); + }, + "seats.kind" => { + request_seats_init(&mut request); + request.seats.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "seats.number-of-seats" => { + request_seats_init(&mut request); + request.seats.as_mut().unwrap().number_of_seats = Some(arg_from_str(value.unwrap_or("-0"), err, "seats.number-of-seats", "integer")); + }, + "seats.maximum-number-of-seats" => { + request_seats_init(&mut request); + request.seats.as_mut().unwrap().maximum_number_of_seats = Some(arg_from_str(value.unwrap_or("-0"), err, "seats.maximum-number-of-seats", "integer")); + }, + "seats.licensed-number-of-seats" => { + request_seats_init(&mut request); + request.seats.as_mut().unwrap().licensed_number_of_seats = Some(arg_from_str(value.unwrap_or("-0"), err, "seats.licensed-number-of-seats", "integer")); + }, + "creation-time" => { + request_seats_init(&mut request); + request.creation_time = Some(value.unwrap_or("").to_string()); + }, + "status" => { + request_seats_init(&mut request); + request.status = Some(value.unwrap_or("").to_string()); + }, + "plan.plan-name" => { + request_plan_init(&mut request); + request.plan.as_mut().unwrap().plan_name = Some(value.unwrap_or("").to_string()); + }, + "plan.commitment-interval.end-time" => { + request_plan_commitment_interval_init(&mut request); + request.plan.as_mut().unwrap().commitment_interval.as_mut().unwrap().end_time = Some(value.unwrap_or("").to_string()); + }, + "plan.commitment-interval.start-time" => { + request_plan_commitment_interval_init(&mut request); + request.plan.as_mut().unwrap().commitment_interval.as_mut().unwrap().start_time = Some(value.unwrap_or("").to_string()); + }, + "plan.is-commitment-plan" => { + request_plan_commitment_interval_init(&mut request); + request.plan.as_mut().unwrap().is_commitment_plan = Some(arg_from_str(value.unwrap_or("false"), err, "plan.is-commitment-plan", "boolean")); + }, + "purchase-order-id" => { + request_plan_init(&mut request); + request.purchase_order_id = Some(value.unwrap_or("").to_string()); + }, + "subscription-id" => { + request_plan_init(&mut request); + request.subscription_id = Some(value.unwrap_or("").to_string()); + }, + "billing-method" => { + request_plan_init(&mut request); + request.billing_method = Some(value.unwrap_or("").to_string()); + }, + "customer-id" => { + request_plan_init(&mut request); + request.customer_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _subscriptions_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.subscriptions().list(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "customer-name-prefix" => { + call = call.customer_name_prefix(value.unwrap_or("")); + }, + "customer-id" => { + call = call.customer_id(value.unwrap_or("")); + }, + "customer-auth-token" => { + call = call.customer_auth_token(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _subscriptions_start_paid_service(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.subscriptions().start_paid_service(&self.opt.arg_customer_id, &self.opt.arg_subscription_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _subscriptions_suspend(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.subscriptions().suspend(&self.opt.arg_customer_id, &self.opt.arg_subscription_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option<api::Error>, Option<InvalidOptionsError>) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option<api::Error>; + let mut err_opt: Option<InvalidOptionsError> = None; + + if self.opt.cmd_customers { + if self.opt.cmd_get { + call_result = self._customers_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._customers_insert(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._customers_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._customers_update(dry_run, &mut err); + } else { + unreachable!(); + } + } + else if self.opt.cmd_subscriptions { + if self.opt.cmd_activate { + call_result = self._subscriptions_activate(dry_run, &mut err); + } else if self.opt.cmd_change_plan { + call_result = self._subscriptions_change_plan(dry_run, &mut err); + } else if self.opt.cmd_change_renewal_settings { + call_result = self._subscriptions_change_renewal_settings(dry_run, &mut err); + } else if self.opt.cmd_change_seats { + call_result = self._subscriptions_change_seats(dry_run, &mut err); + } else if self.opt.cmd_delete { + call_result = self._subscriptions_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._subscriptions_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._subscriptions_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._subscriptions_list(dry_run, &mut err); + } else if self.opt.cmd_start_paid_service { + call_result = self._subscriptions_start_paid_service(dry_run, &mut err); + } else if self.opt.cmd_suspend { + call_result = self._subscriptions_suspend(dry_run, &mut err); + } else { + unreachable!(); + } + } else { + unreachable!(); + } + + if dry_run { + if err.issues.len() > 0 { + err_opt = Some(err); + } + } + (call_result, err_opt) + } + + // Please note that this call will fail if any part of the opt can't be handled + fn new(opt: Options) -> Result<Engine, InvalidOptionsError> { + let (config_dir, secret) = { + let config_dir = match cmn::assure_config_dir_exists(&opt.flag_config_dir) { + Err(e) => return Err(InvalidOptionsError::single(e, 3)), + Ok(p) => p, + }; + + match cmn::application_secret_from_directory(&config_dir, "reseller1-sandbox-secret.json", + "{\"installed\":{\"auth_uri\":\"https://accounts.google.com/o/oauth2/auth\",\"client_secret\":\"hCsslbCUyfehWMmbkG8vTYxG\",\"token_uri\":\"https://accounts.google.com/o/oauth2/token\",\"client_email\":\"\",\"redirect_uris\":[\"urn:ietf:wg:oauth:2.0:oob\",\"oob\"],\"client_x509_cert_url\":\"\",\"client_id\":\"620010449518-9ngf7o4dhs0dka470npqvor6dc5lqb9b.apps.googleusercontent.com\",\"auth_provider_x509_cert_url\":\"https://www.googleapis.com/oauth2/v1/certs\"}}") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new( &secret, DefaultAuthenticatorDelegate, + if opt.flag_debug_auth { + hyper::Client::with_connector(mock::TeeConnector { + connector: hyper::net::HttpConnector(None) + }) + } else { + hyper::Client::new() + }, + JsonTokenStorage { + program_name: "reseller1-sandbox", + db_dir: config_dir.clone(), + }, None); + + let client = + if opt.flag_debug { + hyper::Client::with_connector(mock::TeeConnector { + connector: hyper::net::HttpConnector(None) + }) + } else { + hyper::Client::new() + }; + let engine = Engine { + opt: opt, + hub: api::Reseller::new(client, auth), + }; + + match engine._doit(true) { + (_, Some(err)) => Err(err), + _ => Ok(engine), + } + } + + // Execute the call with all the bells and whistles, informing the caller only if there was an error. + // The absense of one indicates success. + fn doit(&self) -> Option<api::Error> { + self._doit(false).0 + } +} + +fn main() { + let opts: Options = Options::docopt().decode().unwrap_or_else(|e| e.exit()); + match Engine::new(opts) { + Err(err) => { + writeln!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + writeln!(io::stderr(), "{:?}", err).ok(); + writeln!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/tagmanager1-cli/Cargo.toml b/gen/tagmanager1-cli/Cargo.toml new file mode 100644 index 0000000000..fec8c34906 --- /dev/null +++ b/gen/tagmanager1-cli/Cargo.toml @@ -0,0 +1,31 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-tagmanager1-cli" +version = "0.0.1+20150121" +authors = ["Sebastian Thiel <byronimo@gmail.com>"] +description = "A complete library to interact with Tag Manager (protocol v1)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/tagmanager1-cli" +homepage = "https://developers.google.com/tag-manager/api/v1/" +documentation = "http://byron.github.io/google-apis-rs/google_tagmanager1_cli" +license = "MIT" +keywords = ["tagmanager", "google", "cli"] + +[[bin]] +name = "tagmanager1" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "*" +docopt_macros = "*" +rustc-serialize = "*" +yup-hyper-mock = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-tagmanager1] +path = "../tagmanager1" diff --git a/gen/tagmanager1-cli/LICENSE.md b/gen/tagmanager1-cli/LICENSE.md new file mode 100644 index 0000000000..ae22e6ec52 --- /dev/null +++ b/gen/tagmanager1-cli/LICENSE.md @@ -0,0 +1,30 @@ +<!--- +DO NOT EDIT ! +This file was generated automatically from 'src/mako/LICENSE.md.mako' +DO NOT EDIT ! +--> +The MIT License (MIT) +===================== + +Copyright © `2015` `Sebastian Thiel` + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the “Software”), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. diff --git a/gen/tagmanager1-cli/README.md b/gen/tagmanager1-cli/README.md new file mode 100644 index 0000000000..1fcc018979 --- /dev/null +++ b/gen/tagmanager1-cli/README.md @@ -0,0 +1,4 @@ +# HELLO TAGMANAGER:V1 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/tagmanager1-cli/mkdocs.yml b/gen/tagmanager1-cli/mkdocs.yml new file mode 100644 index 0000000000..5344c3a6d5 --- /dev/null +++ b/gen/tagmanager1-cli/mkdocs.yml @@ -0,0 +1,62 @@ +site_name: Tag Manager v0.0.1+20150121 +site_url: http://byron.github.io/google-apis-rs/google-tagmanager1-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/tagmanager1-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['accounts_containers-create.md', 'Accounts', 'Containers Create'] +- ['accounts_containers-delete.md', 'Accounts', 'Containers Delete'] +- ['accounts_containers-get.md', 'Accounts', 'Containers Get'] +- ['accounts_containers-list.md', 'Accounts', 'Containers List'] +- ['accounts_containers-macros-create.md', 'Accounts', 'Containers Macros Create'] +- ['accounts_containers-macros-delete.md', 'Accounts', 'Containers Macros Delete'] +- ['accounts_containers-macros-get.md', 'Accounts', 'Containers Macros Get'] +- ['accounts_containers-macros-list.md', 'Accounts', 'Containers Macros List'] +- ['accounts_containers-macros-update.md', 'Accounts', 'Containers Macros Update'] +- ['accounts_containers-rules-create.md', 'Accounts', 'Containers Rules Create'] +- ['accounts_containers-rules-delete.md', 'Accounts', 'Containers Rules Delete'] +- ['accounts_containers-rules-get.md', 'Accounts', 'Containers Rules Get'] +- ['accounts_containers-rules-list.md', 'Accounts', 'Containers Rules List'] +- ['accounts_containers-rules-update.md', 'Accounts', 'Containers Rules Update'] +- ['accounts_containers-tags-create.md', 'Accounts', 'Containers Tags Create'] +- ['accounts_containers-tags-delete.md', 'Accounts', 'Containers Tags Delete'] +- ['accounts_containers-tags-get.md', 'Accounts', 'Containers Tags Get'] +- ['accounts_containers-tags-list.md', 'Accounts', 'Containers Tags List'] +- ['accounts_containers-tags-update.md', 'Accounts', 'Containers Tags Update'] +- ['accounts_containers-triggers-create.md', 'Accounts', 'Containers Triggers Create'] +- ['accounts_containers-triggers-delete.md', 'Accounts', 'Containers Triggers Delete'] +- ['accounts_containers-triggers-get.md', 'Accounts', 'Containers Triggers Get'] +- ['accounts_containers-triggers-list.md', 'Accounts', 'Containers Triggers List'] +- ['accounts_containers-triggers-update.md', 'Accounts', 'Containers Triggers Update'] +- ['accounts_containers-update.md', 'Accounts', 'Containers Update'] +- ['accounts_containers-variables-create.md', 'Accounts', 'Containers Variables Create'] +- ['accounts_containers-variables-delete.md', 'Accounts', 'Containers Variables Delete'] +- ['accounts_containers-variables-get.md', 'Accounts', 'Containers Variables Get'] +- ['accounts_containers-variables-list.md', 'Accounts', 'Containers Variables List'] +- ['accounts_containers-variables-update.md', 'Accounts', 'Containers Variables Update'] +- ['accounts_containers-versions-create.md', 'Accounts', 'Containers Versions Create'] +- ['accounts_containers-versions-delete.md', 'Accounts', 'Containers Versions Delete'] +- ['accounts_containers-versions-get.md', 'Accounts', 'Containers Versions Get'] +- ['accounts_containers-versions-list.md', 'Accounts', 'Containers Versions List'] +- ['accounts_containers-versions-publish.md', 'Accounts', 'Containers Versions Publish'] +- ['accounts_containers-versions-restore.md', 'Accounts', 'Containers Versions Restore'] +- ['accounts_containers-versions-undelete.md', 'Accounts', 'Containers Versions Undelete'] +- ['accounts_containers-versions-update.md', 'Accounts', 'Containers Versions Update'] +- ['accounts_get.md', 'Accounts', 'Get'] +- ['accounts_list.md', 'Accounts', 'List'] +- ['accounts_permissions-create.md', 'Accounts', 'Permissions Create'] +- ['accounts_permissions-delete.md', 'Accounts', 'Permissions Delete'] +- ['accounts_permissions-get.md', 'Accounts', 'Permissions Get'] +- ['accounts_permissions-list.md', 'Accounts', 'Permissions List'] +- ['accounts_permissions-update.md', 'Accounts', 'Permissions Update'] +- ['accounts_update.md', 'Accounts', 'Update'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/tagmanager1-cli/src/cmn.rs b/gen/tagmanager1-cli/src/cmn.rs new file mode 100644 index 0000000000..a8d3f46368 --- /dev/null +++ b/gen/tagmanager1-cli/src/cmn.rs @@ -0,0 +1,454 @@ +// COPY OF 'src/rust/cli/cmn.rs' +// DO NOT EDIT +use oauth2::{ApplicationSecret, ConsoleApplicationSecret, TokenStorage, Token}; +use rustc_serialize::json; +use mime::Mime; + +use std::fs; +use std::env; +use std::io; +use std::fmt; +use std::path::{Path, PathBuf}; +use std::str::FromStr; +use std::string::ToString; +use std::io::{Write, Read, stdout}; + +use std::default::Default; + +const FIELD_SEP: char = '.'; + +#[derive(Clone, Default)] +pub struct FieldCursor(Vec<String>); + +impl ToString for FieldCursor { + fn to_string(&self) -> String { + self.0.connect(".") + } +} + +impl FieldCursor { + pub fn set(&mut self, value: &str) -> Result<(), CLIError> { + if value.len() == 0 { + return Err(CLIError::Field(FieldError::Empty)) + } + + let mut first_is_field_sep = false; + let mut char_count: usize = 0; + let mut last_c = FIELD_SEP; + let mut num_conscutive_field_seps = 0; + + let mut field = String::new(); + let mut fields = self.0.clone(); + + let push_field = |fs: &mut Vec<String>, f: &mut String| { + if f.len() > 0 { + fs.push(f.clone()); + f.truncate(0); + } + }; + + for (cid, c) in value.chars().enumerate() { + char_count += 1; + + if c == FIELD_SEP { + if cid == 0 { + first_is_field_sep = true; + } + num_conscutive_field_seps += 1; + if cid > 0 && last_c == FIELD_SEP { + if fields.pop().is_none() { + return Err(CLIError::Field(FieldError::PopOnEmpty(value.to_string()))) + } + } else { + push_field(&mut fields, &mut field); + } + } else { + num_conscutive_field_seps = 0; + if cid == 1 { + if first_is_field_sep { + fields.truncate(0); + } + } + field.push(c); + } + + last_c = c; + } + + push_field(&mut fields, &mut field); + + if char_count == 1 && first_is_field_sep { + fields.truncate(0); + } + if char_count > 1 && num_conscutive_field_seps == 1 { + return Err(CLIError::Field(FieldError::TrailingFieldSep(value.to_string()))) + } + + self.0 = fields; + Ok(()) + } + + pub fn num_fields(&self) -> usize { + self.0.len() + } +} + +pub fn parse_kv_arg<'a>(kv: &'a str, err: &mut InvalidOptionsError, for_hashmap: bool) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string(),for_hashmap)); + match kv.find('=') { + None => { + add_err(); + return (kv, None) + }, + Some(pos) => { + let key = &kv[..pos]; + if kv.len() <= pos + 1 { + add_err(); + return (key, None) + } + (key, Some(&kv[pos+1..])) + } + } +} + +pub fn input_file_from_opts(file_path: &str, err: &mut InvalidOptionsError) -> Option<fs::File> { + match fs::File::open(file_path) { + Ok(f) => Some(f), + Err(io_err) => { + err.issues.push(CLIError::Input(InputError::IOError((file_path.to_string(), io_err)))); + None + } + } +} + +pub fn input_mime_from_opts(mime: &str, err: &mut InvalidOptionsError) -> Option<Mime> { + match mime.parse() { + Ok(m) => Some(m), + Err(_) => { + err.issues.push(CLIError::Input(InputError::Mime(mime.to_string()))); + None + } + } +} + +// May panic if we can't open the file - this is anticipated, we can't currently communicate this +// kind of error: TODO: fix this architecture :) +pub fn writer_from_opts(flag: bool, arg: &str) -> Box<Write> { + if !flag || arg == "-" { + Box::new(stdout()) + } else { + Box::new(fs::OpenOptions::new().create(true).write(true).open(arg).unwrap()) + } +} + + +pub fn arg_from_str<T>(arg: &str, err: &mut InvalidOptionsError, + arg_name: &'static str, + arg_type: &'static 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))) + ); + Default::default() + }, + Ok(v) => v, + } +} + +pub struct JsonTokenStorage { + pub program_name: &'static str, + pub db_dir: String, +} + +impl JsonTokenStorage { + fn path(&self, scope_hash: u64) -> PathBuf { + Path::new(&self.db_dir).join(&format!("{}-token-{}.json", self.program_name, scope_hash)) + } +} + +impl TokenStorage for JsonTokenStorage { + type Error = io::Error; + + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, _: &Vec<&str>, token: Option<Token>) -> Option<io::Error> { + match token { + None => { + match fs::remove_file(self.path(scope_hash)) { + Err(err) => + match err.kind() { + io::ErrorKind::NotFound => None, + _ => Some(err) + }, + Ok(_) => None + } + } + Some(token) => { + let json_token = json::encode(&token).unwrap(); + match fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)) { + Ok(mut f) => { + match f.write(json_token.as_bytes()) { + Ok(_) => None, + Err(io_err) => Some(io_err), + } + }, + Err(io_err) => Some(io_err) + } + } + } + } + + fn get(&self, scope_hash: u64, _: &Vec<&str>) -> Result<Option<Token>, io::Error> { + match fs::File::open(&self.path(scope_hash)) { + Ok(mut f) => { + let mut json_string = String::new(); + match f.read_to_string(&mut json_string) { + Ok(_) => Ok(Some(json::decode::<Token>(&json_string).unwrap())), + Err(io_err) => Err(io_err), + } + }, + Err(io_err) => { + match io_err.kind() { + io::ErrorKind::NotFound => Ok(None), + _ => Err(io_err) + } + } + } + } +} + + +#[derive(Debug)] +pub enum ApplicationSecretError { + DecoderError((String, json::DecoderError)), + FormatError(String), +} + +impl fmt::Display for ApplicationSecretError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + match *self { + ApplicationSecretError::DecoderError((ref path, ref err)) + => writeln!(f, "Could not decode file at '{}' with error: {}", + path, err), + ApplicationSecretError::FormatError(ref path) + => writeln!(f, "'installed' field is unset in secret file at '{}'", + path), + } + } +} + +#[derive(Debug)] +pub enum ConfigurationError { + DirectoryCreationFailed((String, io::Error)), + DirectoryUnset, + HomeExpansionFailed(String), + Secret(ApplicationSecretError), + IOError((String, io::Error)), +} + +impl fmt::Display for ConfigurationError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + match *self { + ConfigurationError::DirectoryCreationFailed((ref dir, ref err)) + => writeln!(f, "Directory '{}' could not be created with error: {}", dir, err), + ConfigurationError::DirectoryUnset + => writeln!(f, "--config-dir was unset or empty"), + ConfigurationError::HomeExpansionFailed(ref dir) + => writeln!(f, "Couldn't find HOME directory of current user, failed to expand '{}'", dir), + ConfigurationError::Secret(ref err) + => writeln!(f, "Secret -> {}", err), + ConfigurationError::IOError((ref path, ref err)) + => writeln!(f, "IO operation failed on path '{}' with error: {}", path, err), + } + } +} + +#[derive(Debug)] +pub enum InputError { + IOError((String, io::Error)), + Mime(String), +} + +impl fmt::Display for InputError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + match *self { + InputError::IOError((ref file_path, ref io_err)) + => writeln!(f, "Failed to open '{}' for reading with error: {}", file_path, io_err), + InputError::Mime(ref mime) + => writeln!(f, "'{}' is not a known mime-type", mime), + } + } +} + +#[derive(Debug)] +pub enum FieldError { + PopOnEmpty(String), + TrailingFieldSep(String), + Unknown(String), + Empty, +} + + +impl fmt::Display for FieldError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + match *self { + FieldError::PopOnEmpty(ref field) + => writeln!(f, "'{}': Cannot move up on empty field cursor", field), + FieldError::TrailingFieldSep(ref field) + => writeln!(f, "'{}': Single field separator may not be last character", field), + FieldError::Unknown(ref field) + => writeln!(f, "Field '{}' does not exist", field), + FieldError::Empty + => writeln!(f, "Field names must not be empty"), + } + } +} + + +#[derive(Debug)] +pub enum CLIError { + Configuration(ConfigurationError), + ParseError((&'static str, &'static str, String, String)), + UnknownParameter(String), + InvalidKeyValueSyntax(String, bool), + Input(InputError), + Field(FieldError), +} + +impl fmt::Display for CLIError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + match *self { + CLIError::Configuration(ref err) => write!(f, "Configuration -> {}", err), + CLIError::Input(ref err) => write!(f, "Input -> {}", err), + CLIError::Field(ref err) => write!(f, "Field -> {}", err), + CLIError::ParseError((arg_name, 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) + => writeln!(f, "Parameter '{}' is unknown.", param_name), + CLIError::InvalidKeyValueSyntax(ref kv, is_hashmap) => { + let hashmap_info = if is_hashmap { "hashmap " } else { "" }; + writeln!(f, "'{}' does not match {}pattern <key>=<value>", kv, hashmap_info) + }, + } + } +} + +#[derive(Debug)] +pub struct InvalidOptionsError { + pub issues: Vec<CLIError>, + pub exit_code: i32, +} + +impl fmt::Display for InvalidOptionsError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + for issue in &self.issues { + try!(issue.fmt(f)); + } + Ok(()) + } +} + +impl InvalidOptionsError { + pub fn single(err: CLIError, exit_code: i32) -> InvalidOptionsError { + InvalidOptionsError { + issues: vec![err], + exit_code: exit_code, + } + } + + pub fn new() -> InvalidOptionsError { + InvalidOptionsError { + issues: Vec::new(), + exit_code: 1, + } + } +} + +pub fn assure_config_dir_exists(dir: &str) -> Result<String, CLIError> { + let trdir = dir.trim(); + if trdir.len() == 0 { + return Err(CLIError::Configuration(ConfigurationError::DirectoryUnset)) + } + + let expanded_config_dir = + if trdir.as_bytes()[0] == b'~' { + match env::var("HOME").ok().or(env::var("UserProfile").ok()) { + None => return Err(CLIError::Configuration(ConfigurationError::HomeExpansionFailed(trdir.to_string()))), + Some(mut user) => { + user.push_str(&trdir[1..]); + user + } + } + } else { + trdir.to_string() + }; + + if let Err(err) = fs::create_dir(&expanded_config_dir) { + if err.kind() != io::ErrorKind::AlreadyExists { + return Err(CLIError::Configuration( + ConfigurationError::DirectoryCreationFailed((expanded_config_dir, err)))) + } + } + + Ok(expanded_config_dir) +} + +pub fn application_secret_from_directory(dir: &str, + secret_basename: &str, + json_app_secret: &str) + -> Result<ApplicationSecret, CLIError> { + let secret_path = Path::new(dir).join(secret_basename); + let secret_str = || secret_path.as_path().to_str().unwrap().to_string(); + let secret_io_error = |io_err: io::Error| { + Err(CLIError::Configuration(ConfigurationError::IOError( + (secret_str(), io_err) + ))) + }; + + for _ in 0..2 { + match fs::File::open(&secret_path) { + Err(mut err) => { + if err.kind() == io::ErrorKind::NotFound { + // Write our built-in one - user may adjust the written file at will + + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_app_secret.as_bytes()) { + Err(io_err) => io_err, + Ok(_) => continue, + } + } + }; + // fall through to IO error handling + } + return secret_io_error(err) + }, + Ok(mut f) => { + let mut json_encoded_secret = String::new(); + if let Err(io_err) = f.read_to_string(&mut json_encoded_secret) { + return secret_io_error(io_err) + } + match json::decode::<ConsoleApplicationSecret>(&json_encoded_secret) { + Err(json_decode_error) => return Err(CLIError::Configuration( + ConfigurationError::Secret(ApplicationSecretError::DecoderError( + (secret_str(), json_decode_error) + )))), + Ok(console_secret) => match console_secret.installed { + Some(secret) => return Ok(secret), + None => return Err( + CLIError::Configuration( + ConfigurationError::Secret( + ApplicationSecretError::FormatError(secret_str()) + ))) + }, + } + } + } + } + unreachable!(); +} \ No newline at end of file diff --git a/gen/tagmanager1-cli/src/main.rs b/gen/tagmanager1-cli/src/main.rs new file mode 100644 index 0000000000..f9f4422d65 --- /dev/null +++ b/gen/tagmanager1-cli/src/main.rs @@ -0,0 +1,3484 @@ +// DO NOT EDIT ! +// This file was generated automatically from 'src/mako/cli/main.rs.mako' +// DO NOT EDIT ! +#![feature(plugin, exit_status)] +#![plugin(docopt_macros)] +#![allow(unused_variables, unused_imports, dead_code, unused_mut)] + +extern crate docopt; +extern crate yup_oauth2 as oauth2; +extern crate yup_hyper_mock as mock; +extern crate rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_tagmanager1 as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + tagmanager1 [options] accounts containers-create <account-id> -r <kv>... [-p <v>]... [-o <out>] + tagmanager1 [options] accounts containers-delete <account-id> <container-id> [-p <v>]... + tagmanager1 [options] accounts containers-get <account-id> <container-id> [-p <v>]... [-o <out>] + tagmanager1 [options] accounts containers-list <account-id> [-p <v>]... [-o <out>] + tagmanager1 [options] accounts containers-macros-create <account-id> <container-id> -r <kv>... [-p <v>]... [-o <out>] + tagmanager1 [options] accounts containers-macros-delete <account-id> <container-id> <macro-id> [-p <v>]... + tagmanager1 [options] accounts containers-macros-get <account-id> <container-id> <macro-id> [-p <v>]... [-o <out>] + tagmanager1 [options] accounts containers-macros-list <account-id> <container-id> [-p <v>]... [-o <out>] + tagmanager1 [options] accounts containers-macros-update <account-id> <container-id> <macro-id> -r <kv>... [-p <v>]... [-o <out>] + tagmanager1 [options] accounts containers-rules-create <account-id> <container-id> -r <kv>... [-p <v>]... [-o <out>] + tagmanager1 [options] accounts containers-rules-delete <account-id> <container-id> <rule-id> [-p <v>]... + tagmanager1 [options] accounts containers-rules-get <account-id> <container-id> <rule-id> [-p <v>]... [-o <out>] + tagmanager1 [options] accounts containers-rules-list <account-id> <container-id> [-p <v>]... [-o <out>] + tagmanager1 [options] accounts containers-rules-update <account-id> <container-id> <rule-id> -r <kv>... [-p <v>]... [-o <out>] + tagmanager1 [options] accounts containers-tags-create <account-id> <container-id> -r <kv>... [-p <v>]... [-o <out>] + tagmanager1 [options] accounts containers-tags-delete <account-id> <container-id> <tag-id> [-p <v>]... + tagmanager1 [options] accounts containers-tags-get <account-id> <container-id> <tag-id> [-p <v>]... [-o <out>] + tagmanager1 [options] accounts containers-tags-list <account-id> <container-id> [-p <v>]... [-o <out>] + tagmanager1 [options] accounts containers-tags-update <account-id> <container-id> <tag-id> -r <kv>... [-p <v>]... [-o <out>] + tagmanager1 [options] accounts containers-triggers-create <account-id> <container-id> -r <kv>... [-p <v>]... [-o <out>] + tagmanager1 [options] accounts containers-triggers-delete <account-id> <container-id> <trigger-id> [-p <v>]... + tagmanager1 [options] accounts containers-triggers-get <account-id> <container-id> <trigger-id> [-p <v>]... [-o <out>] + tagmanager1 [options] accounts containers-triggers-list <account-id> <container-id> [-p <v>]... [-o <out>] + tagmanager1 [options] accounts containers-triggers-update <account-id> <container-id> <trigger-id> -r <kv>... [-p <v>]... [-o <out>] + tagmanager1 [options] accounts containers-update <account-id> <container-id> -r <kv>... [-p <v>]... [-o <out>] + tagmanager1 [options] accounts containers-variables-create <account-id> <container-id> -r <kv>... [-p <v>]... [-o <out>] + tagmanager1 [options] accounts containers-variables-delete <account-id> <container-id> <variable-id> [-p <v>]... + tagmanager1 [options] accounts containers-variables-get <account-id> <container-id> <variable-id> [-p <v>]... [-o <out>] + tagmanager1 [options] accounts containers-variables-list <account-id> <container-id> [-p <v>]... [-o <out>] + tagmanager1 [options] accounts containers-variables-update <account-id> <container-id> <variable-id> -r <kv>... [-p <v>]... [-o <out>] + tagmanager1 [options] accounts containers-versions-create <account-id> <container-id> -r <kv>... [-p <v>]... [-o <out>] + tagmanager1 [options] accounts containers-versions-delete <account-id> <container-id> <container-version-id> [-p <v>]... + tagmanager1 [options] accounts containers-versions-get <account-id> <container-id> <container-version-id> [-p <v>]... [-o <out>] + tagmanager1 [options] accounts containers-versions-list <account-id> <container-id> [-p <v>]... [-o <out>] + tagmanager1 [options] accounts containers-versions-publish <account-id> <container-id> <container-version-id> [-p <v>]... [-o <out>] + tagmanager1 [options] accounts containers-versions-restore <account-id> <container-id> <container-version-id> [-p <v>]... [-o <out>] + tagmanager1 [options] accounts containers-versions-undelete <account-id> <container-id> <container-version-id> [-p <v>]... [-o <out>] + tagmanager1 [options] accounts containers-versions-update <account-id> <container-id> <container-version-id> -r <kv>... [-p <v>]... [-o <out>] + tagmanager1 [options] accounts get <account-id> [-p <v>]... [-o <out>] + tagmanager1 [options] accounts list [-p <v>]... [-o <out>] + tagmanager1 [options] accounts permissions-create <account-id> -r <kv>... [-p <v>]... [-o <out>] + tagmanager1 [options] accounts permissions-delete <account-id> <permission-id> [-p <v>]... + tagmanager1 [options] accounts permissions-get <account-id> <permission-id> [-p <v>]... [-o <out>] + tagmanager1 [options] accounts permissions-list <account-id> [-p <v>]... [-o <out>] + tagmanager1 [options] accounts permissions-update <account-id> <permission-id> -r <kv>... [-p <v>]... [-o <out>] + tagmanager1 [options] accounts update <account-id> -r <kv>... [-p <v>]... [-o <out>] + tagmanager1 --help + +All documentation details can be found TODO: <URL to github.io docs here, see #51> + +Configuration: + --scope <url> + 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. + --config-dir <folder> + 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] + --debug + Output all server communication to standard error. `tx` and `rx` are placed into + the same stream. + --debug-auth + Output all communication related to authentication to standard error. `tx` and `rx` are placed into + the same stream. +"); + +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}; + +use std::default::Default; +use std::str::FromStr; + +use oauth2::{Authenticator, DefaultAuthenticatorDelegate}; +use rustc_serialize::json; + +struct Engine { + opt: Options, + hub: api::TagManager<hyper::Client, Authenticator<DefaultAuthenticatorDelegate, JsonTokenStorage, hyper::Client>>, +} + + +impl Engine { + fn _accounts_containers_create(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request = api::Container::default(); + let mut call = self.hub.accounts().containers_create(&request, &self.opt.arg_account_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "time-zone-id" => { + request.time_zone_id = Some(value.unwrap_or("").to_string()); + }, + "enabled-built-in-variable" => { + if request.enabled_built_in_variable.is_none() { + request.enabled_built_in_variable = Some(Default::default()); + } + request.enabled_built_in_variable.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "time-zone-country-id" => { + request.time_zone_country_id = Some(arg_from_str(value.unwrap_or("-0"), err, "time-zone-country-id", "int64")); + }, + "public-id" => { + request.public_id = Some(value.unwrap_or("").to_string()); + }, + "container-id" => { + request.container_id = Some(value.unwrap_or("").to_string()); + }, + "domain-name" => { + if request.domain_name.is_none() { + request.domain_name = Some(Default::default()); + } + request.domain_name.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "notes" => { + request.notes = Some(value.unwrap_or("").to_string()); + }, + "usage-context" => { + if request.usage_context.is_none() { + request.usage_context = Some(Default::default()); + } + request.usage_context.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "fingerprint" => { + request.fingerprint = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request.account_id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_containers_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.accounts().containers_delete(&self.opt.arg_account_id, &self.opt.arg_container_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + None + } + } + } + } + + fn _accounts_containers_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.accounts().containers_get(&self.opt.arg_account_id, &self.opt.arg_container_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_containers_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.accounts().containers_list(&self.opt.arg_account_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_containers_macros_create(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request = api::Macro::default(); + let mut call = self.hub.accounts().containers_macros_create(&request, &self.opt.arg_account_id, &self.opt.arg_container_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "schedule-start-ms" => { + request.schedule_start_ms = Some(value.unwrap_or("").to_string()); + }, + "schedule-end-ms" => { + request.schedule_end_ms = Some(value.unwrap_or("").to_string()); + }, + "macro-id" => { + request.macro_id = Some(value.unwrap_or("").to_string()); + }, + "container-id" => { + request.container_id = Some(value.unwrap_or("").to_string()); + }, + "notes" => { + request.notes = Some(value.unwrap_or("").to_string()); + }, + "enabling-rule-id" => { + if request.enabling_rule_id.is_none() { + request.enabling_rule_id = Some(Default::default()); + } + request.enabling_rule_id.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "disabling-rule-id" => { + if request.disabling_rule_id.is_none() { + request.disabling_rule_id = Some(Default::default()); + } + request.disabling_rule_id.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "fingerprint" => { + request.fingerprint = Some(value.unwrap_or("").to_string()); + }, + "type" => { + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request.account_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_containers_macros_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.accounts().containers_macros_delete(&self.opt.arg_account_id, &self.opt.arg_container_id, &self.opt.arg_macro_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + None + } + } + } + } + + fn _accounts_containers_macros_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.accounts().containers_macros_get(&self.opt.arg_account_id, &self.opt.arg_container_id, &self.opt.arg_macro_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_containers_macros_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.accounts().containers_macros_list(&self.opt.arg_account_id, &self.opt.arg_container_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_containers_macros_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request = api::Macro::default(); + let mut call = self.hub.accounts().containers_macros_update(&request, &self.opt.arg_account_id, &self.opt.arg_container_id, &self.opt.arg_macro_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "fingerprint" => { + call = call.fingerprint(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "schedule-start-ms" => { + request.schedule_start_ms = Some(value.unwrap_or("").to_string()); + }, + "schedule-end-ms" => { + request.schedule_end_ms = Some(value.unwrap_or("").to_string()); + }, + "macro-id" => { + request.macro_id = Some(value.unwrap_or("").to_string()); + }, + "container-id" => { + request.container_id = Some(value.unwrap_or("").to_string()); + }, + "notes" => { + request.notes = Some(value.unwrap_or("").to_string()); + }, + "enabling-rule-id" => { + if request.enabling_rule_id.is_none() { + request.enabling_rule_id = Some(Default::default()); + } + request.enabling_rule_id.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "disabling-rule-id" => { + if request.disabling_rule_id.is_none() { + request.disabling_rule_id = Some(Default::default()); + } + request.disabling_rule_id.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "fingerprint" => { + request.fingerprint = Some(value.unwrap_or("").to_string()); + }, + "type" => { + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request.account_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_containers_rules_create(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request = api::Rule::default(); + let mut call = self.hub.accounts().containers_rules_create(&request, &self.opt.arg_account_id, &self.opt.arg_container_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "container-id" => { + request.container_id = Some(value.unwrap_or("").to_string()); + }, + "rule-id" => { + request.rule_id = Some(value.unwrap_or("").to_string()); + }, + "notes" => { + request.notes = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "fingerprint" => { + request.fingerprint = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request.account_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_containers_rules_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.accounts().containers_rules_delete(&self.opt.arg_account_id, &self.opt.arg_container_id, &self.opt.arg_rule_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + None + } + } + } + } + + fn _accounts_containers_rules_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.accounts().containers_rules_get(&self.opt.arg_account_id, &self.opt.arg_container_id, &self.opt.arg_rule_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_containers_rules_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.accounts().containers_rules_list(&self.opt.arg_account_id, &self.opt.arg_container_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_containers_rules_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request = api::Rule::default(); + let mut call = self.hub.accounts().containers_rules_update(&request, &self.opt.arg_account_id, &self.opt.arg_container_id, &self.opt.arg_rule_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "fingerprint" => { + call = call.fingerprint(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "container-id" => { + request.container_id = Some(value.unwrap_or("").to_string()); + }, + "rule-id" => { + request.rule_id = Some(value.unwrap_or("").to_string()); + }, + "notes" => { + request.notes = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "fingerprint" => { + request.fingerprint = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request.account_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_containers_tags_create(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request = api::Tag::default(); + let mut call = self.hub.accounts().containers_tags_create(&request, &self.opt.arg_account_id, &self.opt.arg_container_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_priority_init(request: &mut api::Tag) { + if request.priority.is_none() { + request.priority = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "schedule-start-ms" => { + request.schedule_start_ms = Some(value.unwrap_or("").to_string()); + }, + "schedule-end-ms" => { + request.schedule_end_ms = Some(value.unwrap_or("").to_string()); + }, + "container-id" => { + request.container_id = Some(value.unwrap_or("").to_string()); + }, + "blocking-trigger-id" => { + if request.blocking_trigger_id.is_none() { + request.blocking_trigger_id = Some(Default::default()); + } + request.blocking_trigger_id.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "tag-id" => { + request.tag_id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "priority.type" => { + request_priority_init(&mut request); + request.priority.as_mut().unwrap().type_ = Some(value.unwrap_or("").to_string()); + }, + "priority.value" => { + request_priority_init(&mut request); + request.priority.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "priority.key" => { + request_priority_init(&mut request); + request.priority.as_mut().unwrap().key = Some(value.unwrap_or("").to_string()); + }, + "blocking-rule-id" => { + request_priority_init(&mut request); + if request.blocking_rule_id.is_none() { + request.blocking_rule_id = Some(Default::default()); + } + request.blocking_rule_id.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "live-only" => { + request_priority_init(&mut request); + request.live_only = Some(arg_from_str(value.unwrap_or("false"), err, "live-only", "boolean")); + }, + "fingerprint" => { + request_priority_init(&mut request); + request.fingerprint = Some(value.unwrap_or("").to_string()); + }, + "firing-rule-id" => { + request_priority_init(&mut request); + if request.firing_rule_id.is_none() { + request.firing_rule_id = Some(Default::default()); + } + request.firing_rule_id.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "firing-trigger-id" => { + request_priority_init(&mut request); + if request.firing_trigger_id.is_none() { + request.firing_trigger_id = Some(Default::default()); + } + request.firing_trigger_id.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "type" => { + request_priority_init(&mut request); + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "notes" => { + request_priority_init(&mut request); + request.notes = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request_priority_init(&mut request); + request.account_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_containers_tags_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.accounts().containers_tags_delete(&self.opt.arg_account_id, &self.opt.arg_container_id, &self.opt.arg_tag_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + None + } + } + } + } + + fn _accounts_containers_tags_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.accounts().containers_tags_get(&self.opt.arg_account_id, &self.opt.arg_container_id, &self.opt.arg_tag_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_containers_tags_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.accounts().containers_tags_list(&self.opt.arg_account_id, &self.opt.arg_container_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_containers_tags_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request = api::Tag::default(); + let mut call = self.hub.accounts().containers_tags_update(&request, &self.opt.arg_account_id, &self.opt.arg_container_id, &self.opt.arg_tag_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "fingerprint" => { + call = call.fingerprint(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_priority_init(request: &mut api::Tag) { + if request.priority.is_none() { + request.priority = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "schedule-start-ms" => { + request.schedule_start_ms = Some(value.unwrap_or("").to_string()); + }, + "schedule-end-ms" => { + request.schedule_end_ms = Some(value.unwrap_or("").to_string()); + }, + "container-id" => { + request.container_id = Some(value.unwrap_or("").to_string()); + }, + "blocking-trigger-id" => { + if request.blocking_trigger_id.is_none() { + request.blocking_trigger_id = Some(Default::default()); + } + request.blocking_trigger_id.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "tag-id" => { + request.tag_id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "priority.type" => { + request_priority_init(&mut request); + request.priority.as_mut().unwrap().type_ = Some(value.unwrap_or("").to_string()); + }, + "priority.value" => { + request_priority_init(&mut request); + request.priority.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "priority.key" => { + request_priority_init(&mut request); + request.priority.as_mut().unwrap().key = Some(value.unwrap_or("").to_string()); + }, + "blocking-rule-id" => { + request_priority_init(&mut request); + if request.blocking_rule_id.is_none() { + request.blocking_rule_id = Some(Default::default()); + } + request.blocking_rule_id.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "live-only" => { + request_priority_init(&mut request); + request.live_only = Some(arg_from_str(value.unwrap_or("false"), err, "live-only", "boolean")); + }, + "fingerprint" => { + request_priority_init(&mut request); + request.fingerprint = Some(value.unwrap_or("").to_string()); + }, + "firing-rule-id" => { + request_priority_init(&mut request); + if request.firing_rule_id.is_none() { + request.firing_rule_id = Some(Default::default()); + } + request.firing_rule_id.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "firing-trigger-id" => { + request_priority_init(&mut request); + if request.firing_trigger_id.is_none() { + request.firing_trigger_id = Some(Default::default()); + } + request.firing_trigger_id.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "type" => { + request_priority_init(&mut request); + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "notes" => { + request_priority_init(&mut request); + request.notes = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request_priority_init(&mut request); + request.account_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_containers_triggers_create(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request = api::Trigger::default(); + let mut call = self.hub.accounts().containers_triggers_create(&request, &self.opt.arg_account_id, &self.opt.arg_container_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_check_validation_init(request: &mut api::Trigger) { + if request.check_validation.is_none() { + request.check_validation = Some(Default::default()); + } + } + + fn request_enable_all_videos_init(request: &mut api::Trigger) { + if request.enable_all_videos.is_none() { + request.enable_all_videos = Some(Default::default()); + } + } + + fn request_event_name_init(request: &mut api::Trigger) { + if request.event_name.is_none() { + request.event_name = Some(Default::default()); + } + } + + fn request_interval_init(request: &mut api::Trigger) { + if request.interval.is_none() { + request.interval = Some(Default::default()); + } + } + + fn request_limit_init(request: &mut api::Trigger) { + if request.limit.is_none() { + request.limit = Some(Default::default()); + } + } + + fn request_unique_trigger_id_init(request: &mut api::Trigger) { + if request.unique_trigger_id.is_none() { + request.unique_trigger_id = Some(Default::default()); + } + } + + fn request_video_percentage_list_init(request: &mut api::Trigger) { + if request.video_percentage_list.is_none() { + request.video_percentage_list = Some(Default::default()); + } + } + + fn request_wait_for_tags_init(request: &mut api::Trigger) { + if request.wait_for_tags.is_none() { + request.wait_for_tags = Some(Default::default()); + } + } + + fn request_wait_for_tags_timeout_init(request: &mut api::Trigger) { + if request.wait_for_tags_timeout.is_none() { + request.wait_for_tags_timeout = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "video-percentage-list.type" => { + request_video_percentage_list_init(&mut request); + request.video_percentage_list.as_mut().unwrap().type_ = Some(value.unwrap_or("").to_string()); + }, + "video-percentage-list.value" => { + request_video_percentage_list_init(&mut request); + request.video_percentage_list.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "video-percentage-list.key" => { + request_video_percentage_list_init(&mut request); + request.video_percentage_list.as_mut().unwrap().key = Some(value.unwrap_or("").to_string()); + }, + "interval.type" => { + request_interval_init(&mut request); + request.interval.as_mut().unwrap().type_ = Some(value.unwrap_or("").to_string()); + }, + "interval.value" => { + request_interval_init(&mut request); + request.interval.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "interval.key" => { + request_interval_init(&mut request); + request.interval.as_mut().unwrap().key = Some(value.unwrap_or("").to_string()); + }, + "wait-for-tags.type" => { + request_wait_for_tags_init(&mut request); + request.wait_for_tags.as_mut().unwrap().type_ = Some(value.unwrap_or("").to_string()); + }, + "wait-for-tags.value" => { + request_wait_for_tags_init(&mut request); + request.wait_for_tags.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "wait-for-tags.key" => { + request_wait_for_tags_init(&mut request); + request.wait_for_tags.as_mut().unwrap().key = Some(value.unwrap_or("").to_string()); + }, + "container-id" => { + request_wait_for_tags_init(&mut request); + request.container_id = Some(value.unwrap_or("").to_string()); + }, + "unique-trigger-id.type" => { + request_unique_trigger_id_init(&mut request); + request.unique_trigger_id.as_mut().unwrap().type_ = Some(value.unwrap_or("").to_string()); + }, + "unique-trigger-id.value" => { + request_unique_trigger_id_init(&mut request); + request.unique_trigger_id.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "unique-trigger-id.key" => { + request_unique_trigger_id_init(&mut request); + request.unique_trigger_id.as_mut().unwrap().key = Some(value.unwrap_or("").to_string()); + }, + "wait-for-tags-timeout.type" => { + request_wait_for_tags_timeout_init(&mut request); + request.wait_for_tags_timeout.as_mut().unwrap().type_ = Some(value.unwrap_or("").to_string()); + }, + "wait-for-tags-timeout.value" => { + request_wait_for_tags_timeout_init(&mut request); + request.wait_for_tags_timeout.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "wait-for-tags-timeout.key" => { + request_wait_for_tags_timeout_init(&mut request); + request.wait_for_tags_timeout.as_mut().unwrap().key = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request_wait_for_tags_timeout_init(&mut request); + request.name = Some(value.unwrap_or("").to_string()); + }, + "event-name.type" => { + request_event_name_init(&mut request); + request.event_name.as_mut().unwrap().type_ = Some(value.unwrap_or("").to_string()); + }, + "event-name.value" => { + request_event_name_init(&mut request); + request.event_name.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "event-name.key" => { + request_event_name_init(&mut request); + request.event_name.as_mut().unwrap().key = Some(value.unwrap_or("").to_string()); + }, + "trigger-id" => { + request_event_name_init(&mut request); + request.trigger_id = Some(value.unwrap_or("").to_string()); + }, + "limit.type" => { + request_limit_init(&mut request); + request.limit.as_mut().unwrap().type_ = Some(value.unwrap_or("").to_string()); + }, + "limit.value" => { + request_limit_init(&mut request); + request.limit.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "limit.key" => { + request_limit_init(&mut request); + request.limit.as_mut().unwrap().key = Some(value.unwrap_or("").to_string()); + }, + "check-validation.type" => { + request_check_validation_init(&mut request); + request.check_validation.as_mut().unwrap().type_ = Some(value.unwrap_or("").to_string()); + }, + "check-validation.value" => { + request_check_validation_init(&mut request); + request.check_validation.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "check-validation.key" => { + request_check_validation_init(&mut request); + request.check_validation.as_mut().unwrap().key = Some(value.unwrap_or("").to_string()); + }, + "fingerprint" => { + request_check_validation_init(&mut request); + request.fingerprint = Some(value.unwrap_or("").to_string()); + }, + "type" => { + request_check_validation_init(&mut request); + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "enable-all-videos.type" => { + request_enable_all_videos_init(&mut request); + request.enable_all_videos.as_mut().unwrap().type_ = Some(value.unwrap_or("").to_string()); + }, + "enable-all-videos.value" => { + request_enable_all_videos_init(&mut request); + request.enable_all_videos.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "enable-all-videos.key" => { + request_enable_all_videos_init(&mut request); + request.enable_all_videos.as_mut().unwrap().key = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request_enable_all_videos_init(&mut request); + request.account_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_containers_triggers_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.accounts().containers_triggers_delete(&self.opt.arg_account_id, &self.opt.arg_container_id, &self.opt.arg_trigger_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + None + } + } + } + } + + fn _accounts_containers_triggers_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.accounts().containers_triggers_get(&self.opt.arg_account_id, &self.opt.arg_container_id, &self.opt.arg_trigger_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_containers_triggers_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.accounts().containers_triggers_list(&self.opt.arg_account_id, &self.opt.arg_container_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_containers_triggers_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request = api::Trigger::default(); + let mut call = self.hub.accounts().containers_triggers_update(&request, &self.opt.arg_account_id, &self.opt.arg_container_id, &self.opt.arg_trigger_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "fingerprint" => { + call = call.fingerprint(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_check_validation_init(request: &mut api::Trigger) { + if request.check_validation.is_none() { + request.check_validation = Some(Default::default()); + } + } + + fn request_enable_all_videos_init(request: &mut api::Trigger) { + if request.enable_all_videos.is_none() { + request.enable_all_videos = Some(Default::default()); + } + } + + fn request_event_name_init(request: &mut api::Trigger) { + if request.event_name.is_none() { + request.event_name = Some(Default::default()); + } + } + + fn request_interval_init(request: &mut api::Trigger) { + if request.interval.is_none() { + request.interval = Some(Default::default()); + } + } + + fn request_limit_init(request: &mut api::Trigger) { + if request.limit.is_none() { + request.limit = Some(Default::default()); + } + } + + fn request_unique_trigger_id_init(request: &mut api::Trigger) { + if request.unique_trigger_id.is_none() { + request.unique_trigger_id = Some(Default::default()); + } + } + + fn request_video_percentage_list_init(request: &mut api::Trigger) { + if request.video_percentage_list.is_none() { + request.video_percentage_list = Some(Default::default()); + } + } + + fn request_wait_for_tags_init(request: &mut api::Trigger) { + if request.wait_for_tags.is_none() { + request.wait_for_tags = Some(Default::default()); + } + } + + fn request_wait_for_tags_timeout_init(request: &mut api::Trigger) { + if request.wait_for_tags_timeout.is_none() { + request.wait_for_tags_timeout = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "video-percentage-list.type" => { + request_video_percentage_list_init(&mut request); + request.video_percentage_list.as_mut().unwrap().type_ = Some(value.unwrap_or("").to_string()); + }, + "video-percentage-list.value" => { + request_video_percentage_list_init(&mut request); + request.video_percentage_list.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "video-percentage-list.key" => { + request_video_percentage_list_init(&mut request); + request.video_percentage_list.as_mut().unwrap().key = Some(value.unwrap_or("").to_string()); + }, + "interval.type" => { + request_interval_init(&mut request); + request.interval.as_mut().unwrap().type_ = Some(value.unwrap_or("").to_string()); + }, + "interval.value" => { + request_interval_init(&mut request); + request.interval.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "interval.key" => { + request_interval_init(&mut request); + request.interval.as_mut().unwrap().key = Some(value.unwrap_or("").to_string()); + }, + "wait-for-tags.type" => { + request_wait_for_tags_init(&mut request); + request.wait_for_tags.as_mut().unwrap().type_ = Some(value.unwrap_or("").to_string()); + }, + "wait-for-tags.value" => { + request_wait_for_tags_init(&mut request); + request.wait_for_tags.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "wait-for-tags.key" => { + request_wait_for_tags_init(&mut request); + request.wait_for_tags.as_mut().unwrap().key = Some(value.unwrap_or("").to_string()); + }, + "container-id" => { + request_wait_for_tags_init(&mut request); + request.container_id = Some(value.unwrap_or("").to_string()); + }, + "unique-trigger-id.type" => { + request_unique_trigger_id_init(&mut request); + request.unique_trigger_id.as_mut().unwrap().type_ = Some(value.unwrap_or("").to_string()); + }, + "unique-trigger-id.value" => { + request_unique_trigger_id_init(&mut request); + request.unique_trigger_id.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "unique-trigger-id.key" => { + request_unique_trigger_id_init(&mut request); + request.unique_trigger_id.as_mut().unwrap().key = Some(value.unwrap_or("").to_string()); + }, + "wait-for-tags-timeout.type" => { + request_wait_for_tags_timeout_init(&mut request); + request.wait_for_tags_timeout.as_mut().unwrap().type_ = Some(value.unwrap_or("").to_string()); + }, + "wait-for-tags-timeout.value" => { + request_wait_for_tags_timeout_init(&mut request); + request.wait_for_tags_timeout.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "wait-for-tags-timeout.key" => { + request_wait_for_tags_timeout_init(&mut request); + request.wait_for_tags_timeout.as_mut().unwrap().key = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request_wait_for_tags_timeout_init(&mut request); + request.name = Some(value.unwrap_or("").to_string()); + }, + "event-name.type" => { + request_event_name_init(&mut request); + request.event_name.as_mut().unwrap().type_ = Some(value.unwrap_or("").to_string()); + }, + "event-name.value" => { + request_event_name_init(&mut request); + request.event_name.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "event-name.key" => { + request_event_name_init(&mut request); + request.event_name.as_mut().unwrap().key = Some(value.unwrap_or("").to_string()); + }, + "trigger-id" => { + request_event_name_init(&mut request); + request.trigger_id = Some(value.unwrap_or("").to_string()); + }, + "limit.type" => { + request_limit_init(&mut request); + request.limit.as_mut().unwrap().type_ = Some(value.unwrap_or("").to_string()); + }, + "limit.value" => { + request_limit_init(&mut request); + request.limit.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "limit.key" => { + request_limit_init(&mut request); + request.limit.as_mut().unwrap().key = Some(value.unwrap_or("").to_string()); + }, + "check-validation.type" => { + request_check_validation_init(&mut request); + request.check_validation.as_mut().unwrap().type_ = Some(value.unwrap_or("").to_string()); + }, + "check-validation.value" => { + request_check_validation_init(&mut request); + request.check_validation.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "check-validation.key" => { + request_check_validation_init(&mut request); + request.check_validation.as_mut().unwrap().key = Some(value.unwrap_or("").to_string()); + }, + "fingerprint" => { + request_check_validation_init(&mut request); + request.fingerprint = Some(value.unwrap_or("").to_string()); + }, + "type" => { + request_check_validation_init(&mut request); + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "enable-all-videos.type" => { + request_enable_all_videos_init(&mut request); + request.enable_all_videos.as_mut().unwrap().type_ = Some(value.unwrap_or("").to_string()); + }, + "enable-all-videos.value" => { + request_enable_all_videos_init(&mut request); + request.enable_all_videos.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "enable-all-videos.key" => { + request_enable_all_videos_init(&mut request); + request.enable_all_videos.as_mut().unwrap().key = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request_enable_all_videos_init(&mut request); + request.account_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_containers_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request = api::Container::default(); + let mut call = self.hub.accounts().containers_update(&request, &self.opt.arg_account_id, &self.opt.arg_container_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "fingerprint" => { + call = call.fingerprint(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "time-zone-id" => { + request.time_zone_id = Some(value.unwrap_or("").to_string()); + }, + "enabled-built-in-variable" => { + if request.enabled_built_in_variable.is_none() { + request.enabled_built_in_variable = Some(Default::default()); + } + request.enabled_built_in_variable.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "time-zone-country-id" => { + request.time_zone_country_id = Some(arg_from_str(value.unwrap_or("-0"), err, "time-zone-country-id", "int64")); + }, + "public-id" => { + request.public_id = Some(value.unwrap_or("").to_string()); + }, + "container-id" => { + request.container_id = Some(value.unwrap_or("").to_string()); + }, + "domain-name" => { + if request.domain_name.is_none() { + request.domain_name = Some(Default::default()); + } + request.domain_name.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "notes" => { + request.notes = Some(value.unwrap_or("").to_string()); + }, + "usage-context" => { + if request.usage_context.is_none() { + request.usage_context = Some(Default::default()); + } + request.usage_context.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "fingerprint" => { + request.fingerprint = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request.account_id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_containers_variables_create(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request = api::Variable::default(); + let mut call = self.hub.accounts().containers_variables_create(&request, &self.opt.arg_account_id, &self.opt.arg_container_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "schedule-start-ms" => { + request.schedule_start_ms = Some(value.unwrap_or("").to_string()); + }, + "schedule-end-ms" => { + request.schedule_end_ms = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "variable-id" => { + request.variable_id = Some(value.unwrap_or("").to_string()); + }, + "notes" => { + request.notes = Some(value.unwrap_or("").to_string()); + }, + "enabling-trigger-id" => { + if request.enabling_trigger_id.is_none() { + request.enabling_trigger_id = Some(Default::default()); + } + request.enabling_trigger_id.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "fingerprint" => { + request.fingerprint = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request.account_id = Some(value.unwrap_or("").to_string()); + }, + "type" => { + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "disabling-trigger-id" => { + if request.disabling_trigger_id.is_none() { + request.disabling_trigger_id = Some(Default::default()); + } + request.disabling_trigger_id.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "container-id" => { + request.container_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_containers_variables_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.accounts().containers_variables_delete(&self.opt.arg_account_id, &self.opt.arg_container_id, &self.opt.arg_variable_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + None + } + } + } + } + + fn _accounts_containers_variables_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.accounts().containers_variables_get(&self.opt.arg_account_id, &self.opt.arg_container_id, &self.opt.arg_variable_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_containers_variables_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.accounts().containers_variables_list(&self.opt.arg_account_id, &self.opt.arg_container_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_containers_variables_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request = api::Variable::default(); + let mut call = self.hub.accounts().containers_variables_update(&request, &self.opt.arg_account_id, &self.opt.arg_container_id, &self.opt.arg_variable_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "fingerprint" => { + call = call.fingerprint(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "schedule-start-ms" => { + request.schedule_start_ms = Some(value.unwrap_or("").to_string()); + }, + "schedule-end-ms" => { + request.schedule_end_ms = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "variable-id" => { + request.variable_id = Some(value.unwrap_or("").to_string()); + }, + "notes" => { + request.notes = Some(value.unwrap_or("").to_string()); + }, + "enabling-trigger-id" => { + if request.enabling_trigger_id.is_none() { + request.enabling_trigger_id = Some(Default::default()); + } + request.enabling_trigger_id.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "fingerprint" => { + request.fingerprint = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request.account_id = Some(value.unwrap_or("").to_string()); + }, + "type" => { + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "disabling-trigger-id" => { + if request.disabling_trigger_id.is_none() { + request.disabling_trigger_id = Some(Default::default()); + } + request.disabling_trigger_id.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "container-id" => { + request.container_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_containers_versions_create(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request = api::CreateContainerVersionRequestVersionOptions::default(); + let mut call = self.hub.accounts().containers_versions_create(&request, &self.opt.arg_account_id, &self.opt.arg_container_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "notes" => { + request.notes = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "quick-preview" => { + request.quick_preview = Some(arg_from_str(value.unwrap_or("false"), err, "quick-preview", "boolean")); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_containers_versions_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.accounts().containers_versions_delete(&self.opt.arg_account_id, &self.opt.arg_container_id, &self.opt.arg_container_version_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + None + } + } + } + } + + fn _accounts_containers_versions_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.accounts().containers_versions_get(&self.opt.arg_account_id, &self.opt.arg_container_id, &self.opt.arg_container_version_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_containers_versions_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.accounts().containers_versions_list(&self.opt.arg_account_id, &self.opt.arg_container_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "headers" => { + call = call.headers(arg_from_str(value.unwrap_or("false"), err, "headers", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_containers_versions_publish(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.accounts().containers_versions_publish(&self.opt.arg_account_id, &self.opt.arg_container_id, &self.opt.arg_container_version_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "fingerprint" => { + call = call.fingerprint(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_containers_versions_restore(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.accounts().containers_versions_restore(&self.opt.arg_account_id, &self.opt.arg_container_id, &self.opt.arg_container_version_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_containers_versions_undelete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.accounts().containers_versions_undelete(&self.opt.arg_account_id, &self.opt.arg_container_id, &self.opt.arg_container_version_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_containers_versions_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request = api::ContainerVersion::default(); + let mut call = self.hub.accounts().containers_versions_update(&request, &self.opt.arg_account_id, &self.opt.arg_container_id, &self.opt.arg_container_version_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "fingerprint" => { + call = call.fingerprint(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_container_init(request: &mut api::ContainerVersion) { + if request.container.is_none() { + request.container = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "container.time-zone-id" => { + request_container_init(&mut request); + request.container.as_mut().unwrap().time_zone_id = Some(value.unwrap_or("").to_string()); + }, + "container.enabled-built-in-variable" => { + request_container_init(&mut request); + if request.container.as_mut().unwrap().enabled_built_in_variable.is_none() { + request.container.as_mut().unwrap().enabled_built_in_variable = Some(Default::default()); + } + request.container.as_mut().unwrap().enabled_built_in_variable.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "container.time-zone-country-id" => { + request_container_init(&mut request); + request.container.as_mut().unwrap().time_zone_country_id = Some(arg_from_str(value.unwrap_or("-0"), err, "container.time-zone-country-id", "int64")); + }, + "container.public-id" => { + request_container_init(&mut request); + request.container.as_mut().unwrap().public_id = Some(value.unwrap_or("").to_string()); + }, + "container.container-id" => { + request_container_init(&mut request); + request.container.as_mut().unwrap().container_id = Some(value.unwrap_or("").to_string()); + }, + "container.domain-name" => { + request_container_init(&mut request); + if request.container.as_mut().unwrap().domain_name.is_none() { + request.container.as_mut().unwrap().domain_name = Some(Default::default()); + } + request.container.as_mut().unwrap().domain_name.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "container.notes" => { + request_container_init(&mut request); + request.container.as_mut().unwrap().notes = Some(value.unwrap_or("").to_string()); + }, + "container.usage-context" => { + request_container_init(&mut request); + if request.container.as_mut().unwrap().usage_context.is_none() { + request.container.as_mut().unwrap().usage_context = Some(Default::default()); + } + request.container.as_mut().unwrap().usage_context.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "container.fingerprint" => { + request_container_init(&mut request); + request.container.as_mut().unwrap().fingerprint = Some(value.unwrap_or("").to_string()); + }, + "container.account-id" => { + request_container_init(&mut request); + request.container.as_mut().unwrap().account_id = Some(value.unwrap_or("").to_string()); + }, + "container.name" => { + request_container_init(&mut request); + request.container.as_mut().unwrap().name = Some(value.unwrap_or("").to_string()); + }, + "container-id" => { + request_container_init(&mut request); + request.container_id = Some(value.unwrap_or("").to_string()); + }, + "deleted" => { + request_container_init(&mut request); + request.deleted = Some(arg_from_str(value.unwrap_or("false"), err, "deleted", "boolean")); + }, + "notes" => { + request_container_init(&mut request); + request.notes = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request_container_init(&mut request); + request.name = Some(value.unwrap_or("").to_string()); + }, + "container-version-id" => { + request_container_init(&mut request); + request.container_version_id = Some(value.unwrap_or("").to_string()); + }, + "fingerprint" => { + request_container_init(&mut request); + request.fingerprint = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request_container_init(&mut request); + request.account_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.accounts().get(&self.opt.arg_account_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.accounts().list(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_permissions_create(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request = api::UserAccess::default(); + let mut call = self.hub.accounts().permissions_create(&request, &self.opt.arg_account_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_account_access_init(request: &mut api::UserAccess) { + if request.account_access.is_none() { + request.account_access = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "account-access.permission" => { + request_account_access_init(&mut request); + if request.account_access.as_mut().unwrap().permission.is_none() { + request.account_access.as_mut().unwrap().permission = Some(Default::default()); + } + request.account_access.as_mut().unwrap().permission.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "email-address" => { + request_account_access_init(&mut request); + request.email_address = Some(value.unwrap_or("").to_string()); + }, + "permission-id" => { + request_account_access_init(&mut request); + request.permission_id = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request_account_access_init(&mut request); + request.account_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_permissions_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.accounts().permissions_delete(&self.opt.arg_account_id, &self.opt.arg_permission_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + None + } + } + } + } + + fn _accounts_permissions_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.accounts().permissions_get(&self.opt.arg_account_id, &self.opt.arg_permission_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_permissions_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.accounts().permissions_list(&self.opt.arg_account_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_permissions_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request = api::UserAccess::default(); + let mut call = self.hub.accounts().permissions_update(&request, &self.opt.arg_account_id, &self.opt.arg_permission_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_account_access_init(request: &mut api::UserAccess) { + if request.account_access.is_none() { + request.account_access = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "account-access.permission" => { + request_account_access_init(&mut request); + if request.account_access.as_mut().unwrap().permission.is_none() { + request.account_access.as_mut().unwrap().permission = Some(Default::default()); + } + request.account_access.as_mut().unwrap().permission.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "email-address" => { + request_account_access_init(&mut request); + request.email_address = Some(value.unwrap_or("").to_string()); + }, + "permission-id" => { + request_account_access_init(&mut request); + request.permission_id = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request_account_access_init(&mut request); + request.account_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request = api::Account::default(); + let mut call = self.hub.accounts().update(&request, &self.opt.arg_account_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "fingerprint" => { + call = call.fingerprint(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "share-data" => { + request.share_data = Some(arg_from_str(value.unwrap_or("false"), err, "share-data", "boolean")); + }, + "fingerprint" => { + request.fingerprint = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request.account_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option<api::Error>, Option<InvalidOptionsError>) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option<api::Error>; + let mut err_opt: Option<InvalidOptionsError> = None; + + if self.opt.cmd_accounts { + if self.opt.cmd_containers_create { + call_result = self._accounts_containers_create(dry_run, &mut err); + } else if self.opt.cmd_containers_delete { + call_result = self._accounts_containers_delete(dry_run, &mut err); + } else if self.opt.cmd_containers_get { + call_result = self._accounts_containers_get(dry_run, &mut err); + } else if self.opt.cmd_containers_list { + call_result = self._accounts_containers_list(dry_run, &mut err); + } else if self.opt.cmd_containers_macros_create { + call_result = self._accounts_containers_macros_create(dry_run, &mut err); + } else if self.opt.cmd_containers_macros_delete { + call_result = self._accounts_containers_macros_delete(dry_run, &mut err); + } else if self.opt.cmd_containers_macros_get { + call_result = self._accounts_containers_macros_get(dry_run, &mut err); + } else if self.opt.cmd_containers_macros_list { + call_result = self._accounts_containers_macros_list(dry_run, &mut err); + } else if self.opt.cmd_containers_macros_update { + call_result = self._accounts_containers_macros_update(dry_run, &mut err); + } else if self.opt.cmd_containers_rules_create { + call_result = self._accounts_containers_rules_create(dry_run, &mut err); + } else if self.opt.cmd_containers_rules_delete { + call_result = self._accounts_containers_rules_delete(dry_run, &mut err); + } else if self.opt.cmd_containers_rules_get { + call_result = self._accounts_containers_rules_get(dry_run, &mut err); + } else if self.opt.cmd_containers_rules_list { + call_result = self._accounts_containers_rules_list(dry_run, &mut err); + } else if self.opt.cmd_containers_rules_update { + call_result = self._accounts_containers_rules_update(dry_run, &mut err); + } else if self.opt.cmd_containers_tags_create { + call_result = self._accounts_containers_tags_create(dry_run, &mut err); + } else if self.opt.cmd_containers_tags_delete { + call_result = self._accounts_containers_tags_delete(dry_run, &mut err); + } else if self.opt.cmd_containers_tags_get { + call_result = self._accounts_containers_tags_get(dry_run, &mut err); + } else if self.opt.cmd_containers_tags_list { + call_result = self._accounts_containers_tags_list(dry_run, &mut err); + } else if self.opt.cmd_containers_tags_update { + call_result = self._accounts_containers_tags_update(dry_run, &mut err); + } else if self.opt.cmd_containers_triggers_create { + call_result = self._accounts_containers_triggers_create(dry_run, &mut err); + } else if self.opt.cmd_containers_triggers_delete { + call_result = self._accounts_containers_triggers_delete(dry_run, &mut err); + } else if self.opt.cmd_containers_triggers_get { + call_result = self._accounts_containers_triggers_get(dry_run, &mut err); + } else if self.opt.cmd_containers_triggers_list { + call_result = self._accounts_containers_triggers_list(dry_run, &mut err); + } else if self.opt.cmd_containers_triggers_update { + call_result = self._accounts_containers_triggers_update(dry_run, &mut err); + } else if self.opt.cmd_containers_update { + call_result = self._accounts_containers_update(dry_run, &mut err); + } else if self.opt.cmd_containers_variables_create { + call_result = self._accounts_containers_variables_create(dry_run, &mut err); + } else if self.opt.cmd_containers_variables_delete { + call_result = self._accounts_containers_variables_delete(dry_run, &mut err); + } else if self.opt.cmd_containers_variables_get { + call_result = self._accounts_containers_variables_get(dry_run, &mut err); + } else if self.opt.cmd_containers_variables_list { + call_result = self._accounts_containers_variables_list(dry_run, &mut err); + } else if self.opt.cmd_containers_variables_update { + call_result = self._accounts_containers_variables_update(dry_run, &mut err); + } else if self.opt.cmd_containers_versions_create { + call_result = self._accounts_containers_versions_create(dry_run, &mut err); + } else if self.opt.cmd_containers_versions_delete { + call_result = self._accounts_containers_versions_delete(dry_run, &mut err); + } else if self.opt.cmd_containers_versions_get { + call_result = self._accounts_containers_versions_get(dry_run, &mut err); + } else if self.opt.cmd_containers_versions_list { + call_result = self._accounts_containers_versions_list(dry_run, &mut err); + } else if self.opt.cmd_containers_versions_publish { + call_result = self._accounts_containers_versions_publish(dry_run, &mut err); + } else if self.opt.cmd_containers_versions_restore { + call_result = self._accounts_containers_versions_restore(dry_run, &mut err); + } else if self.opt.cmd_containers_versions_undelete { + call_result = self._accounts_containers_versions_undelete(dry_run, &mut err); + } else if self.opt.cmd_containers_versions_update { + call_result = self._accounts_containers_versions_update(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._accounts_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._accounts_list(dry_run, &mut err); + } else if self.opt.cmd_permissions_create { + call_result = self._accounts_permissions_create(dry_run, &mut err); + } else if self.opt.cmd_permissions_delete { + call_result = self._accounts_permissions_delete(dry_run, &mut err); + } else if self.opt.cmd_permissions_get { + call_result = self._accounts_permissions_get(dry_run, &mut err); + } else if self.opt.cmd_permissions_list { + call_result = self._accounts_permissions_list(dry_run, &mut err); + } else if self.opt.cmd_permissions_update { + call_result = self._accounts_permissions_update(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._accounts_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else { + unreachable!(); + } + + if dry_run { + if err.issues.len() > 0 { + err_opt = Some(err); + } + } + (call_result, err_opt) + } + + // Please note that this call will fail if any part of the opt can't be handled + fn new(opt: Options) -> Result<Engine, InvalidOptionsError> { + let (config_dir, secret) = { + let config_dir = match cmn::assure_config_dir_exists(&opt.flag_config_dir) { + Err(e) => return Err(InvalidOptionsError::single(e, 3)), + Ok(p) => p, + }; + + match cmn::application_secret_from_directory(&config_dir, "tagmanager1-secret.json", + "{\"installed\":{\"auth_uri\":\"https://accounts.google.com/o/oauth2/auth\",\"client_secret\":\"hCsslbCUyfehWMmbkG8vTYxG\",\"token_uri\":\"https://accounts.google.com/o/oauth2/token\",\"client_email\":\"\",\"redirect_uris\":[\"urn:ietf:wg:oauth:2.0:oob\",\"oob\"],\"client_x509_cert_url\":\"\",\"client_id\":\"620010449518-9ngf7o4dhs0dka470npqvor6dc5lqb9b.apps.googleusercontent.com\",\"auth_provider_x509_cert_url\":\"https://www.googleapis.com/oauth2/v1/certs\"}}") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new( &secret, DefaultAuthenticatorDelegate, + if opt.flag_debug_auth { + hyper::Client::with_connector(mock::TeeConnector { + connector: hyper::net::HttpConnector(None) + }) + } else { + hyper::Client::new() + }, + JsonTokenStorage { + program_name: "tagmanager1", + db_dir: config_dir.clone(), + }, None); + + let client = + if opt.flag_debug { + hyper::Client::with_connector(mock::TeeConnector { + connector: hyper::net::HttpConnector(None) + }) + } else { + hyper::Client::new() + }; + let engine = Engine { + opt: opt, + hub: api::TagManager::new(client, auth), + }; + + match engine._doit(true) { + (_, Some(err)) => Err(err), + _ => Ok(engine), + } + } + + // Execute the call with all the bells and whistles, informing the caller only if there was an error. + // The absense of one indicates success. + fn doit(&self) -> Option<api::Error> { + self._doit(false).0 + } +} + +fn main() { + let opts: Options = Options::docopt().decode().unwrap_or_else(|e| e.exit()); + match Engine::new(opts) { + Err(err) => { + writeln!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + writeln!(io::stderr(), "{:?}", err).ok(); + writeln!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/taskqueue1_beta2-cli/Cargo.toml b/gen/taskqueue1_beta2-cli/Cargo.toml new file mode 100644 index 0000000000..9790921b57 --- /dev/null +++ b/gen/taskqueue1_beta2-cli/Cargo.toml @@ -0,0 +1,31 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-taskqueue1_beta2-cli" +version = "0.0.1+20141111" +authors = ["Sebastian Thiel <byronimo@gmail.com>"] +description = "A complete library to interact with taskqueue (protocol v1beta2)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/taskqueue1_beta2-cli" +homepage = "https://developers.google.com/appengine/docs/python/taskqueue/rest" +documentation = "http://byron.github.io/google-apis-rs/google_taskqueue1_beta2_cli" +license = "MIT" +keywords = ["taskqueue", "google", "cli"] + +[[bin]] +name = "taskqueue1-beta2" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "*" +docopt_macros = "*" +rustc-serialize = "*" +yup-hyper-mock = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-taskqueue1_beta2] +path = "../taskqueue1_beta2" diff --git a/gen/taskqueue1_beta2-cli/LICENSE.md b/gen/taskqueue1_beta2-cli/LICENSE.md new file mode 100644 index 0000000000..ae22e6ec52 --- /dev/null +++ b/gen/taskqueue1_beta2-cli/LICENSE.md @@ -0,0 +1,30 @@ +<!--- +DO NOT EDIT ! +This file was generated automatically from 'src/mako/LICENSE.md.mako' +DO NOT EDIT ! +--> +The MIT License (MIT) +===================== + +Copyright © `2015` `Sebastian Thiel` + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the “Software”), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. diff --git a/gen/taskqueue1_beta2-cli/README.md b/gen/taskqueue1_beta2-cli/README.md new file mode 100644 index 0000000000..7baaf70b4b --- /dev/null +++ b/gen/taskqueue1_beta2-cli/README.md @@ -0,0 +1,4 @@ +# HELLO TASKQUEUE:V1BETA2 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/taskqueue1_beta2-cli/mkdocs.yml b/gen/taskqueue1_beta2-cli/mkdocs.yml new file mode 100644 index 0000000000..88e631eedb --- /dev/null +++ b/gen/taskqueue1_beta2-cli/mkdocs.yml @@ -0,0 +1,24 @@ +site_name: taskqueue v0.0.1+20141111 +site_url: http://byron.github.io/google-apis-rs/google-taskqueue1_beta2-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/taskqueue1_beta2-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['taskqueues_get.md', 'Taskqueues', 'Get'] +- ['tasks_delete.md', 'Tasks', 'Delete'] +- ['tasks_get.md', 'Tasks', 'Get'] +- ['tasks_insert.md', 'Tasks', 'Insert'] +- ['tasks_lease.md', 'Tasks', 'Lease'] +- ['tasks_list.md', 'Tasks', 'List'] +- ['tasks_patch.md', 'Tasks', 'Patch'] +- ['tasks_update.md', 'Tasks', 'Update'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/taskqueue1_beta2-cli/src/cmn.rs b/gen/taskqueue1_beta2-cli/src/cmn.rs new file mode 100644 index 0000000000..a8d3f46368 --- /dev/null +++ b/gen/taskqueue1_beta2-cli/src/cmn.rs @@ -0,0 +1,454 @@ +// COPY OF 'src/rust/cli/cmn.rs' +// DO NOT EDIT +use oauth2::{ApplicationSecret, ConsoleApplicationSecret, TokenStorage, Token}; +use rustc_serialize::json; +use mime::Mime; + +use std::fs; +use std::env; +use std::io; +use std::fmt; +use std::path::{Path, PathBuf}; +use std::str::FromStr; +use std::string::ToString; +use std::io::{Write, Read, stdout}; + +use std::default::Default; + +const FIELD_SEP: char = '.'; + +#[derive(Clone, Default)] +pub struct FieldCursor(Vec<String>); + +impl ToString for FieldCursor { + fn to_string(&self) -> String { + self.0.connect(".") + } +} + +impl FieldCursor { + pub fn set(&mut self, value: &str) -> Result<(), CLIError> { + if value.len() == 0 { + return Err(CLIError::Field(FieldError::Empty)) + } + + let mut first_is_field_sep = false; + let mut char_count: usize = 0; + let mut last_c = FIELD_SEP; + let mut num_conscutive_field_seps = 0; + + let mut field = String::new(); + let mut fields = self.0.clone(); + + let push_field = |fs: &mut Vec<String>, f: &mut String| { + if f.len() > 0 { + fs.push(f.clone()); + f.truncate(0); + } + }; + + for (cid, c) in value.chars().enumerate() { + char_count += 1; + + if c == FIELD_SEP { + if cid == 0 { + first_is_field_sep = true; + } + num_conscutive_field_seps += 1; + if cid > 0 && last_c == FIELD_SEP { + if fields.pop().is_none() { + return Err(CLIError::Field(FieldError::PopOnEmpty(value.to_string()))) + } + } else { + push_field(&mut fields, &mut field); + } + } else { + num_conscutive_field_seps = 0; + if cid == 1 { + if first_is_field_sep { + fields.truncate(0); + } + } + field.push(c); + } + + last_c = c; + } + + push_field(&mut fields, &mut field); + + if char_count == 1 && first_is_field_sep { + fields.truncate(0); + } + if char_count > 1 && num_conscutive_field_seps == 1 { + return Err(CLIError::Field(FieldError::TrailingFieldSep(value.to_string()))) + } + + self.0 = fields; + Ok(()) + } + + pub fn num_fields(&self) -> usize { + self.0.len() + } +} + +pub fn parse_kv_arg<'a>(kv: &'a str, err: &mut InvalidOptionsError, for_hashmap: bool) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string(),for_hashmap)); + match kv.find('=') { + None => { + add_err(); + return (kv, None) + }, + Some(pos) => { + let key = &kv[..pos]; + if kv.len() <= pos + 1 { + add_err(); + return (key, None) + } + (key, Some(&kv[pos+1..])) + } + } +} + +pub fn input_file_from_opts(file_path: &str, err: &mut InvalidOptionsError) -> Option<fs::File> { + match fs::File::open(file_path) { + Ok(f) => Some(f), + Err(io_err) => { + err.issues.push(CLIError::Input(InputError::IOError((file_path.to_string(), io_err)))); + None + } + } +} + +pub fn input_mime_from_opts(mime: &str, err: &mut InvalidOptionsError) -> Option<Mime> { + match mime.parse() { + Ok(m) => Some(m), + Err(_) => { + err.issues.push(CLIError::Input(InputError::Mime(mime.to_string()))); + None + } + } +} + +// May panic if we can't open the file - this is anticipated, we can't currently communicate this +// kind of error: TODO: fix this architecture :) +pub fn writer_from_opts(flag: bool, arg: &str) -> Box<Write> { + if !flag || arg == "-" { + Box::new(stdout()) + } else { + Box::new(fs::OpenOptions::new().create(true).write(true).open(arg).unwrap()) + } +} + + +pub fn arg_from_str<T>(arg: &str, err: &mut InvalidOptionsError, + arg_name: &'static str, + arg_type: &'static 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))) + ); + Default::default() + }, + Ok(v) => v, + } +} + +pub struct JsonTokenStorage { + pub program_name: &'static str, + pub db_dir: String, +} + +impl JsonTokenStorage { + fn path(&self, scope_hash: u64) -> PathBuf { + Path::new(&self.db_dir).join(&format!("{}-token-{}.json", self.program_name, scope_hash)) + } +} + +impl TokenStorage for JsonTokenStorage { + type Error = io::Error; + + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, _: &Vec<&str>, token: Option<Token>) -> Option<io::Error> { + match token { + None => { + match fs::remove_file(self.path(scope_hash)) { + Err(err) => + match err.kind() { + io::ErrorKind::NotFound => None, + _ => Some(err) + }, + Ok(_) => None + } + } + Some(token) => { + let json_token = json::encode(&token).unwrap(); + match fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)) { + Ok(mut f) => { + match f.write(json_token.as_bytes()) { + Ok(_) => None, + Err(io_err) => Some(io_err), + } + }, + Err(io_err) => Some(io_err) + } + } + } + } + + fn get(&self, scope_hash: u64, _: &Vec<&str>) -> Result<Option<Token>, io::Error> { + match fs::File::open(&self.path(scope_hash)) { + Ok(mut f) => { + let mut json_string = String::new(); + match f.read_to_string(&mut json_string) { + Ok(_) => Ok(Some(json::decode::<Token>(&json_string).unwrap())), + Err(io_err) => Err(io_err), + } + }, + Err(io_err) => { + match io_err.kind() { + io::ErrorKind::NotFound => Ok(None), + _ => Err(io_err) + } + } + } + } +} + + +#[derive(Debug)] +pub enum ApplicationSecretError { + DecoderError((String, json::DecoderError)), + FormatError(String), +} + +impl fmt::Display for ApplicationSecretError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + match *self { + ApplicationSecretError::DecoderError((ref path, ref err)) + => writeln!(f, "Could not decode file at '{}' with error: {}", + path, err), + ApplicationSecretError::FormatError(ref path) + => writeln!(f, "'installed' field is unset in secret file at '{}'", + path), + } + } +} + +#[derive(Debug)] +pub enum ConfigurationError { + DirectoryCreationFailed((String, io::Error)), + DirectoryUnset, + HomeExpansionFailed(String), + Secret(ApplicationSecretError), + IOError((String, io::Error)), +} + +impl fmt::Display for ConfigurationError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + match *self { + ConfigurationError::DirectoryCreationFailed((ref dir, ref err)) + => writeln!(f, "Directory '{}' could not be created with error: {}", dir, err), + ConfigurationError::DirectoryUnset + => writeln!(f, "--config-dir was unset or empty"), + ConfigurationError::HomeExpansionFailed(ref dir) + => writeln!(f, "Couldn't find HOME directory of current user, failed to expand '{}'", dir), + ConfigurationError::Secret(ref err) + => writeln!(f, "Secret -> {}", err), + ConfigurationError::IOError((ref path, ref err)) + => writeln!(f, "IO operation failed on path '{}' with error: {}", path, err), + } + } +} + +#[derive(Debug)] +pub enum InputError { + IOError((String, io::Error)), + Mime(String), +} + +impl fmt::Display for InputError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + match *self { + InputError::IOError((ref file_path, ref io_err)) + => writeln!(f, "Failed to open '{}' for reading with error: {}", file_path, io_err), + InputError::Mime(ref mime) + => writeln!(f, "'{}' is not a known mime-type", mime), + } + } +} + +#[derive(Debug)] +pub enum FieldError { + PopOnEmpty(String), + TrailingFieldSep(String), + Unknown(String), + Empty, +} + + +impl fmt::Display for FieldError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + match *self { + FieldError::PopOnEmpty(ref field) + => writeln!(f, "'{}': Cannot move up on empty field cursor", field), + FieldError::TrailingFieldSep(ref field) + => writeln!(f, "'{}': Single field separator may not be last character", field), + FieldError::Unknown(ref field) + => writeln!(f, "Field '{}' does not exist", field), + FieldError::Empty + => writeln!(f, "Field names must not be empty"), + } + } +} + + +#[derive(Debug)] +pub enum CLIError { + Configuration(ConfigurationError), + ParseError((&'static str, &'static str, String, String)), + UnknownParameter(String), + InvalidKeyValueSyntax(String, bool), + Input(InputError), + Field(FieldError), +} + +impl fmt::Display for CLIError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + match *self { + CLIError::Configuration(ref err) => write!(f, "Configuration -> {}", err), + CLIError::Input(ref err) => write!(f, "Input -> {}", err), + CLIError::Field(ref err) => write!(f, "Field -> {}", err), + CLIError::ParseError((arg_name, 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) + => writeln!(f, "Parameter '{}' is unknown.", param_name), + CLIError::InvalidKeyValueSyntax(ref kv, is_hashmap) => { + let hashmap_info = if is_hashmap { "hashmap " } else { "" }; + writeln!(f, "'{}' does not match {}pattern <key>=<value>", kv, hashmap_info) + }, + } + } +} + +#[derive(Debug)] +pub struct InvalidOptionsError { + pub issues: Vec<CLIError>, + pub exit_code: i32, +} + +impl fmt::Display for InvalidOptionsError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + for issue in &self.issues { + try!(issue.fmt(f)); + } + Ok(()) + } +} + +impl InvalidOptionsError { + pub fn single(err: CLIError, exit_code: i32) -> InvalidOptionsError { + InvalidOptionsError { + issues: vec![err], + exit_code: exit_code, + } + } + + pub fn new() -> InvalidOptionsError { + InvalidOptionsError { + issues: Vec::new(), + exit_code: 1, + } + } +} + +pub fn assure_config_dir_exists(dir: &str) -> Result<String, CLIError> { + let trdir = dir.trim(); + if trdir.len() == 0 { + return Err(CLIError::Configuration(ConfigurationError::DirectoryUnset)) + } + + let expanded_config_dir = + if trdir.as_bytes()[0] == b'~' { + match env::var("HOME").ok().or(env::var("UserProfile").ok()) { + None => return Err(CLIError::Configuration(ConfigurationError::HomeExpansionFailed(trdir.to_string()))), + Some(mut user) => { + user.push_str(&trdir[1..]); + user + } + } + } else { + trdir.to_string() + }; + + if let Err(err) = fs::create_dir(&expanded_config_dir) { + if err.kind() != io::ErrorKind::AlreadyExists { + return Err(CLIError::Configuration( + ConfigurationError::DirectoryCreationFailed((expanded_config_dir, err)))) + } + } + + Ok(expanded_config_dir) +} + +pub fn application_secret_from_directory(dir: &str, + secret_basename: &str, + json_app_secret: &str) + -> Result<ApplicationSecret, CLIError> { + let secret_path = Path::new(dir).join(secret_basename); + let secret_str = || secret_path.as_path().to_str().unwrap().to_string(); + let secret_io_error = |io_err: io::Error| { + Err(CLIError::Configuration(ConfigurationError::IOError( + (secret_str(), io_err) + ))) + }; + + for _ in 0..2 { + match fs::File::open(&secret_path) { + Err(mut err) => { + if err.kind() == io::ErrorKind::NotFound { + // Write our built-in one - user may adjust the written file at will + + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_app_secret.as_bytes()) { + Err(io_err) => io_err, + Ok(_) => continue, + } + } + }; + // fall through to IO error handling + } + return secret_io_error(err) + }, + Ok(mut f) => { + let mut json_encoded_secret = String::new(); + if let Err(io_err) = f.read_to_string(&mut json_encoded_secret) { + return secret_io_error(io_err) + } + match json::decode::<ConsoleApplicationSecret>(&json_encoded_secret) { + Err(json_decode_error) => return Err(CLIError::Configuration( + ConfigurationError::Secret(ApplicationSecretError::DecoderError( + (secret_str(), json_decode_error) + )))), + Ok(console_secret) => match console_secret.installed { + Some(secret) => return Ok(secret), + None => return Err( + CLIError::Configuration( + ConfigurationError::Secret( + ApplicationSecretError::FormatError(secret_str()) + ))) + }, + } + } + } + } + unreachable!(); +} \ No newline at end of file diff --git a/gen/taskqueue1_beta2-cli/src/main.rs b/gen/taskqueue1_beta2-cli/src/main.rs new file mode 100644 index 0000000000..ed62ba55f3 --- /dev/null +++ b/gen/taskqueue1_beta2-cli/src/main.rs @@ -0,0 +1,648 @@ +// DO NOT EDIT ! +// This file was generated automatically from 'src/mako/cli/main.rs.mako' +// DO NOT EDIT ! +#![feature(plugin, exit_status)] +#![plugin(docopt_macros)] +#![allow(unused_variables, unused_imports, dead_code, unused_mut)] + +extern crate docopt; +extern crate yup_oauth2 as oauth2; +extern crate yup_hyper_mock as mock; +extern crate rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_taskqueue1_beta2 as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + taskqueue1-beta2 [options] taskqueues get <project> <taskqueue> [-p <v>]... [-o <out>] + taskqueue1-beta2 [options] tasks delete <project> <taskqueue> <task> [-p <v>]... + taskqueue1-beta2 [options] tasks get <project> <taskqueue> <task> [-p <v>]... [-o <out>] + taskqueue1-beta2 [options] tasks insert <project> <taskqueue> -r <kv>... [-p <v>]... [-o <out>] + taskqueue1-beta2 [options] tasks lease <project> <taskqueue> <num-tasks> <lease-secs> [-p <v>]... [-o <out>] + taskqueue1-beta2 [options] tasks list <project> <taskqueue> [-p <v>]... [-o <out>] + taskqueue1-beta2 [options] tasks patch <project> <taskqueue> <task> <new-lease-seconds> -r <kv>... [-p <v>]... [-o <out>] + taskqueue1-beta2 [options] tasks update <project> <taskqueue> <task> <new-lease-seconds> -r <kv>... [-p <v>]... [-o <out>] + taskqueue1-beta2 --help + +All documentation details can be found TODO: <URL to github.io docs here, see #51> + +Configuration: + --scope <url> + 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. + --config-dir <folder> + 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] + --debug + Output all server communication to standard error. `tx` and `rx` are placed into + the same stream. + --debug-auth + Output all communication related to authentication to standard error. `tx` and `rx` are placed into + the same stream. +"); + +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}; + +use std::default::Default; +use std::str::FromStr; + +use oauth2::{Authenticator, DefaultAuthenticatorDelegate}; +use rustc_serialize::json; + +struct Engine { + opt: Options, + hub: api::Taskqueue<hyper::Client, Authenticator<DefaultAuthenticatorDelegate, JsonTokenStorage, hyper::Client>>, +} + + +impl Engine { + fn _taskqueues_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.taskqueues().get(&self.opt.arg_project, &self.opt.arg_taskqueue); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "get-stats" => { + call = call.get_stats(arg_from_str(value.unwrap_or("false"), err, "get-stats", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _tasks_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.tasks().delete(&self.opt.arg_project, &self.opt.arg_taskqueue, &self.opt.arg_task); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + None + } + } + } + } + + fn _tasks_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.tasks().get(&self.opt.arg_project, &self.opt.arg_taskqueue, &self.opt.arg_task); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _tasks_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request = api::Task::default(); + let mut call = self.hub.tasks().insert(&request, &self.opt.arg_project, &self.opt.arg_taskqueue); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "lease-timestamp" => { + request.lease_timestamp = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "retry-count" => { + request.retry_count = Some(arg_from_str(value.unwrap_or("-0"), err, "retry-count", "integer")); + }, + "tag" => { + request.tag = Some(value.unwrap_or("").to_string()); + }, + "payload-base64" => { + request.payload_base64 = Some(value.unwrap_or("").to_string()); + }, + "queue-name" => { + request.queue_name = Some(value.unwrap_or("").to_string()); + }, + "enqueue-timestamp" => { + request.enqueue_timestamp = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _tasks_lease(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let num_tasks: i32 = arg_from_str(&self.opt.arg_num_tasks, err, "<num-tasks>", "integer"); + let lease_secs: i32 = arg_from_str(&self.opt.arg_lease_secs, err, "<lease-secs>", "integer"); + let mut call = self.hub.tasks().lease(&self.opt.arg_project, &self.opt.arg_taskqueue, num_tasks, lease_secs); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "tag" => { + call = call.tag(value.unwrap_or("")); + }, + "group-by-tag" => { + call = call.group_by_tag(arg_from_str(value.unwrap_or("false"), err, "group-by-tag", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _tasks_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.tasks().list(&self.opt.arg_project, &self.opt.arg_taskqueue); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _tasks_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request = api::Task::default(); + let new_lease_seconds: i32 = arg_from_str(&self.opt.arg_new_lease_seconds, err, "<new-lease-seconds>", "integer"); + let mut call = self.hub.tasks().patch(&request, &self.opt.arg_project, &self.opt.arg_taskqueue, &self.opt.arg_task, new_lease_seconds); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "lease-timestamp" => { + request.lease_timestamp = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "retry-count" => { + request.retry_count = Some(arg_from_str(value.unwrap_or("-0"), err, "retry-count", "integer")); + }, + "tag" => { + request.tag = Some(value.unwrap_or("").to_string()); + }, + "payload-base64" => { + request.payload_base64 = Some(value.unwrap_or("").to_string()); + }, + "queue-name" => { + request.queue_name = Some(value.unwrap_or("").to_string()); + }, + "enqueue-timestamp" => { + request.enqueue_timestamp = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _tasks_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request = api::Task::default(); + let new_lease_seconds: i32 = arg_from_str(&self.opt.arg_new_lease_seconds, err, "<new-lease-seconds>", "integer"); + let mut call = self.hub.tasks().update(&request, &self.opt.arg_project, &self.opt.arg_taskqueue, &self.opt.arg_task, new_lease_seconds); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + + let mut field_name = FieldCursor::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err, false); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "lease-timestamp" => { + request.lease_timestamp = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "retry-count" => { + request.retry_count = Some(arg_from_str(value.unwrap_or("-0"), err, "retry-count", "integer")); + }, + "tag" => { + request.tag = Some(value.unwrap_or("").to_string()); + }, + "payload-base64" => { + request.payload_base64 = Some(value.unwrap_or("").to_string()); + }, + "queue-name" => { + request.queue_name = Some(value.unwrap_or("").to_string()); + }, + "enqueue-timestamp" => { + request.enqueue_timestamp = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option<api::Error>, Option<InvalidOptionsError>) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option<api::Error>; + let mut err_opt: Option<InvalidOptionsError> = None; + + if self.opt.cmd_taskqueues { + if self.opt.cmd_get { + call_result = self._taskqueues_get(dry_run, &mut err); + } else { + unreachable!(); + } + } + else if self.opt.cmd_tasks { + if self.opt.cmd_delete { + call_result = self._tasks_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._tasks_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._tasks_insert(dry_run, &mut err); + } else if self.opt.cmd_lease { + call_result = self._tasks_lease(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._tasks_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._tasks_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._tasks_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else { + unreachable!(); + } + + if dry_run { + if err.issues.len() > 0 { + err_opt = Some(err); + } + } + (call_result, err_opt) + } + + // Please note that this call will fail if any part of the opt can't be handled + fn new(opt: Options) -> Result<Engine, InvalidOptionsError> { + let (config_dir, secret) = { + let config_dir = match cmn::assure_config_dir_exists(&opt.flag_config_dir) { + Err(e) => return Err(InvalidOptionsError::single(e, 3)), + Ok(p) => p, + }; + + match cmn::application_secret_from_directory(&config_dir, "taskqueue1-beta2-secret.json", + "{\"installed\":{\"auth_uri\":\"https://accounts.google.com/o/oauth2/auth\",\"client_secret\":\"hCsslbCUyfehWMmbkG8vTYxG\",\"token_uri\":\"https://accounts.google.com/o/oauth2/token\",\"client_email\":\"\",\"redirect_uris\":[\"urn:ietf:wg:oauth:2.0:oob\",\"oob\"],\"client_x509_cert_url\":\"\",\"client_id\":\"620010449518-9ngf7o4dhs0dka470npqvor6dc5lqb9b.apps.googleusercontent.com\",\"auth_provider_x509_cert_url\":\"https://www.googleapis.com/oauth2/v1/certs\"}}") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new( &secret, DefaultAuthenticatorDelegate, + if opt.flag_debug_auth { + hyper::Client::with_connector(mock::TeeConnector { + connector: hyper::net::HttpConnector(None) + }) + } else { + hyper::Client::new() + }, + JsonTokenStorage { + program_name: "taskqueue1-beta2", + db_dir: config_dir.clone(), + }, None); + + let client = + if opt.flag_debug { + hyper::Client::with_connector(mock::TeeConnector { + connector: hyper::net::HttpConnector(None) + }) + } else { + hyper::Client::new() + }; + let engine = Engine { + opt: opt, + hub: api::Taskqueue::new(client, auth), + }; + + match engine._doit(true) { + (_, Some(err)) => Err(err), + _ => Ok(engine), + } + } + + // Execute the call with all the bells and whistles, informing the caller only if there was an error. + // The absense of one indicates success. + fn doit(&self) -> Option<api::Error> { + self._doit(false).0 + } +} + +fn main() { + let opts: Options = Options::docopt().decode().unwrap_or_else(|e| e.exit()); + match Engine::new(opts) { + Err(err) => { + writeln!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + writeln!(io::stderr(), "{:?}", err).ok(); + writeln!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/webfonts1-cli/Cargo.toml b/gen/webfonts1-cli/Cargo.toml new file mode 100644 index 0000000000..983f237653 --- /dev/null +++ b/gen/webfonts1-cli/Cargo.toml @@ -0,0 +1,31 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-webfonts1-cli" +version = "0.0.1+20140210" +authors = ["Sebastian Thiel <byronimo@gmail.com>"] +description = "A complete library to interact with webfonts (protocol v1)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/webfonts1-cli" +homepage = "https://developers.google.com/fonts/docs/developer_api" +documentation = "http://byron.github.io/google-apis-rs/google_webfonts1_cli" +license = "MIT" +keywords = ["webfonts", "google", "cli"] + +[[bin]] +name = "webfonts1" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "*" +docopt_macros = "*" +rustc-serialize = "*" +yup-hyper-mock = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-webfonts1] +path = "../webfonts1" diff --git a/gen/webfonts1-cli/LICENSE.md b/gen/webfonts1-cli/LICENSE.md new file mode 100644 index 0000000000..ae22e6ec52 --- /dev/null +++ b/gen/webfonts1-cli/LICENSE.md @@ -0,0 +1,30 @@ +<!--- +DO NOT EDIT ! +This file was generated automatically from 'src/mako/LICENSE.md.mako' +DO NOT EDIT ! +--> +The MIT License (MIT) +===================== + +Copyright © `2015` `Sebastian Thiel` + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the “Software”), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. diff --git a/gen/webfonts1-cli/README.md b/gen/webfonts1-cli/README.md new file mode 100644 index 0000000000..5c37fe560e --- /dev/null +++ b/gen/webfonts1-cli/README.md @@ -0,0 +1,4 @@ +# HELLO WEBFONTS:V1 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/webfonts1-cli/mkdocs.yml b/gen/webfonts1-cli/mkdocs.yml new file mode 100644 index 0000000000..924720343c --- /dev/null +++ b/gen/webfonts1-cli/mkdocs.yml @@ -0,0 +1,17 @@ +site_name: webfonts v0.0.1+20140210 +site_url: http://byron.github.io/google-apis-rs/google-webfonts1-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/webfonts1-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['webfonts_list.md', 'Webfonts', 'List'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/webfonts1-cli/src/cmn.rs b/gen/webfonts1-cli/src/cmn.rs new file mode 100644 index 0000000000..a8d3f46368 --- /dev/null +++ b/gen/webfonts1-cli/src/cmn.rs @@ -0,0 +1,454 @@ +// COPY OF 'src/rust/cli/cmn.rs' +// DO NOT EDIT +use oauth2::{ApplicationSecret, ConsoleApplicationSecret, TokenStorage, Token}; +use rustc_serialize::json; +use mime::Mime; + +use std::fs; +use std::env; +use std::io; +use std::fmt; +use std::path::{Path, PathBuf}; +use std::str::FromStr; +use std::string::ToString; +use std::io::{Write, Read, stdout}; + +use std::default::Default; + +const FIELD_SEP: char = '.'; + +#[derive(Clone, Default)] +pub struct FieldCursor(Vec<String>); + +impl ToString for FieldCursor { + fn to_string(&self) -> String { + self.0.connect(".") + } +} + +impl FieldCursor { + pub fn set(&mut self, value: &str) -> Result<(), CLIError> { + if value.len() == 0 { + return Err(CLIError::Field(FieldError::Empty)) + } + + let mut first_is_field_sep = false; + let mut char_count: usize = 0; + let mut last_c = FIELD_SEP; + let mut num_conscutive_field_seps = 0; + + let mut field = String::new(); + let mut fields = self.0.clone(); + + let push_field = |fs: &mut Vec<String>, f: &mut String| { + if f.len() > 0 { + fs.push(f.clone()); + f.truncate(0); + } + }; + + for (cid, c) in value.chars().enumerate() { + char_count += 1; + + if c == FIELD_SEP { + if cid == 0 { + first_is_field_sep = true; + } + num_conscutive_field_seps += 1; + if cid > 0 && last_c == FIELD_SEP { + if fields.pop().is_none() { + return Err(CLIError::Field(FieldError::PopOnEmpty(value.to_string()))) + } + } else { + push_field(&mut fields, &mut field); + } + } else { + num_conscutive_field_seps = 0; + if cid == 1 { + if first_is_field_sep { + fields.truncate(0); + } + } + field.push(c); + } + + last_c = c; + } + + push_field(&mut fields, &mut field); + + if char_count == 1 && first_is_field_sep { + fields.truncate(0); + } + if char_count > 1 && num_conscutive_field_seps == 1 { + return Err(CLIError::Field(FieldError::TrailingFieldSep(value.to_string()))) + } + + self.0 = fields; + Ok(()) + } + + pub fn num_fields(&self) -> usize { + self.0.len() + } +} + +pub fn parse_kv_arg<'a>(kv: &'a str, err: &mut InvalidOptionsError, for_hashmap: bool) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string(),for_hashmap)); + match kv.find('=') { + None => { + add_err(); + return (kv, None) + }, + Some(pos) => { + let key = &kv[..pos]; + if kv.len() <= pos + 1 { + add_err(); + return (key, None) + } + (key, Some(&kv[pos+1..])) + } + } +} + +pub fn input_file_from_opts(file_path: &str, err: &mut InvalidOptionsError) -> Option<fs::File> { + match fs::File::open(file_path) { + Ok(f) => Some(f), + Err(io_err) => { + err.issues.push(CLIError::Input(InputError::IOError((file_path.to_string(), io_err)))); + None + } + } +} + +pub fn input_mime_from_opts(mime: &str, err: &mut InvalidOptionsError) -> Option<Mime> { + match mime.parse() { + Ok(m) => Some(m), + Err(_) => { + err.issues.push(CLIError::Input(InputError::Mime(mime.to_string()))); + None + } + } +} + +// May panic if we can't open the file - this is anticipated, we can't currently communicate this +// kind of error: TODO: fix this architecture :) +pub fn writer_from_opts(flag: bool, arg: &str) -> Box<Write> { + if !flag || arg == "-" { + Box::new(stdout()) + } else { + Box::new(fs::OpenOptions::new().create(true).write(true).open(arg).unwrap()) + } +} + + +pub fn arg_from_str<T>(arg: &str, err: &mut InvalidOptionsError, + arg_name: &'static str, + arg_type: &'static 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))) + ); + Default::default() + }, + Ok(v) => v, + } +} + +pub struct JsonTokenStorage { + pub program_name: &'static str, + pub db_dir: String, +} + +impl JsonTokenStorage { + fn path(&self, scope_hash: u64) -> PathBuf { + Path::new(&self.db_dir).join(&format!("{}-token-{}.json", self.program_name, scope_hash)) + } +} + +impl TokenStorage for JsonTokenStorage { + type Error = io::Error; + + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, _: &Vec<&str>, token: Option<Token>) -> Option<io::Error> { + match token { + None => { + match fs::remove_file(self.path(scope_hash)) { + Err(err) => + match err.kind() { + io::ErrorKind::NotFound => None, + _ => Some(err) + }, + Ok(_) => None + } + } + Some(token) => { + let json_token = json::encode(&token).unwrap(); + match fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)) { + Ok(mut f) => { + match f.write(json_token.as_bytes()) { + Ok(_) => None, + Err(io_err) => Some(io_err), + } + }, + Err(io_err) => Some(io_err) + } + } + } + } + + fn get(&self, scope_hash: u64, _: &Vec<&str>) -> Result<Option<Token>, io::Error> { + match fs::File::open(&self.path(scope_hash)) { + Ok(mut f) => { + let mut json_string = String::new(); + match f.read_to_string(&mut json_string) { + Ok(_) => Ok(Some(json::decode::<Token>(&json_string).unwrap())), + Err(io_err) => Err(io_err), + } + }, + Err(io_err) => { + match io_err.kind() { + io::ErrorKind::NotFound => Ok(None), + _ => Err(io_err) + } + } + } + } +} + + +#[derive(Debug)] +pub enum ApplicationSecretError { + DecoderError((String, json::DecoderError)), + FormatError(String), +} + +impl fmt::Display for ApplicationSecretError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + match *self { + ApplicationSecretError::DecoderError((ref path, ref err)) + => writeln!(f, "Could not decode file at '{}' with error: {}", + path, err), + ApplicationSecretError::FormatError(ref path) + => writeln!(f, "'installed' field is unset in secret file at '{}'", + path), + } + } +} + +#[derive(Debug)] +pub enum ConfigurationError { + DirectoryCreationFailed((String, io::Error)), + DirectoryUnset, + HomeExpansionFailed(String), + Secret(ApplicationSecretError), + IOError((String, io::Error)), +} + +impl fmt::Display for ConfigurationError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + match *self { + ConfigurationError::DirectoryCreationFailed((ref dir, ref err)) + => writeln!(f, "Directory '{}' could not be created with error: {}", dir, err), + ConfigurationError::DirectoryUnset + => writeln!(f, "--config-dir was unset or empty"), + ConfigurationError::HomeExpansionFailed(ref dir) + => writeln!(f, "Couldn't find HOME directory of current user, failed to expand '{}'", dir), + ConfigurationError::Secret(ref err) + => writeln!(f, "Secret -> {}", err), + ConfigurationError::IOError((ref path, ref err)) + => writeln!(f, "IO operation failed on path '{}' with error: {}", path, err), + } + } +} + +#[derive(Debug)] +pub enum InputError { + IOError((String, io::Error)), + Mime(String), +} + +impl fmt::Display for InputError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + match *self { + InputError::IOError((ref file_path, ref io_err)) + => writeln!(f, "Failed to open '{}' for reading with error: {}", file_path, io_err), + InputError::Mime(ref mime) + => writeln!(f, "'{}' is not a known mime-type", mime), + } + } +} + +#[derive(Debug)] +pub enum FieldError { + PopOnEmpty(String), + TrailingFieldSep(String), + Unknown(String), + Empty, +} + + +impl fmt::Display for FieldError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + match *self { + FieldError::PopOnEmpty(ref field) + => writeln!(f, "'{}': Cannot move up on empty field cursor", field), + FieldError::TrailingFieldSep(ref field) + => writeln!(f, "'{}': Single field separator may not be last character", field), + FieldError::Unknown(ref field) + => writeln!(f, "Field '{}' does not exist", field), + FieldError::Empty + => writeln!(f, "Field names must not be empty"), + } + } +} + + +#[derive(Debug)] +pub enum CLIError { + Configuration(ConfigurationError), + ParseError((&'static str, &'static str, String, String)), + UnknownParameter(String), + InvalidKeyValueSyntax(String, bool), + Input(InputError), + Field(FieldError), +} + +impl fmt::Display for CLIError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + match *self { + CLIError::Configuration(ref err) => write!(f, "Configuration -> {}", err), + CLIError::Input(ref err) => write!(f, "Input -> {}", err), + CLIError::Field(ref err) => write!(f, "Field -> {}", err), + CLIError::ParseError((arg_name, 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) + => writeln!(f, "Parameter '{}' is unknown.", param_name), + CLIError::InvalidKeyValueSyntax(ref kv, is_hashmap) => { + let hashmap_info = if is_hashmap { "hashmap " } else { "" }; + writeln!(f, "'{}' does not match {}pattern <key>=<value>", kv, hashmap_info) + }, + } + } +} + +#[derive(Debug)] +pub struct InvalidOptionsError { + pub issues: Vec<CLIError>, + pub exit_code: i32, +} + +impl fmt::Display for InvalidOptionsError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + for issue in &self.issues { + try!(issue.fmt(f)); + } + Ok(()) + } +} + +impl InvalidOptionsError { + pub fn single(err: CLIError, exit_code: i32) -> InvalidOptionsError { + InvalidOptionsError { + issues: vec![err], + exit_code: exit_code, + } + } + + pub fn new() -> InvalidOptionsError { + InvalidOptionsError { + issues: Vec::new(), + exit_code: 1, + } + } +} + +pub fn assure_config_dir_exists(dir: &str) -> Result<String, CLIError> { + let trdir = dir.trim(); + if trdir.len() == 0 { + return Err(CLIError::Configuration(ConfigurationError::DirectoryUnset)) + } + + let expanded_config_dir = + if trdir.as_bytes()[0] == b'~' { + match env::var("HOME").ok().or(env::var("UserProfile").ok()) { + None => return Err(CLIError::Configuration(ConfigurationError::HomeExpansionFailed(trdir.to_string()))), + Some(mut user) => { + user.push_str(&trdir[1..]); + user + } + } + } else { + trdir.to_string() + }; + + if let Err(err) = fs::create_dir(&expanded_config_dir) { + if err.kind() != io::ErrorKind::AlreadyExists { + return Err(CLIError::Configuration( + ConfigurationError::DirectoryCreationFailed((expanded_config_dir, err)))) + } + } + + Ok(expanded_config_dir) +} + +pub fn application_secret_from_directory(dir: &str, + secret_basename: &str, + json_app_secret: &str) + -> Result<ApplicationSecret, CLIError> { + let secret_path = Path::new(dir).join(secret_basename); + let secret_str = || secret_path.as_path().to_str().unwrap().to_string(); + let secret_io_error = |io_err: io::Error| { + Err(CLIError::Configuration(ConfigurationError::IOError( + (secret_str(), io_err) + ))) + }; + + for _ in 0..2 { + match fs::File::open(&secret_path) { + Err(mut err) => { + if err.kind() == io::ErrorKind::NotFound { + // Write our built-in one - user may adjust the written file at will + + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_app_secret.as_bytes()) { + Err(io_err) => io_err, + Ok(_) => continue, + } + } + }; + // fall through to IO error handling + } + return secret_io_error(err) + }, + Ok(mut f) => { + let mut json_encoded_secret = String::new(); + if let Err(io_err) = f.read_to_string(&mut json_encoded_secret) { + return secret_io_error(io_err) + } + match json::decode::<ConsoleApplicationSecret>(&json_encoded_secret) { + Err(json_decode_error) => return Err(CLIError::Configuration( + ConfigurationError::Secret(ApplicationSecretError::DecoderError( + (secret_str(), json_decode_error) + )))), + Ok(console_secret) => match console_secret.installed { + Some(secret) => return Ok(secret), + None => return Err( + CLIError::Configuration( + ConfigurationError::Secret( + ApplicationSecretError::FormatError(secret_str()) + ))) + }, + } + } + } + } + unreachable!(); +} \ No newline at end of file diff --git a/gen/webfonts1-cli/src/main.rs b/gen/webfonts1-cli/src/main.rs new file mode 100644 index 0000000000..6b9e60aeea --- /dev/null +++ b/gen/webfonts1-cli/src/main.rs @@ -0,0 +1,195 @@ +// DO NOT EDIT ! +// This file was generated automatically from 'src/mako/cli/main.rs.mako' +// DO NOT EDIT ! +#![feature(plugin, exit_status)] +#![plugin(docopt_macros)] +#![allow(unused_variables, unused_imports, dead_code, unused_mut)] + +extern crate docopt; +extern crate yup_oauth2 as oauth2; +extern crate yup_hyper_mock as mock; +extern crate rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_webfonts1 as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + webfonts1 [options] webfonts list [-p <v>]... [-o <out>] + webfonts1 --help + +All documentation details can be found TODO: <URL to github.io docs here, see #51> + +Configuration: + --config-dir <folder> + 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] + --debug + Output all server communication to standard error. `tx` and `rx` are placed into + the same stream. + --debug-auth + Output all communication related to authentication to standard error. `tx` and `rx` are placed into + the same stream. +"); + +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}; + +use std::default::Default; +use std::str::FromStr; + +use oauth2::{Authenticator, DefaultAuthenticatorDelegate}; +use rustc_serialize::json; + +struct Engine { + opt: Options, + hub: api::Webfonts<hyper::Client, Authenticator<DefaultAuthenticatorDelegate, JsonTokenStorage, hyper::Client>>, +} + + +impl Engine { + fn _webfonts_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.webfonts().list(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err, false); + match key { + "sort" => { + call = call.sort(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option<api::Error>, Option<InvalidOptionsError>) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option<api::Error>; + let mut err_opt: Option<InvalidOptionsError> = None; + + if self.opt.cmd_webfonts { + if self.opt.cmd_list { + call_result = self._webfonts_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else { + unreachable!(); + } + + if dry_run { + if err.issues.len() > 0 { + err_opt = Some(err); + } + } + (call_result, err_opt) + } + + // Please note that this call will fail if any part of the opt can't be handled + fn new(opt: Options) -> Result<Engine, InvalidOptionsError> { + let (config_dir, secret) = { + let config_dir = match cmn::assure_config_dir_exists(&opt.flag_config_dir) { + Err(e) => return Err(InvalidOptionsError::single(e, 3)), + Ok(p) => p, + }; + + match cmn::application_secret_from_directory(&config_dir, "webfonts1-secret.json", + "{\"installed\":{\"auth_uri\":\"https://accounts.google.com/o/oauth2/auth\",\"client_secret\":\"hCsslbCUyfehWMmbkG8vTYxG\",\"token_uri\":\"https://accounts.google.com/o/oauth2/token\",\"client_email\":\"\",\"redirect_uris\":[\"urn:ietf:wg:oauth:2.0:oob\",\"oob\"],\"client_x509_cert_url\":\"\",\"client_id\":\"620010449518-9ngf7o4dhs0dka470npqvor6dc5lqb9b.apps.googleusercontent.com\",\"auth_provider_x509_cert_url\":\"https://www.googleapis.com/oauth2/v1/certs\"}}") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new( &secret, DefaultAuthenticatorDelegate, + if opt.flag_debug_auth { + hyper::Client::with_connector(mock::TeeConnector { + connector: hyper::net::HttpConnector(None) + }) + } else { + hyper::Client::new() + }, + JsonTokenStorage { + program_name: "webfonts1", + db_dir: config_dir.clone(), + }, None); + + let client = + if opt.flag_debug { + hyper::Client::with_connector(mock::TeeConnector { + connector: hyper::net::HttpConnector(None) + }) + } else { + hyper::Client::new() + }; + let engine = Engine { + opt: opt, + hub: api::Webfonts::new(client, auth), + }; + + match engine._doit(true) { + (_, Some(err)) => Err(err), + _ => Ok(engine), + } + } + + // Execute the call with all the bells and whistles, informing the caller only if there was an error. + // The absense of one indicates success. + fn doit(&self) -> Option<api::Error> { + self._doit(false).0 + } +} + +fn main() { + let opts: Options = Options::docopt().decode().unwrap_or_else(|e| e.exit()); + match Engine::new(opts) { + Err(err) => { + writeln!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + writeln!(io::stderr(), "{:?}", err).ok(); + writeln!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/src/mako/api/lib.rs.mako b/src/mako/api/lib.rs.mako index 07c896649d..738860cfa3 100644 --- a/src/mako/api/lib.rs.mako +++ b/src/mako/api/lib.rs.mako @@ -51,7 +51,7 @@ use std::io; use std::fs; use std::thread::sleep_ms; -pub use cmn::{MultiPartReader, ToParts, MethodInfo, Result, Error, CallBuilder, Hub, ReadSeek, Part, ResponseResult, RequestValue, NestedType, Delegate, DefaultDelegate, MethodsBuilder, Resource, JsonServerError}; +pub use cmn::{MultiPartReader, ToParts, MethodInfo, Result, Error, CallBuilder, Hub, ReadSeek, Part, ResponseResult, RequestValue, NestedType, Delegate, DefaultDelegate, MethodsBuilder, Resource, ErrorResponse}; // ############## diff --git a/src/mako/api/lib/mbuild.mako b/src/mako/api/lib/mbuild.mako index 3e830a5d19..6d0fc43a95 100644 --- a/src/mako/api/lib/mbuild.mako +++ b/src/mako/api/lib/mbuild.mako @@ -368,14 +368,15 @@ match result { Err(e) => match e { // The Error enum provides details about what exactly happened. // You can also just use its `Debug`, `Display` or `Error` traits - Error::HttpError(_) + Error::HttpError(_) |Error::MissingAPIKey |Error::MissingToken |Error::Cancelled |Error::UploadSizeLimitExceeded(_, _) |Error::Failure(_) + |Error::BadRequest(_) |Error::FieldClash(_) - |Error::JsonDecodeError(_) => println!("{}", e), + |Error::JsonDecodeError(_, _) => println!("{}", e), }, Ok(res) => println!("Success: {:?}", res), } @@ -770,12 +771,17 @@ else { if !res.status.is_success() { let mut json_err = String::new(); res.read_to_string(&mut json_err).unwrap(); - if let oauth2::Retry::After(d) = dlg.http_failure(&res, json::from_str(&json_err).ok()) { + if let oauth2::Retry::After(d) = dlg.http_failure(&res, + json::from_str(&json_err).ok(), + json::from_str(&json_err).ok()) { sleep_ms(d.num_milliseconds() as u32); continue; } ${delegate_finish}(false); - return Err(Error::Failure(res)) + return match json::from_str::<ErrorResponse>(&json_err){ + Err(_) => Err(Error::Failure(res)), + Ok(serr) => Err(Error::BadRequest(serr)) + } } % if resumable_media_param: if protocol == "${resumable_media_param.protocol}" { @@ -836,7 +842,7 @@ if enable_resource_parsing \ Ok(decoded) => (res, decoded), Err(err) => { dlg.response_json_decode_error(&json_response, &err); - return Err(Error::JsonDecodeError(err)); + return Err(Error::JsonDecodeError(json_response, err)); } } }\ diff --git a/src/mako/cli/main.rs.mako b/src/mako/cli/main.rs.mako index 0e6c0dbd6f..549e531fe3 100644 --- a/src/mako/cli/main.rs.mako +++ b/src/mako/cli/main.rs.mako @@ -32,6 +32,7 @@ ${engine.new(c)}\ fn main() { let opts: Options = Options::docopt().decode().unwrap_or_else(|e| e.exit()); + let debug = opts.flag_debug; match Engine::new(opts) { Err(err) => { writeln!(io::stderr(), "{}", err).ok(); @@ -39,8 +40,11 @@ fn main() { }, Ok(engine) => { if let Some(err) = engine.doit() { - writeln!(io::stderr(), "{:?}", err).ok(); - writeln!(io::stderr(), "{}", err).ok(); + if debug { + writeln!(io::stderr(), "{:?}", err).ok(); + } else { + writeln!(io::stderr(), "{}", err).ok(); + } env::set_exit_status(1); } } diff --git a/src/rust/api/cmn.rs b/src/rust/api/cmn.rs index 3cdad1301a..5b7eb4d484 100644 --- a/src/rust/api/cmn.rs +++ b/src/rust/api/cmn.rs @@ -58,7 +58,6 @@ pub trait ToParts { fn to_parts(&self) -> String; } - /// A utility type which can decode a server response that indicates error #[derive(Deserialize)] pub struct JsonServerError { @@ -66,6 +65,30 @@ pub struct JsonServerError { pub error_description: Option<String> } +/// A utility to represent detailed errors we might see in case there are BadRequests. +/// The latter happen if the sent parameters or request structures are unsound +#[derive(Deserialize, Serialize, Debug)] +pub struct ErrorResponse { + error: ServerError, +} + +#[derive(Deserialize, Serialize, Debug)] +pub struct ServerError { + errors: Vec<ServerMessage>, + code: u16, + message: String, +} + +#[derive(Deserialize, Serialize, Debug)] +pub struct ServerMessage { + domain: String, + reason: String, + message: String, + #[serde(rename="locationType")] + location_type: Option<String>, + location: Option<String> +} + #[derive(Copy, Clone)] pub struct DummyNetworkStream; @@ -173,7 +196,7 @@ pub trait Delegate { /// /// If you choose to retry after a duration, the duration should be chosen using the /// [exponential backoff algorithm](http://en.wikipedia.org/wiki/Exponential_backoff). - fn http_failure(&mut self, _: &hyper::client::Response, Option<JsonServerError>) -> Retry { + fn http_failure(&mut self, _: &hyper::client::Response, Option<JsonServerError>, _: Option<ServerError>) -> Retry { Retry::Abort } @@ -228,6 +251,10 @@ pub enum Error { /// even though the maximum upload size is what is stored in field `.1`. UploadSizeLimitExceeded(u64, u64), + /// Represents information about a request that was not understood by the server. + /// Details are included. + BadRequest(ErrorResponse), + /// We needed an API key for authentication, but didn't obtain one. /// Neither through the authenticator, nor through the Delegate. MissingAPIKey, @@ -243,7 +270,7 @@ pub enum Error { /// Shows that we failed to decode the server response. /// This can happen if the protocol changes in conjunction with strict json decoding. - JsonDecodeError(serde::json::Error), + JsonDecodeError(String, serde::json::Error), /// Indicates an HTTP repsonse with a non-success status code Failure(hyper::client::Response), @@ -261,13 +288,16 @@ impl Display for Error { writeln!(f, "The application's API key was not found in the configuration").ok(); writeln!(f, "It is used as there are no Scopes defined for this method.") }, + Error::BadRequest(ref err) + => writeln!(f, "Bad Requst ({}): {}", err.error.code, err.error.message), Error::MissingToken(ref err) => writeln!(f, "Token retrieval failed with error: {}", err), Error::Cancelled => writeln!(f, "Operation cancelled by delegate"), Error::FieldClash(field) => writeln!(f, "The custom parameter '{}' is already provided natively by the CallBuilder.", field), - Error::JsonDecodeError(ref err) => err.fmt(f), + Error::JsonDecodeError(ref json_str, ref err) + => writeln!(f, "{}: {}", err, json_str), Error::Failure(ref response) => writeln!(f, "Http status indicates failure: {:?}", response), } @@ -278,7 +308,7 @@ impl error::Error for Error { fn description(&self) -> &str { match *self { Error::HttpError(ref err) => err.description(), - Error::JsonDecodeError(ref err) => err.description(), + Error::JsonDecodeError(_, ref err) => err.description(), _ => "NO DESCRIPTION POSSIBLE - use `Display.fmt()` instead" } } @@ -286,7 +316,7 @@ impl error::Error for Error { fn cause(&self) -> Option<&error::Error> { match *self { Error::HttpError(ref err) => err.cause(), - Error::JsonDecodeError(ref err) => err.cause(), + Error::JsonDecodeError(_, ref err) => err.cause(), _ => None } } @@ -557,7 +587,7 @@ impl<'a, A> ResumableUploadHelper<'a, A> let h: &RangeResponseHeader = match headers.get() { Some(hh) if r.status == StatusCode::PermanentRedirect => hh, None|Some(_) => { - if let Retry::After(d) = self.delegate.http_failure(&r, None) { + if let Retry::After(d) = self.delegate.http_failure(&r, None, None) { sleep_ms(d.num_milliseconds() as u32); continue; } @@ -624,7 +654,9 @@ impl<'a, A> ResumableUploadHelper<'a, A> if !res.status.is_success() { let mut json_err = String::new(); res.read_to_string(&mut json_err).unwrap(); - if let Retry::After(d) = self.delegate.http_failure(&res, serde::json::from_str(&json_err).ok()) { + if let Retry::After(d) = self.delegate.http_failure(&res, + serde::json::from_str(&json_err).ok(), + serde::json::from_str(&json_err).ok()) { sleep_ms(d.num_milliseconds() as u32); continue; }