Skip to content

Commit be7ccb0

Browse files
committed
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
1 parent 6befdbc commit be7ccb0

5 files changed

Lines changed: 11 additions & 9 deletions

File tree

src/mako/api/lib/mbuild.mako

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ ${self._setter_fn(resource, method, m, p, part_prop, ThisType, c)}\
272272
rvfrt = lambda spn, sp, sn=None: rnd_arg_val_for_type(trv(spn, sp, sn))
273273
274274
rb_name = 'req' # name of request binding
275-
required_args = request_value and ['&' + rb_name] or []
275+
required_args = request_value and [rb_name] or []
276276
for p in required_props:
277277
# could also just skip the first element, but ... let's be safe
278278
if request_value and request_value.id == p.get(TREF):
@@ -370,7 +370,7 @@ match result {
370370
// You can also just use its `Debug`, `Display` or `Error` traits
371371
Error::HttpError(_)
372372
|Error::MissingAPIKey
373-
|Error::MissingToken
373+
|Error::MissingToken(_)
374374
|Error::Cancelled
375375
|Error::UploadSizeLimitExceeded(_, _)
376376
|Error::Failure(_)

src/mako/api/lib/rbuild.mako

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
rb_type, singular, hub_type, mangle_ident, mb_type, method_params, property,
44
to_fqan, indent_all_but_first_by,
55
activity_input_type, TREF, IO_REQUEST, schema_to_required_property,
6-
rust_copy_value_s, is_required_property, organize_params, REQUEST_VALUE_PROPERTY_NAME,
6+
rust_copy_value_s, organize_params, REQUEST_VALUE_PROPERTY_NAME,
77
build_all_params, rb_type_params_s, hub_type_params_s, mb_type_params_s, mb_additional_type_params,
88
struct_type_bounds_s, METHODS_RESOURCE, SPACES_PER_TAB, prefix_all_but_first_with,
99
METHODS_BUILDER_MARKER_TRAIT, remove_empty_lines, method_default_scope)

src/mako/cli/lib/docopt.mako

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Usage:
3939
# end upload handling
4040
4141
if mc.optional_props or parameters is not UNDEFINED:
42-
args.append('[-%s %s]...' % (PARAM_FLAG, '<%s>' % VALUE_ARG))
42+
args.append('[-%s %s...]' % (PARAM_FLAG, '<%s>' % VALUE_ARG))
4343
param_used = True
4444
# end paramters
4545

src/mako/cli/lib/engine.mako

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<%!
33
from util import (hub_type, mangle_ident, indent_all_but_first_by, activity_rust_type, setter_fn_name, ADD_PARAM_FN,
44
upload_action_fn, is_schema_with_optionals, schema_markers, indent_by, method_default_scope,
5-
ADD_SCOPE_FN)
5+
ADD_SCOPE_FN, TREF)
66
from cli import (mangle_subcommand, new_method_context, PARAM_FLAG, STRUCT_FLAG, UPLOAD_FLAG, OUTPUT_FLAG, VALUE_ARG,
77
CONFIG_DIR, SCOPE_FLAG, is_request_value_property, FIELD_SEP, docopt_mode, FILE_ARG, MIME_ARG, OUT_ARG,
88
cmd_ident, call_method_ident, arg_ident, POD_TYPES, flag_ident, ident, JSON_TYPE_VALUE_MAP,
@@ -16,7 +16,7 @@
1616
def borrow_prefix(p):
1717
ptype = p.get('type', None)
1818
borrow = ''
19-
if ptype not in POD_TYPES or ptype in ('string', None) or p.get('repeated', False):
19+
if (ptype not in POD_TYPES or ptype in ('string', None) or p.get('repeated', False)) and ptype is not None:
2020
borrow = '&'
2121
return borrow
2222
@@ -175,7 +175,7 @@ if opt.flag_${flag_name} {
175175
%>\
176176
% if is_request_value_property(mc, p):
177177
<% request_prop_type = prop_type %>\
178-
let mut ${prop_name} = api::${prop_type}::default();
178+
let ${prop_name} = api::${prop_type}::default();
179179
% elif p.type != 'string':
180180
% if p.get('repeated', False):
181181
let ${prop_name}: Vec<${prop_type} = Vec::new();
@@ -384,6 +384,7 @@ if dry_run {
384384
init_fn_map = dict()
385385
flatten_schema_fields(request_cli_schema, schema_fields, init_fn_map)
386386
%>\
387+
let mut request = api::${request_prop_type}::default();
387388
let mut field_name = FieldCursor::default();
388389
for kvarg in ${SOPT + arg_ident(KEY_VALUE_ARG)}.iter() {
389390
let (key, value) = parse_kv_arg(&*kvarg, err, false);
@@ -445,4 +446,5 @@ ${opt_suffix}\
445446
}
446447
}
447448
}
449+
call = call.request(request);
448450
</%def>

src/mako/lib/util.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ def activity_input_type(schemas, p):
379379
if n == 'String':
380380
n = 'str'
381381
# pods are copied anyway
382-
elif is_pod_property(p):
382+
elif is_pod_property(p) or p.get(TREF):
383383
return n
384384
return '&%s' % n
385385

@@ -535,7 +535,7 @@ def rust_copy_value_s(n, tn, p):
535535
nc = n + '.clone()'
536536
if tn == '&str':
537537
nc = n + '.to_string()'
538-
elif is_pod_property(p):
538+
elif is_pod_property(p) or p.get(TREF):
539539
nc = n
540540
return nc
541541

0 commit comments

Comments
 (0)