chore(code): updated to latest state

This commit is contained in:
Sebastian Thiel
2016-01-30 14:08:25 +01:00
parent 5cba22f0c6
commit 75076acf16
1164 changed files with 241839 additions and 123033 deletions

View File

@@ -20,7 +20,7 @@ use clap::{App, SubCommand, Arg};
mod cmn;
use cmn::{InvalidOptionsError, CLIError, JsonTokenStorage, arg_from_str, writer_from_opts, parse_kv_arg,
use cmn::{InvalidOptionsError, CLIError, JsonTokenStorage, arg_from_str, writer_from_opts, parse_kv_arg,
input_file_from_opts, input_mime_from_opts, FieldCursor, FieldError, CallType, UploadProtocol,
calltype_from_str, remove_json_null_values, ComplexType, JsonType, JsonTypeInfo};
@@ -36,19 +36,19 @@ enum DoitError {
ApiError(api::Error),
}
struct Engine<'n, 'a> {
opt: ArgMatches<'n, 'a>,
struct Engine<'n> {
opt: ArgMatches<'n>,
hub: api::SiteVerification<hyper::Client, Authenticator<DefaultAuthenticatorDelegate, JsonTokenStorage, hyper::Client>>,
gp: Vec<&'static str>,
gpm: Vec<(&'static str, &'static str)>,
}
impl<'n, 'a> Engine<'n, 'a> {
fn _web_resource_delete(&self, opt: &ArgMatches<'n, 'a>, dry_run: bool, err: &mut InvalidOptionsError)
impl<'n> Engine<'n> {
fn _web_resource_delete(&self, opt: &ArgMatches<'n>, dry_run: bool, err: &mut InvalidOptionsError)
-> Result<(), DoitError> {
let mut call = self.hub.web_resource().delete(opt.value_of("id").unwrap_or(""));
for parg in opt.values_of("v").unwrap_or(Vec::new()).iter() {
for parg in opt.values_of("v").map(|i|i.collect()).unwrap_or(Vec::new()).iter() {
let (key, value) = parse_kv_arg(&*parg, err, false);
match key {
_ => {
@@ -61,7 +61,7 @@ impl<'n, 'a> Engine<'n, 'a> {
}
}
if !found {
err.issues.push(CLIError::UnknownParameter(key.to_string(),
err.issues.push(CLIError::UnknownParameter(key.to_string(),
{let mut v = Vec::new();
v.extend(self.gp.iter().map(|v|*v));
v } ));
@@ -74,7 +74,7 @@ impl<'n, 'a> Engine<'n, 'a> {
Ok(())
} else {
assert!(err.issues.len() == 0);
for scope in self.opt.values_of("url").unwrap_or(Vec::new()).iter() {
for scope in self.opt.values_of("url").map(|i|i.collect()).unwrap_or(Vec::new()).iter() {
call = call.add_scope(scope);
}
match match protocol {
@@ -89,10 +89,10 @@ impl<'n, 'a> Engine<'n, 'a> {
}
}
fn _web_resource_get(&self, opt: &ArgMatches<'n, 'a>, dry_run: bool, err: &mut InvalidOptionsError)
fn _web_resource_get(&self, opt: &ArgMatches<'n>, dry_run: bool, err: &mut InvalidOptionsError)
-> Result<(), DoitError> {
let mut call = self.hub.web_resource().get(opt.value_of("id").unwrap_or(""));
for parg in opt.values_of("v").unwrap_or(Vec::new()).iter() {
for parg in opt.values_of("v").map(|i|i.collect()).unwrap_or(Vec::new()).iter() {
let (key, value) = parse_kv_arg(&*parg, err, false);
match key {
_ => {
@@ -105,7 +105,7 @@ impl<'n, 'a> Engine<'n, 'a> {
}
}
if !found {
err.issues.push(CLIError::UnknownParameter(key.to_string(),
err.issues.push(CLIError::UnknownParameter(key.to_string(),
{let mut v = Vec::new();
v.extend(self.gp.iter().map(|v|*v));
v } ));
@@ -118,7 +118,7 @@ impl<'n, 'a> Engine<'n, 'a> {
Ok(())
} else {
assert!(err.issues.len() == 0);
for scope in self.opt.values_of("url").unwrap_or(Vec::new()).iter() {
for scope in self.opt.values_of("url").map(|i|i.collect()).unwrap_or(Vec::new()).iter() {
call = call.add_scope(scope);
}
let mut ostream = match writer_from_opts(opt.value_of("out")) {
@@ -141,13 +141,13 @@ impl<'n, 'a> Engine<'n, 'a> {
}
}
fn _web_resource_get_token(&self, opt: &ArgMatches<'n, 'a>, dry_run: bool, err: &mut InvalidOptionsError)
fn _web_resource_get_token(&self, opt: &ArgMatches<'n>, dry_run: bool, err: &mut InvalidOptionsError)
-> Result<(), DoitError> {
let mut field_cursor = FieldCursor::default();
let mut object = json::value::Value::Object(Default::default());
for kvarg in opt.values_of("kv").unwrap_or(Vec::new()).iter() {
for kvarg in opt.values_of("kv").map(|i|i.collect()).unwrap_or(Vec::new()).iter() {
let last_errc = err.issues.len();
let (key, value) = parse_kv_arg(&*kvarg, err, false);
let mut temp_cursor = field_cursor.clone();
@@ -161,8 +161,8 @@ impl<'n, 'a> Engine<'n, 'a> {
}
continue;
}
let type_info: Option<(&'static str, JsonTypeInfo)> =
let type_info: Option<(&'static str, JsonTypeInfo)> =
match &temp_cursor.to_string()[..] {
"verification-method" => Some(("verificationMethod", JsonTypeInfo { jtype: JsonType::String, ctype: ComplexType::Pod })),
"site.identifier" => Some(("site.identifier", JsonTypeInfo { jtype: JsonType::String, ctype: ComplexType::Pod })),
@@ -179,7 +179,7 @@ impl<'n, 'a> Engine<'n, 'a> {
}
let mut request: api::SiteVerificationWebResourceGettokenRequest = json::value::from_value(object).unwrap();
let mut call = self.hub.web_resource().get_token(request);
for parg in opt.values_of("v").unwrap_or(Vec::new()).iter() {
for parg in opt.values_of("v").map(|i|i.collect()).unwrap_or(Vec::new()).iter() {
let (key, value) = parse_kv_arg(&*parg, err, false);
match key {
_ => {
@@ -192,7 +192,7 @@ impl<'n, 'a> Engine<'n, 'a> {
}
}
if !found {
err.issues.push(CLIError::UnknownParameter(key.to_string(),
err.issues.push(CLIError::UnknownParameter(key.to_string(),
{let mut v = Vec::new();
v.extend(self.gp.iter().map(|v|*v));
v } ));
@@ -205,7 +205,7 @@ impl<'n, 'a> Engine<'n, 'a> {
Ok(())
} else {
assert!(err.issues.len() == 0);
for scope in self.opt.values_of("url").unwrap_or(Vec::new()).iter() {
for scope in self.opt.values_of("url").map(|i|i.collect()).unwrap_or(Vec::new()).iter() {
call = call.add_scope(scope);
}
let mut ostream = match writer_from_opts(opt.value_of("out")) {
@@ -228,13 +228,13 @@ impl<'n, 'a> Engine<'n, 'a> {
}
}
fn _web_resource_insert(&self, opt: &ArgMatches<'n, 'a>, dry_run: bool, err: &mut InvalidOptionsError)
fn _web_resource_insert(&self, opt: &ArgMatches<'n>, dry_run: bool, err: &mut InvalidOptionsError)
-> Result<(), DoitError> {
let mut field_cursor = FieldCursor::default();
let mut object = json::value::Value::Object(Default::default());
for kvarg in opt.values_of("kv").unwrap_or(Vec::new()).iter() {
for kvarg in opt.values_of("kv").map(|i|i.collect()).unwrap_or(Vec::new()).iter() {
let last_errc = err.issues.len();
let (key, value) = parse_kv_arg(&*kvarg, err, false);
let mut temp_cursor = field_cursor.clone();
@@ -248,8 +248,8 @@ impl<'n, 'a> Engine<'n, 'a> {
}
continue;
}
let type_info: Option<(&'static str, JsonTypeInfo)> =
let type_info: Option<(&'static str, JsonTypeInfo)> =
match &temp_cursor.to_string()[..] {
"owners" => Some(("owners", JsonTypeInfo { jtype: JsonType::String, ctype: ComplexType::Vec })),
"id" => Some(("id", JsonTypeInfo { jtype: JsonType::String, ctype: ComplexType::Pod })),
@@ -267,7 +267,7 @@ impl<'n, 'a> Engine<'n, 'a> {
}
let mut request: api::SiteVerificationWebResourceResource = json::value::from_value(object).unwrap();
let mut call = self.hub.web_resource().insert(request, opt.value_of("verification-method").unwrap_or(""));
for parg in opt.values_of("v").unwrap_or(Vec::new()).iter() {
for parg in opt.values_of("v").map(|i|i.collect()).unwrap_or(Vec::new()).iter() {
let (key, value) = parse_kv_arg(&*parg, err, false);
match key {
_ => {
@@ -280,7 +280,7 @@ impl<'n, 'a> Engine<'n, 'a> {
}
}
if !found {
err.issues.push(CLIError::UnknownParameter(key.to_string(),
err.issues.push(CLIError::UnknownParameter(key.to_string(),
{let mut v = Vec::new();
v.extend(self.gp.iter().map(|v|*v));
v } ));
@@ -293,7 +293,7 @@ impl<'n, 'a> Engine<'n, 'a> {
Ok(())
} else {
assert!(err.issues.len() == 0);
for scope in self.opt.values_of("url").unwrap_or(Vec::new()).iter() {
for scope in self.opt.values_of("url").map(|i|i.collect()).unwrap_or(Vec::new()).iter() {
call = call.add_scope(scope);
}
let mut ostream = match writer_from_opts(opt.value_of("out")) {
@@ -316,10 +316,10 @@ impl<'n, 'a> Engine<'n, 'a> {
}
}
fn _web_resource_list(&self, opt: &ArgMatches<'n, 'a>, dry_run: bool, err: &mut InvalidOptionsError)
fn _web_resource_list(&self, opt: &ArgMatches<'n>, dry_run: bool, err: &mut InvalidOptionsError)
-> Result<(), DoitError> {
let mut call = self.hub.web_resource().list();
for parg in opt.values_of("v").unwrap_or(Vec::new()).iter() {
for parg in opt.values_of("v").map(|i|i.collect()).unwrap_or(Vec::new()).iter() {
let (key, value) = parse_kv_arg(&*parg, err, false);
match key {
_ => {
@@ -332,7 +332,7 @@ impl<'n, 'a> Engine<'n, 'a> {
}
}
if !found {
err.issues.push(CLIError::UnknownParameter(key.to_string(),
err.issues.push(CLIError::UnknownParameter(key.to_string(),
{let mut v = Vec::new();
v.extend(self.gp.iter().map(|v|*v));
v } ));
@@ -345,7 +345,7 @@ impl<'n, 'a> Engine<'n, 'a> {
Ok(())
} else {
assert!(err.issues.len() == 0);
for scope in self.opt.values_of("url").unwrap_or(Vec::new()).iter() {
for scope in self.opt.values_of("url").map(|i|i.collect()).unwrap_or(Vec::new()).iter() {
call = call.add_scope(scope);
}
let mut ostream = match writer_from_opts(opt.value_of("out")) {
@@ -368,13 +368,13 @@ impl<'n, 'a> Engine<'n, 'a> {
}
}
fn _web_resource_patch(&self, opt: &ArgMatches<'n, 'a>, dry_run: bool, err: &mut InvalidOptionsError)
fn _web_resource_patch(&self, opt: &ArgMatches<'n>, dry_run: bool, err: &mut InvalidOptionsError)
-> Result<(), DoitError> {
let mut field_cursor = FieldCursor::default();
let mut object = json::value::Value::Object(Default::default());
for kvarg in opt.values_of("kv").unwrap_or(Vec::new()).iter() {
for kvarg in opt.values_of("kv").map(|i|i.collect()).unwrap_or(Vec::new()).iter() {
let last_errc = err.issues.len();
let (key, value) = parse_kv_arg(&*kvarg, err, false);
let mut temp_cursor = field_cursor.clone();
@@ -388,8 +388,8 @@ impl<'n, 'a> Engine<'n, 'a> {
}
continue;
}
let type_info: Option<(&'static str, JsonTypeInfo)> =
let type_info: Option<(&'static str, JsonTypeInfo)> =
match &temp_cursor.to_string()[..] {
"owners" => Some(("owners", JsonTypeInfo { jtype: JsonType::String, ctype: ComplexType::Vec })),
"id" => Some(("id", JsonTypeInfo { jtype: JsonType::String, ctype: ComplexType::Pod })),
@@ -407,7 +407,7 @@ impl<'n, 'a> Engine<'n, 'a> {
}
let mut request: api::SiteVerificationWebResourceResource = json::value::from_value(object).unwrap();
let mut call = self.hub.web_resource().patch(request, opt.value_of("id").unwrap_or(""));
for parg in opt.values_of("v").unwrap_or(Vec::new()).iter() {
for parg in opt.values_of("v").map(|i|i.collect()).unwrap_or(Vec::new()).iter() {
let (key, value) = parse_kv_arg(&*parg, err, false);
match key {
_ => {
@@ -420,7 +420,7 @@ impl<'n, 'a> Engine<'n, 'a> {
}
}
if !found {
err.issues.push(CLIError::UnknownParameter(key.to_string(),
err.issues.push(CLIError::UnknownParameter(key.to_string(),
{let mut v = Vec::new();
v.extend(self.gp.iter().map(|v|*v));
v } ));
@@ -433,7 +433,7 @@ impl<'n, 'a> Engine<'n, 'a> {
Ok(())
} else {
assert!(err.issues.len() == 0);
for scope in self.opt.values_of("url").unwrap_or(Vec::new()).iter() {
for scope in self.opt.values_of("url").map(|i|i.collect()).unwrap_or(Vec::new()).iter() {
call = call.add_scope(scope);
}
let mut ostream = match writer_from_opts(opt.value_of("out")) {
@@ -456,13 +456,13 @@ impl<'n, 'a> Engine<'n, 'a> {
}
}
fn _web_resource_update(&self, opt: &ArgMatches<'n, 'a>, dry_run: bool, err: &mut InvalidOptionsError)
fn _web_resource_update(&self, opt: &ArgMatches<'n>, dry_run: bool, err: &mut InvalidOptionsError)
-> Result<(), DoitError> {
let mut field_cursor = FieldCursor::default();
let mut object = json::value::Value::Object(Default::default());
for kvarg in opt.values_of("kv").unwrap_or(Vec::new()).iter() {
for kvarg in opt.values_of("kv").map(|i|i.collect()).unwrap_or(Vec::new()).iter() {
let last_errc = err.issues.len();
let (key, value) = parse_kv_arg(&*kvarg, err, false);
let mut temp_cursor = field_cursor.clone();
@@ -476,8 +476,8 @@ impl<'n, 'a> Engine<'n, 'a> {
}
continue;
}
let type_info: Option<(&'static str, JsonTypeInfo)> =
let type_info: Option<(&'static str, JsonTypeInfo)> =
match &temp_cursor.to_string()[..] {
"owners" => Some(("owners", JsonTypeInfo { jtype: JsonType::String, ctype: ComplexType::Vec })),
"id" => Some(("id", JsonTypeInfo { jtype: JsonType::String, ctype: ComplexType::Pod })),
@@ -495,7 +495,7 @@ impl<'n, 'a> Engine<'n, 'a> {
}
let mut request: api::SiteVerificationWebResourceResource = json::value::from_value(object).unwrap();
let mut call = self.hub.web_resource().update(request, opt.value_of("id").unwrap_or(""));
for parg in opt.values_of("v").unwrap_or(Vec::new()).iter() {
for parg in opt.values_of("v").map(|i|i.collect()).unwrap_or(Vec::new()).iter() {
let (key, value) = parse_kv_arg(&*parg, err, false);
match key {
_ => {
@@ -508,7 +508,7 @@ impl<'n, 'a> Engine<'n, 'a> {
}
}
if !found {
err.issues.push(CLIError::UnknownParameter(key.to_string(),
err.issues.push(CLIError::UnknownParameter(key.to_string(),
{let mut v = Vec::new();
v.extend(self.gp.iter().map(|v|*v));
v } ));
@@ -521,7 +521,7 @@ impl<'n, 'a> Engine<'n, 'a> {
Ok(())
} else {
assert!(err.issues.len() == 0);
for scope in self.opt.values_of("url").unwrap_or(Vec::new()).iter() {
for scope in self.opt.values_of("url").map(|i|i.collect()).unwrap_or(Vec::new()).iter() {
call = call.add_scope(scope);
}
let mut ostream = match writer_from_opts(opt.value_of("out")) {
@@ -595,14 +595,14 @@ impl<'n, 'a> Engine<'n, 'a> {
}
// Please note that this call will fail if any part of the opt can't be handled
fn new(opt: ArgMatches<'a, 'n>) -> Result<Engine<'a, 'n>, InvalidOptionsError> {
fn new(opt: ArgMatches<'n>) -> Result<Engine<'n>, InvalidOptionsError> {
let (config_dir, secret) = {
let config_dir = match cmn::assure_config_dir_exists(opt.value_of("folder").unwrap_or("~/.google-service-cli")) {
Err(e) => return Err(InvalidOptionsError::single(e, 3)),
Ok(p) => p,
};
match cmn::application_secret_from_directory(&config_dir, "siteverification1-secret.json",
match cmn::application_secret_from_directory(&config_dir, "siteverification1-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))
@@ -622,7 +622,7 @@ impl<'n, 'a> Engine<'n, 'a> {
db_dir: config_dir.clone(),
}, None);
let client =
let client =
if opt.is_present("debug") {
hyper::Client::with_connector(mock::TeeConnector {
connector: hyper::net::HttpsConnector::<hyper::net::Openssl>::default()
@@ -661,7 +661,7 @@ fn main() {
let mut exit_status = 0i32;
let arg_data = [
("web-resource", "methods: 'delete', 'get', 'get-token', 'insert', 'list', 'patch' and 'update'", vec![
("delete",
("delete",
Some(r##"Relinquish ownership of a website or domain."##),
"Details at http://byron.github.io/google-apis-rs/google_siteverification1_cli/web-resource_delete",
vec![
@@ -677,7 +677,7 @@ fn main() {
Some(false),
Some(true)),
]),
("get",
("get",
Some(r##"Get the most current data for a website or domain."##),
"Details at http://byron.github.io/google-apis-rs/google_siteverification1_cli/web-resource_get",
vec![
@@ -699,7 +699,7 @@ fn main() {
Some(false),
Some(false)),
]),
("get-token",
("get-token",
Some(r##"Get a verification token for placing on a website or domain."##),
"Details at http://byron.github.io/google-apis-rs/google_siteverification1_cli/web-resource_get-token",
vec![
@@ -721,7 +721,7 @@ fn main() {
Some(false),
Some(false)),
]),
("insert",
("insert",
Some(r##"Attempt verification of a website or domain."##),
"Details at http://byron.github.io/google-apis-rs/google_siteverification1_cli/web-resource_insert",
vec![
@@ -749,7 +749,7 @@ fn main() {
Some(false),
Some(false)),
]),
("list",
("list",
Some(r##"Get the list of your verified websites and domains."##),
"Details at http://byron.github.io/google-apis-rs/google_siteverification1_cli/web-resource_list",
vec![
@@ -765,7 +765,7 @@ fn main() {
Some(false),
Some(false)),
]),
("patch",
("patch",
Some(r##"Modify the list of owners for your website or domain. This method supports patch semantics."##),
"Details at http://byron.github.io/google-apis-rs/google_siteverification1_cli/web-resource_patch",
vec![
@@ -793,7 +793,7 @@ fn main() {
Some(false),
Some(false)),
]),
("update",
("update",
Some(r##"Modify the list of owners for your website or domain."##),
"Details at http://byron.github.io/google-apis-rs/google_siteverification1_cli/web-resource_update",
vec![
@@ -827,7 +827,7 @@ fn main() {
let mut app = App::new("siteverification1")
.author("Sebastian Thiel <byronimo@gmail.com>")
.version("0.3.2+20151007")
.version("0.3.3+20151007")
.about("Lets you programatically verify ownership of websites or domains with Google.")
.after_help("All documentation details can be found at http://byron.github.io/google-apis-rs/google_siteverification1_cli")
.arg(Arg::with_name("url")
@@ -851,7 +851,7 @@ fn main() {
.multiple(false)
.takes_value(false));
for &(main_command_name, ref about, ref subcommands) in arg_data.iter() {
for &(main_command_name, about, ref subcommands) in arg_data.iter() {
let mut mcmd = SubCommand::with_name(main_command_name).about(about);
for &(sub_command_name, ref desc, url_info, ref args) in subcommands {
@@ -862,7 +862,7 @@ fn main() {
scmd = scmd.after_help(url_info);
for &(ref arg_name, ref flag, ref desc, ref required, ref multi) in args {
let arg_name_str =
let arg_name_str =
match (arg_name, flag) {
(&Some(an), _ ) => an,
(_ , &Some(f)) => f,