|
|
|
|
@@ -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::Resourceviews<hyper::Client, Authenticator<DefaultAuthenticatorDelegate, JsonTokenStorage, hyper::Client>>,
|
|
|
|
|
gp: Vec<&'static str>,
|
|
|
|
|
gpm: Vec<(&'static str, &'static str)>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl<'n, 'a> Engine<'n, 'a> {
|
|
|
|
|
fn _zone_operations_get(&self, opt: &ArgMatches<'n, 'a>, dry_run: bool, err: &mut InvalidOptionsError)
|
|
|
|
|
impl<'n> Engine<'n> {
|
|
|
|
|
fn _zone_operations_get(&self, opt: &ArgMatches<'n>, dry_run: bool, err: &mut InvalidOptionsError)
|
|
|
|
|
-> Result<(), DoitError> {
|
|
|
|
|
let mut call = self.hub.zone_operations().get(opt.value_of("project").unwrap_or(""), opt.value_of("zone").unwrap_or(""), opt.value_of("operation").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);
|
|
|
|
|
}
|
|
|
|
|
let mut ostream = match writer_from_opts(opt.value_of("out")) {
|
|
|
|
|
@@ -97,10 +97,10 @@ impl<'n, 'a> Engine<'n, 'a> {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn _zone_operations_list(&self, opt: &ArgMatches<'n, 'a>, dry_run: bool, err: &mut InvalidOptionsError)
|
|
|
|
|
fn _zone_operations_list(&self, opt: &ArgMatches<'n>, dry_run: bool, err: &mut InvalidOptionsError)
|
|
|
|
|
-> Result<(), DoitError> {
|
|
|
|
|
let mut call = self.hub.zone_operations().list(opt.value_of("project").unwrap_or(""), opt.value_of("zone").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 {
|
|
|
|
|
"page-token" => {
|
|
|
|
|
@@ -122,7 +122,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.extend(["filter", "page-token", "max-results"].iter().map(|v|*v));
|
|
|
|
|
@@ -136,7 +136,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")) {
|
|
|
|
|
@@ -159,13 +159,13 @@ impl<'n, 'a> Engine<'n, 'a> {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn _zone_views_add_resources(&self, opt: &ArgMatches<'n, 'a>, dry_run: bool, err: &mut InvalidOptionsError)
|
|
|
|
|
fn _zone_views_add_resources(&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();
|
|
|
|
|
@@ -179,8 +179,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()[..] {
|
|
|
|
|
"resources" => Some(("resources", JsonTypeInfo { jtype: JsonType::String, ctype: ComplexType::Vec })),
|
|
|
|
|
_ => {
|
|
|
|
|
@@ -195,7 +195,7 @@ impl<'n, 'a> Engine<'n, 'a> {
|
|
|
|
|
}
|
|
|
|
|
let mut request: api::ZoneViewsAddResourcesRequest = json::value::from_value(object).unwrap();
|
|
|
|
|
let mut call = self.hub.zone_views().add_resources(request, opt.value_of("project").unwrap_or(""), opt.value_of("zone").unwrap_or(""), opt.value_of("resource-view").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 {
|
|
|
|
|
_ => {
|
|
|
|
|
@@ -208,7 +208,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 } ));
|
|
|
|
|
@@ -221,7 +221,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")) {
|
|
|
|
|
@@ -244,10 +244,10 @@ impl<'n, 'a> Engine<'n, 'a> {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn _zone_views_delete(&self, opt: &ArgMatches<'n, 'a>, dry_run: bool, err: &mut InvalidOptionsError)
|
|
|
|
|
fn _zone_views_delete(&self, opt: &ArgMatches<'n>, dry_run: bool, err: &mut InvalidOptionsError)
|
|
|
|
|
-> Result<(), DoitError> {
|
|
|
|
|
let mut call = self.hub.zone_views().delete(opt.value_of("project").unwrap_or(""), opt.value_of("zone").unwrap_or(""), opt.value_of("resource-view").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 {
|
|
|
|
|
_ => {
|
|
|
|
|
@@ -260,7 +260,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 } ));
|
|
|
|
|
@@ -273,7 +273,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")) {
|
|
|
|
|
@@ -296,10 +296,10 @@ impl<'n, 'a> Engine<'n, 'a> {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn _zone_views_get(&self, opt: &ArgMatches<'n, 'a>, dry_run: bool, err: &mut InvalidOptionsError)
|
|
|
|
|
fn _zone_views_get(&self, opt: &ArgMatches<'n>, dry_run: bool, err: &mut InvalidOptionsError)
|
|
|
|
|
-> Result<(), DoitError> {
|
|
|
|
|
let mut call = self.hub.zone_views().get(opt.value_of("project").unwrap_or(""), opt.value_of("zone").unwrap_or(""), opt.value_of("resource-view").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 {
|
|
|
|
|
_ => {
|
|
|
|
|
@@ -312,7 +312,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 } ));
|
|
|
|
|
@@ -325,7 +325,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")) {
|
|
|
|
|
@@ -348,10 +348,10 @@ impl<'n, 'a> Engine<'n, 'a> {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn _zone_views_get_service(&self, opt: &ArgMatches<'n, 'a>, dry_run: bool, err: &mut InvalidOptionsError)
|
|
|
|
|
fn _zone_views_get_service(&self, opt: &ArgMatches<'n>, dry_run: bool, err: &mut InvalidOptionsError)
|
|
|
|
|
-> Result<(), DoitError> {
|
|
|
|
|
let mut call = self.hub.zone_views().get_service(opt.value_of("project").unwrap_or(""), opt.value_of("zone").unwrap_or(""), opt.value_of("resource-view").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 {
|
|
|
|
|
"resource-name" => {
|
|
|
|
|
@@ -367,7 +367,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.extend(["resource-name"].iter().map(|v|*v));
|
|
|
|
|
@@ -381,7 +381,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")) {
|
|
|
|
|
@@ -404,13 +404,13 @@ impl<'n, 'a> Engine<'n, 'a> {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn _zone_views_insert(&self, opt: &ArgMatches<'n, 'a>, dry_run: bool, err: &mut InvalidOptionsError)
|
|
|
|
|
fn _zone_views_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();
|
|
|
|
|
@@ -424,8 +424,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()[..] {
|
|
|
|
|
"kind" => Some(("kind", JsonTypeInfo { jtype: JsonType::String, ctype: ComplexType::Pod })),
|
|
|
|
|
"network" => Some(("network", JsonTypeInfo { jtype: JsonType::String, ctype: ComplexType::Pod })),
|
|
|
|
|
@@ -449,7 +449,7 @@ impl<'n, 'a> Engine<'n, 'a> {
|
|
|
|
|
}
|
|
|
|
|
let mut request: api::ResourceView = json::value::from_value(object).unwrap();
|
|
|
|
|
let mut call = self.hub.zone_views().insert(request, opt.value_of("project").unwrap_or(""), opt.value_of("zone").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 {
|
|
|
|
|
_ => {
|
|
|
|
|
@@ -462,7 +462,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 } ));
|
|
|
|
|
@@ -475,7 +475,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")) {
|
|
|
|
|
@@ -498,10 +498,10 @@ impl<'n, 'a> Engine<'n, 'a> {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn _zone_views_list(&self, opt: &ArgMatches<'n, 'a>, dry_run: bool, err: &mut InvalidOptionsError)
|
|
|
|
|
fn _zone_views_list(&self, opt: &ArgMatches<'n>, dry_run: bool, err: &mut InvalidOptionsError)
|
|
|
|
|
-> Result<(), DoitError> {
|
|
|
|
|
let mut call = self.hub.zone_views().list(opt.value_of("project").unwrap_or(""), opt.value_of("zone").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 {
|
|
|
|
|
"page-token" => {
|
|
|
|
|
@@ -520,7 +520,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.extend(["page-token", "max-results"].iter().map(|v|*v));
|
|
|
|
|
@@ -534,7 +534,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")) {
|
|
|
|
|
@@ -557,10 +557,10 @@ impl<'n, 'a> Engine<'n, 'a> {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn _zone_views_list_resources(&self, opt: &ArgMatches<'n, 'a>, dry_run: bool, err: &mut InvalidOptionsError)
|
|
|
|
|
fn _zone_views_list_resources(&self, opt: &ArgMatches<'n>, dry_run: bool, err: &mut InvalidOptionsError)
|
|
|
|
|
-> Result<(), DoitError> {
|
|
|
|
|
let mut call = self.hub.zone_views().list_resources(opt.value_of("project").unwrap_or(""), opt.value_of("zone").unwrap_or(""), opt.value_of("resource-view").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 {
|
|
|
|
|
"service-name" => {
|
|
|
|
|
@@ -588,7 +588,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.extend(["page-token", "service-name", "list-state", "max-results", "format"].iter().map(|v|*v));
|
|
|
|
|
@@ -602,7 +602,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")) {
|
|
|
|
|
@@ -625,13 +625,13 @@ impl<'n, 'a> Engine<'n, 'a> {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn _zone_views_remove_resources(&self, opt: &ArgMatches<'n, 'a>, dry_run: bool, err: &mut InvalidOptionsError)
|
|
|
|
|
fn _zone_views_remove_resources(&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();
|
|
|
|
|
@@ -645,8 +645,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()[..] {
|
|
|
|
|
"resources" => Some(("resources", JsonTypeInfo { jtype: JsonType::String, ctype: ComplexType::Vec })),
|
|
|
|
|
_ => {
|
|
|
|
|
@@ -661,7 +661,7 @@ impl<'n, 'a> Engine<'n, 'a> {
|
|
|
|
|
}
|
|
|
|
|
let mut request: api::ZoneViewsRemoveResourcesRequest = json::value::from_value(object).unwrap();
|
|
|
|
|
let mut call = self.hub.zone_views().remove_resources(request, opt.value_of("project").unwrap_or(""), opt.value_of("zone").unwrap_or(""), opt.value_of("resource-view").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 {
|
|
|
|
|
_ => {
|
|
|
|
|
@@ -674,7 +674,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 } ));
|
|
|
|
|
@@ -687,7 +687,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")) {
|
|
|
|
|
@@ -710,13 +710,13 @@ impl<'n, 'a> Engine<'n, 'a> {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn _zone_views_set_service(&self, opt: &ArgMatches<'n, 'a>, dry_run: bool, err: &mut InvalidOptionsError)
|
|
|
|
|
fn _zone_views_set_service(&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();
|
|
|
|
|
@@ -730,8 +730,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()[..] {
|
|
|
|
|
"resource-name" => Some(("resourceName", JsonTypeInfo { jtype: JsonType::String, ctype: ComplexType::Pod })),
|
|
|
|
|
"fingerprint" => Some(("fingerprint", JsonTypeInfo { jtype: JsonType::String, ctype: ComplexType::Pod })),
|
|
|
|
|
@@ -747,7 +747,7 @@ impl<'n, 'a> Engine<'n, 'a> {
|
|
|
|
|
}
|
|
|
|
|
let mut request: api::ZoneViewsSetServiceRequest = json::value::from_value(object).unwrap();
|
|
|
|
|
let mut call = self.hub.zone_views().set_service(request, opt.value_of("project").unwrap_or(""), opt.value_of("zone").unwrap_or(""), opt.value_of("resource-view").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 {
|
|
|
|
|
_ => {
|
|
|
|
|
@@ -760,7 +760,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 } ));
|
|
|
|
|
@@ -773,7 +773,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")) {
|
|
|
|
|
@@ -867,14 +867,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, "resourceviews1-beta2-secret.json",
|
|
|
|
|
match cmn::application_secret_from_directory(&config_dir, "resourceviews1-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))
|
|
|
|
|
@@ -894,7 +894,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()
|
|
|
|
|
@@ -933,7 +933,7 @@ fn main() {
|
|
|
|
|
let mut exit_status = 0i32;
|
|
|
|
|
let arg_data = [
|
|
|
|
|
("zone-operations", "methods: 'get' and 'list'", vec![
|
|
|
|
|
("get",
|
|
|
|
|
("get",
|
|
|
|
|
Some(r##"Retrieves the specified zone-specific operation resource."##),
|
|
|
|
|
"Details at http://byron.github.io/google-apis-rs/google_resourceviews1_beta2_cli/zone-operations_get",
|
|
|
|
|
vec![
|
|
|
|
|
@@ -967,7 +967,7 @@ fn main() {
|
|
|
|
|
Some(false),
|
|
|
|
|
Some(false)),
|
|
|
|
|
]),
|
|
|
|
|
("list",
|
|
|
|
|
("list",
|
|
|
|
|
Some(r##"Retrieves the list of operation resources contained within the specified zone."##),
|
|
|
|
|
"Details at http://byron.github.io/google-apis-rs/google_resourceviews1_beta2_cli/zone-operations_list",
|
|
|
|
|
vec![
|
|
|
|
|
@@ -998,7 +998,7 @@ fn main() {
|
|
|
|
|
]),
|
|
|
|
|
|
|
|
|
|
("zone-views", "methods: 'add-resources', 'delete', 'get', 'get-service', 'insert', 'list', 'list-resources', 'remove-resources' and 'set-service'", vec![
|
|
|
|
|
("add-resources",
|
|
|
|
|
("add-resources",
|
|
|
|
|
Some(r##"Add resources to the view."##),
|
|
|
|
|
"Details at http://byron.github.io/google-apis-rs/google_resourceviews1_beta2_cli/zone-views_add-resources",
|
|
|
|
|
vec![
|
|
|
|
|
@@ -1038,7 +1038,7 @@ fn main() {
|
|
|
|
|
Some(false),
|
|
|
|
|
Some(false)),
|
|
|
|
|
]),
|
|
|
|
|
("delete",
|
|
|
|
|
("delete",
|
|
|
|
|
Some(r##"Delete a resource view."##),
|
|
|
|
|
"Details at http://byron.github.io/google-apis-rs/google_resourceviews1_beta2_cli/zone-views_delete",
|
|
|
|
|
vec![
|
|
|
|
|
@@ -1072,7 +1072,7 @@ fn main() {
|
|
|
|
|
Some(false),
|
|
|
|
|
Some(false)),
|
|
|
|
|
]),
|
|
|
|
|
("get",
|
|
|
|
|
("get",
|
|
|
|
|
Some(r##"Get the information of a zonal resource view."##),
|
|
|
|
|
"Details at http://byron.github.io/google-apis-rs/google_resourceviews1_beta2_cli/zone-views_get",
|
|
|
|
|
vec![
|
|
|
|
|
@@ -1106,7 +1106,7 @@ fn main() {
|
|
|
|
|
Some(false),
|
|
|
|
|
Some(false)),
|
|
|
|
|
]),
|
|
|
|
|
("get-service",
|
|
|
|
|
("get-service",
|
|
|
|
|
Some(r##"Get the service information of a resource view or a resource."##),
|
|
|
|
|
"Details at http://byron.github.io/google-apis-rs/google_resourceviews1_beta2_cli/zone-views_get-service",
|
|
|
|
|
vec![
|
|
|
|
|
@@ -1140,7 +1140,7 @@ fn main() {
|
|
|
|
|
Some(false),
|
|
|
|
|
Some(false)),
|
|
|
|
|
]),
|
|
|
|
|
("insert",
|
|
|
|
|
("insert",
|
|
|
|
|
Some(r##"Create a resource view."##),
|
|
|
|
|
"Details at http://byron.github.io/google-apis-rs/google_resourceviews1_beta2_cli/zone-views_insert",
|
|
|
|
|
vec![
|
|
|
|
|
@@ -1174,7 +1174,7 @@ fn main() {
|
|
|
|
|
Some(false),
|
|
|
|
|
Some(false)),
|
|
|
|
|
]),
|
|
|
|
|
("list",
|
|
|
|
|
("list",
|
|
|
|
|
Some(r##"List resource views."##),
|
|
|
|
|
"Details at http://byron.github.io/google-apis-rs/google_resourceviews1_beta2_cli/zone-views_list",
|
|
|
|
|
vec![
|
|
|
|
|
@@ -1202,7 +1202,7 @@ fn main() {
|
|
|
|
|
Some(false),
|
|
|
|
|
Some(false)),
|
|
|
|
|
]),
|
|
|
|
|
("list-resources",
|
|
|
|
|
("list-resources",
|
|
|
|
|
Some(r##"List the resources of the resource view."##),
|
|
|
|
|
"Details at http://byron.github.io/google-apis-rs/google_resourceviews1_beta2_cli/zone-views_list-resources",
|
|
|
|
|
vec![
|
|
|
|
|
@@ -1236,7 +1236,7 @@ fn main() {
|
|
|
|
|
Some(false),
|
|
|
|
|
Some(false)),
|
|
|
|
|
]),
|
|
|
|
|
("remove-resources",
|
|
|
|
|
("remove-resources",
|
|
|
|
|
Some(r##"Remove resources from the view."##),
|
|
|
|
|
"Details at http://byron.github.io/google-apis-rs/google_resourceviews1_beta2_cli/zone-views_remove-resources",
|
|
|
|
|
vec![
|
|
|
|
|
@@ -1276,7 +1276,7 @@ fn main() {
|
|
|
|
|
Some(false),
|
|
|
|
|
Some(false)),
|
|
|
|
|
]),
|
|
|
|
|
("set-service",
|
|
|
|
|
("set-service",
|
|
|
|
|
Some(r##"Update the service information of a resource view or a resource."##),
|
|
|
|
|
"Details at http://byron.github.io/google-apis-rs/google_resourceviews1_beta2_cli/zone-views_set-service",
|
|
|
|
|
vec![
|
|
|
|
|
@@ -1322,7 +1322,7 @@ fn main() {
|
|
|
|
|
|
|
|
|
|
let mut app = App::new("resourceviews1-beta2")
|
|
|
|
|
.author("Sebastian Thiel <byronimo@gmail.com>")
|
|
|
|
|
.version("0.3.2+20150708")
|
|
|
|
|
.version("0.3.3+20150708")
|
|
|
|
|
.about("The Resource View API allows users to create and manage logical sets of Google Compute Engine instances.")
|
|
|
|
|
.after_help("All documentation details can be found at http://byron.github.io/google-apis-rs/google_resourceviews1_beta2_cli")
|
|
|
|
|
.arg(Arg::with_name("url")
|
|
|
|
|
@@ -1346,7 +1346,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 {
|
|
|
|
|
@@ -1357,7 +1357,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,
|
|
|
|
|
|