mirror of
https://github.com/OMGeeky/google-apis-rs.git
synced 2026-01-17 17:03:06 +01:00
feat(CLI): repeated required args
* Seem to work for docopt, mkdocs and code itself * mkdocs now show type of required params * some code which deals with converting elements to their target types is totally untested right now. Related to #77
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
from cli import (subcommand_md_filename, new_method_context, SPLIT_START, SPLIT_END, pretty, SCOPE_FLAG,
|
||||
mangle_subcommand, is_request_value_property, FIELD_SEP, PARAM_FLAG, UPLOAD_FLAG, docopt_mode,
|
||||
FILE_ARG, MIME_ARG, OUT_ARG, OUTPUT_FLAG, to_cli_schema, cli_schema_to_yaml, SchemaEntry,
|
||||
STRUCT_FLAG, field_to_value, CTYPE_ARRAY, CTYPE_MAP)
|
||||
STRUCT_FLAG, field_to_value, CTYPE_ARRAY, CTYPE_MAP, to_docopt_arg)
|
||||
|
||||
from copy import deepcopy
|
||||
|
||||
@@ -51,8 +51,11 @@ You can set the scope for this method like this: `${util.program_name()} --${SCO
|
||||
% if rprops:
|
||||
# Required Scalar ${len(rprops) > 1 and 'Arguments' or 'Argument'}
|
||||
% for p in rprops:
|
||||
* **<${mangle_subcommand(p.name)}\>**
|
||||
* **${to_docopt_arg(p) | xml_escape}** *(${p.type})*
|
||||
- ${p.get('description') or NO_DESC | xml_escape, indent_all_but_first_by(2)}
|
||||
% if p.get('repeated'):
|
||||
- This property can be specified one or more times
|
||||
% endif
|
||||
% endfor # each required property (which is not the request value)
|
||||
% endif # have required properties
|
||||
% if mc.request_value:
|
||||
|
||||
@@ -121,6 +121,11 @@ def actual_json_type(name, type):
|
||||
return 'int64'
|
||||
return type
|
||||
|
||||
# return a string representing property `p` suitable for docopt argument parsing
|
||||
def to_docopt_arg(p):
|
||||
return '<%s>%s' % (mangle_subcommand(p.name), p.get('repeated', False) and '...' or '')
|
||||
|
||||
|
||||
# Return schema' with fields dict: { 'field1' : SchemaField(...), 'SubSchema': schema' }
|
||||
def to_cli_schema(c, schema):
|
||||
res = deepcopy(schema)
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
from util import (put_and, supports_scopes)
|
||||
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)
|
||||
CONFIG_DIR_FLAG, KEY_VALUE_ARG, to_docopt_arg)
|
||||
%>\
|
||||
<%def name="new(c)">\
|
||||
<%
|
||||
@@ -23,7 +23,7 @@ Usage:
|
||||
for p in mc.required_props:
|
||||
if is_request_value_property(mc, p):
|
||||
continue
|
||||
args.append('<%s>' % mangle_subcommand(p.name))
|
||||
args.append(to_docopt_arg(p))
|
||||
# end for each required property
|
||||
|
||||
if mc.request_value:
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
def borrow_prefix(p):
|
||||
ptype = p.get('type', None)
|
||||
borrow = ''
|
||||
if ptype not in POD_TYPES or ptype in ('string', None):
|
||||
if ptype not in POD_TYPES or ptype in ('string', None) or p.get('repeated', False):
|
||||
borrow = '&'
|
||||
return borrow
|
||||
|
||||
@@ -175,7 +175,14 @@ if opt.flag_${flag_name} {
|
||||
<% request_prop_type = prop_type %>\
|
||||
let mut ${prop_name} = api::${prop_type}::default();
|
||||
% elif p.type != 'string':
|
||||
% if p.get('repeated', False):
|
||||
let ${prop_name}: Vec<${prop_type} = Vec::new();
|
||||
for (arg_id, arg) in ${opt_ident}.iter().enumerate() {
|
||||
${prop_name}.push(arg_from_str(&arg, err, "<${mangle_subcommand(p.name)}>", arg_id), "${p.type}"));
|
||||
}
|
||||
% else:
|
||||
let ${prop_name}: ${prop_type} = arg_from_str(&${opt_ident}, err, "<${mangle_subcommand(p.name)}>", "${p.type}");
|
||||
% endif # handle repeated values
|
||||
% endif # handle request value
|
||||
% endfor # each required parameter
|
||||
<%
|
||||
|
||||
Reference in New Issue
Block a user