mirror of
https://github.com/OMGeeky/google-apis-rs.git
synced 2026-01-06 11:34:34 +01:00
fix(clap): tweaks to make youtube3 work
Mainly minor cleanup, and handling of generator branches that didn't show up in smaller APIs that were used during the first steps. related to #81
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
from util import (put_and, supports_scopes, api_index, indent_by, enclose_in)
|
||||
from cli import (mangle_subcommand, new_method_context, PARAM_FLAG, STRUCT_FLAG, UPLOAD_FLAG, OUTPUT_FLAG, VALUE_ARG,
|
||||
CONFIG_DIR, SCOPE_FLAG, is_request_value_property, FIELD_SEP, docopt_mode, FILE_ARG, MIME_ARG, OUT_ARG,
|
||||
CONFIG_DIR_FLAG, KEY_VALUE_ARG, to_docopt_arg, DEBUG_FLAG, DEBUG_AUTH_FLAG)
|
||||
CONFIG_DIR_FLAG, KEY_VALUE_ARG, to_docopt_arg, DEBUG_FLAG, DEBUG_AUTH_FLAG, MODE_ARG)
|
||||
|
||||
def rust_boolean(v):
|
||||
return v and 'true' or 'false'
|
||||
@@ -64,7 +64,7 @@ Configuration:
|
||||
% if supports_scopes(auth):
|
||||
--${SCOPE_FLAG} <url>
|
||||
Specify the authentication a method should be executed in. Each scope
|
||||
requires the user to grant this application permission to use it.
|
||||
requires the user to grant this application permission to use it.
|
||||
If unset, it defaults to the shortest scope url for a particular method.
|
||||
% endif scopes
|
||||
--${CONFIG_DIR_FLAG} <folder>
|
||||
@@ -187,12 +187,11 @@ let arg_data = [
|
||||
args.append((
|
||||
UPLOAD_FLAG,
|
||||
"Specify which file to upload",
|
||||
"mode",
|
||||
False,
|
||||
MODE_ARG,
|
||||
True,
|
||||
False,
|
||||
upload_protocols
|
||||
))
|
||||
## args.append('-%s %s %s %s' % (UPLOAD_FLAG, mode, FILE_ARG, MIME_ARG))
|
||||
# end upload handling
|
||||
|
||||
if mc.optional_props or parameters is not UNDEFINED:
|
||||
@@ -284,12 +283,12 @@ for &(main_command_name, ref subcommands) in arg_data.iter() {
|
||||
|
||||
scmd = scmd.arg(Arg::with_name("file")
|
||||
.short("f")
|
||||
.required(false)
|
||||
.required(true)
|
||||
.help("The file to upload")
|
||||
.takes_value(true));
|
||||
scmd = scmd.arg(Arg::with_name("mime")
|
||||
.short("m")
|
||||
.required(false)
|
||||
.required(true)
|
||||
.help("The file's mime time, like 'application/octet-stream'")
|
||||
.takes_value(true));
|
||||
}
|
||||
@@ -299,6 +298,5 @@ for &(main_command_name, ref subcommands) in arg_data.iter() {
|
||||
}
|
||||
app = app.subcommand(mcmd);
|
||||
}
|
||||
let matches = app.get_matches();
|
||||
</%block>
|
||||
</%def>
|
||||
@@ -20,6 +20,7 @@ CONFIG_DIR_FLAG = 'config-dir'
|
||||
DEBUG_FLAG = 'debug'
|
||||
DEBUG_AUTH_FLAG = 'debug-auth'
|
||||
|
||||
MODE_ARG = 'mode'
|
||||
FILE_ARG = 'file'
|
||||
MIME_ARG = 'mime'
|
||||
OUT_ARG = 'out'
|
||||
@@ -91,12 +92,12 @@ def mangle_subcommand(name):
|
||||
def ident(name):
|
||||
return mangle_subcommand(name).replace('-', '_')
|
||||
|
||||
# Similar to cmd_ident, but for arguments
|
||||
def arg_ident(name):
|
||||
return opt_value(name)
|
||||
# Return a required value in Rust, using unwrap()
|
||||
def req_value(name):
|
||||
return 'opt.value_of("' + mangle_subcommand(name) + '").unwrap()'
|
||||
|
||||
def opt_value(name, opt='opt'):
|
||||
return opt + '.value_of("' + mangle_subcommand(name) + '").unwrap_or("")'
|
||||
def opt_value(name, opt='opt', default=''):
|
||||
return opt + '.value_of("' + mangle_subcommand(name) + ('").unwrap_or("%s")' % default)
|
||||
|
||||
def application_secret_path(program_name):
|
||||
return program_name + '-secret.json'
|
||||
|
||||
@@ -5,9 +5,9 @@
|
||||
ADD_SCOPE_FN, TREF)
|
||||
from cli import (mangle_subcommand, new_method_context, PARAM_FLAG, STRUCT_FLAG, UPLOAD_FLAG, OUTPUT_FLAG, VALUE_ARG,
|
||||
CONFIG_DIR, SCOPE_FLAG, is_request_value_property, FIELD_SEP, docopt_mode, FILE_ARG, MIME_ARG, OUT_ARG,
|
||||
call_method_ident, arg_ident, POD_TYPES, opt_value, ident, JSON_TYPE_VALUE_MAP,
|
||||
call_method_ident, POD_TYPES, opt_value, ident, JSON_TYPE_VALUE_MAP,
|
||||
KEY_VALUE_ARG, to_cli_schema, SchemaEntry, CTYPE_POD, actual_json_type, CTYPE_MAP, CTYPE_ARRAY,
|
||||
application_secret_path, DEBUG_FLAG, DEBUG_AUTH_FLAG, CONFIG_DIR_FLAG)
|
||||
application_secret_path, DEBUG_FLAG, DEBUG_AUTH_FLAG, CONFIG_DIR_FLAG, req_value, MODE_ARG)
|
||||
|
||||
v_arg = '<%s>' % VALUE_ARG
|
||||
SOPT = 'self.opt'
|
||||
@@ -172,7 +172,7 @@ ${self._request_value_impl(c, request_cli_schema, prop_name, request_prop_type)}
|
||||
% elif p.type != 'string':
|
||||
% if p.get('repeated', False):
|
||||
let ${prop_name}: Vec<${prop_type} = Vec::new();
|
||||
for (arg_id, arg) in opt.values_of().unwrap_or(Vec::new()).iter().enumerate() {
|
||||
for (arg_id, arg) in opt.values_of("${mangle_subcommand(p.name)}").unwrap_or(Vec::new()).iter().enumerate() {
|
||||
${prop_name}.push(arg_from_str(&arg, err, "<${mangle_subcommand(p.name)}>", arg_id), "${p.type}"));
|
||||
}
|
||||
% else:
|
||||
@@ -197,7 +197,7 @@ let mut download_mode = false;
|
||||
% endif
|
||||
let mut call = self.hub.${mangle_ident(resource)}().${mangle_ident(method)}(${', '.join(call_args)});
|
||||
% if handle_props:
|
||||
for parg in opt.values_of("${ident(VALUE_ARG)}").unwrap_or(Vec::new()).iter() {
|
||||
for parg in opt.values_of("${VALUE_ARG}").unwrap_or(Vec::new()).iter() {
|
||||
let (key, value) = parse_kv_arg(&*parg, err, false);
|
||||
match key {
|
||||
% for p in optional_props:
|
||||
@@ -253,21 +253,9 @@ ${value_unwrap}\
|
||||
}
|
||||
% endif # handle call parameters
|
||||
% if mc.media_params:
|
||||
let protocol =
|
||||
% for p in mc.media_params:
|
||||
% if loop.first:
|
||||
if \
|
||||
% else:
|
||||
} else if \
|
||||
% endif
|
||||
${opt_value(p.protocol)} {
|
||||
"${p.protocol}"
|
||||
% endfor # each media param
|
||||
} else {
|
||||
unreachable!()
|
||||
};
|
||||
let mut input_file = input_file_from_opts(&${opt_value(FILE_ARG)}, err);
|
||||
let mime_type = input_mime_from_opts(&${opt_value(MIME_ARG)}, err);
|
||||
let protocol = ${req_value(MODE_ARG)};
|
||||
let mut input_file = input_file_from_opts(${req_value(FILE_ARG)}, err);
|
||||
let mime_type = input_mime_from_opts(${req_value(MIME_ARG)}, err);
|
||||
% else:
|
||||
let protocol = "${STANDARD}";
|
||||
% endif # support upload
|
||||
@@ -376,7 +364,7 @@ if dry_run {
|
||||
%>\
|
||||
let mut ${request_prop_name} = api::${request_prop_type}::default();
|
||||
let mut field_cursor = FieldCursor::default();
|
||||
for kvarg in ${opt_value(KEY_VALUE_ARG)}.iter() {
|
||||
for kvarg in opt.values_of("${KEY_VALUE_ARG}").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();
|
||||
|
||||
@@ -34,6 +34,7 @@ ${engine.new(c)}\
|
||||
|
||||
fn main() {
|
||||
${argparse.new(c) | indent_all_but_first_by(1)}\
|
||||
let matches = app.get_matches();
|
||||
|
||||
let debug = matches.is_present("${DEBUG_FLAG}");
|
||||
match Engine::new(matches) {
|
||||
|
||||
Reference in New Issue
Block a user