mirror of
https://github.com/OMGeeky/google-apis-rs.git
synced 2025-12-30 08:08:50 +01:00
fix(CLI): set request value to call
Previously, even though the request was passed by reference, it was copied and thus our changes never arrived in the call. Now the API makes this clear by taking ownership, and the CLI code sets the Request value lateron, explicitly. Related to #76
This commit is contained in:
@@ -272,7 +272,7 @@ ${self._setter_fn(resource, method, m, p, part_prop, ThisType, c)}\
|
||||
rvfrt = lambda spn, sp, sn=None: rnd_arg_val_for_type(trv(spn, sp, sn))
|
||||
|
||||
rb_name = 'req' # name of request binding
|
||||
required_args = request_value and ['&' + rb_name] or []
|
||||
required_args = request_value and [rb_name] or []
|
||||
for p in required_props:
|
||||
# could also just skip the first element, but ... let's be safe
|
||||
if request_value and request_value.id == p.get(TREF):
|
||||
@@ -370,7 +370,7 @@ match result {
|
||||
// You can also just use its `Debug`, `Display` or `Error` traits
|
||||
Error::HttpError(_)
|
||||
|Error::MissingAPIKey
|
||||
|Error::MissingToken
|
||||
|Error::MissingToken(_)
|
||||
|Error::Cancelled
|
||||
|Error::UploadSizeLimitExceeded(_, _)
|
||||
|Error::Failure(_)
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
rb_type, singular, hub_type, mangle_ident, mb_type, method_params, property,
|
||||
to_fqan, indent_all_but_first_by,
|
||||
activity_input_type, TREF, IO_REQUEST, schema_to_required_property,
|
||||
rust_copy_value_s, is_required_property, organize_params, REQUEST_VALUE_PROPERTY_NAME,
|
||||
rust_copy_value_s, organize_params, REQUEST_VALUE_PROPERTY_NAME,
|
||||
build_all_params, rb_type_params_s, hub_type_params_s, mb_type_params_s, mb_additional_type_params,
|
||||
struct_type_bounds_s, METHODS_RESOURCE, SPACES_PER_TAB, prefix_all_but_first_with,
|
||||
METHODS_BUILDER_MARKER_TRAIT, remove_empty_lines, method_default_scope)
|
||||
|
||||
@@ -39,7 +39,7 @@ Usage:
|
||||
# end upload handling
|
||||
|
||||
if mc.optional_props or parameters is not UNDEFINED:
|
||||
args.append('[-%s %s]...' % (PARAM_FLAG, '<%s>' % VALUE_ARG))
|
||||
args.append('[-%s %s...]' % (PARAM_FLAG, '<%s>' % VALUE_ARG))
|
||||
param_used = True
|
||||
# end paramters
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<%!
|
||||
from util import (hub_type, mangle_ident, indent_all_but_first_by, activity_rust_type, setter_fn_name, ADD_PARAM_FN,
|
||||
upload_action_fn, is_schema_with_optionals, schema_markers, indent_by, method_default_scope,
|
||||
ADD_SCOPE_FN)
|
||||
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,
|
||||
cmd_ident, call_method_ident, arg_ident, POD_TYPES, flag_ident, ident, JSON_TYPE_VALUE_MAP,
|
||||
@@ -16,7 +16,7 @@
|
||||
def borrow_prefix(p):
|
||||
ptype = p.get('type', None)
|
||||
borrow = ''
|
||||
if ptype not in POD_TYPES or ptype in ('string', None) or p.get('repeated', False):
|
||||
if (ptype not in POD_TYPES or ptype in ('string', None) or p.get('repeated', False)) and ptype is not None:
|
||||
borrow = '&'
|
||||
return borrow
|
||||
|
||||
@@ -175,7 +175,7 @@ if opt.flag_${flag_name} {
|
||||
%>\
|
||||
% if is_request_value_property(mc, p):
|
||||
<% request_prop_type = prop_type %>\
|
||||
let mut ${prop_name} = api::${prop_type}::default();
|
||||
let ${prop_name} = api::${prop_type}::default();
|
||||
% elif p.type != 'string':
|
||||
% if p.get('repeated', False):
|
||||
let ${prop_name}: Vec<${prop_type} = Vec::new();
|
||||
@@ -384,6 +384,7 @@ if dry_run {
|
||||
init_fn_map = dict()
|
||||
flatten_schema_fields(request_cli_schema, schema_fields, init_fn_map)
|
||||
%>\
|
||||
let mut request = api::${request_prop_type}::default();
|
||||
let mut field_name = FieldCursor::default();
|
||||
for kvarg in ${SOPT + arg_ident(KEY_VALUE_ARG)}.iter() {
|
||||
let (key, value) = parse_kv_arg(&*kvarg, err, false);
|
||||
@@ -445,4 +446,5 @@ ${opt_suffix}\
|
||||
}
|
||||
}
|
||||
}
|
||||
call = call.request(request);
|
||||
</%def>
|
||||
@@ -379,7 +379,7 @@ def activity_input_type(schemas, p):
|
||||
if n == 'String':
|
||||
n = 'str'
|
||||
# pods are copied anyway
|
||||
elif is_pod_property(p):
|
||||
elif is_pod_property(p) or p.get(TREF):
|
||||
return n
|
||||
return '&%s' % n
|
||||
|
||||
@@ -535,7 +535,7 @@ def rust_copy_value_s(n, tn, p):
|
||||
nc = n + '.clone()'
|
||||
if tn == '&str':
|
||||
nc = n + '.to_string()'
|
||||
elif is_pod_property(p):
|
||||
elif is_pod_property(p) or p.get(TREF):
|
||||
nc = n
|
||||
return nc
|
||||
|
||||
|
||||
Reference in New Issue
Block a user