Skip to content

Commit

Permalink
fix(CLI): set request value to call
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Byron committed Apr 25, 2015
1 parent 6befdbc commit be7ccb0
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/mako/api/lib/mbuild.mako
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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(_)
Expand Down
2 changes: 1 addition & 1 deletion src/mako/api/lib/rbuild.mako
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/mako/cli/lib/docopt.mako
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions src/mako/cli/lib/engine.mako
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -445,4 +446,5 @@ ${opt_suffix}\
}
}
}
call = call.request(request);
</%def>
4 changes: 2 additions & 2 deletions src/mako/lib/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down

0 comments on commit be7ccb0

Please sign in to comment.