From be7ccb085cb5ea908fb75d0ae7cb6c91ded33bd4 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sat, 25 Apr 2015 13:25:00 +0200 Subject: [PATCH] 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 --- src/mako/api/lib/mbuild.mako | 4 ++-- src/mako/api/lib/rbuild.mako | 2 +- src/mako/cli/lib/docopt.mako | 2 +- src/mako/cli/lib/engine.mako | 8 +++++--- src/mako/lib/util.py | 4 ++-- 5 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/mako/api/lib/mbuild.mako b/src/mako/api/lib/mbuild.mako index 7cfcd0fede..baa9a89e41 100644 --- a/src/mako/api/lib/mbuild.mako +++ b/src/mako/api/lib/mbuild.mako @@ -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(_) diff --git a/src/mako/api/lib/rbuild.mako b/src/mako/api/lib/rbuild.mako index 9bc42bdcf1..85b1b02469 100644 --- a/src/mako/api/lib/rbuild.mako +++ b/src/mako/api/lib/rbuild.mako @@ -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) diff --git a/src/mako/cli/lib/docopt.mako b/src/mako/cli/lib/docopt.mako index 4cb0685224..9c7aec7958 100644 --- a/src/mako/cli/lib/docopt.mako +++ b/src/mako/cli/lib/docopt.mako @@ -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 diff --git a/src/mako/cli/lib/engine.mako b/src/mako/cli/lib/engine.mako index d4510b3609..2b4c2d4bdb 100644 --- a/src/mako/cli/lib/engine.mako +++ b/src/mako/cli/lib/engine.mako @@ -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); \ No newline at end of file diff --git a/src/mako/lib/util.py b/src/mako/lib/util.py index 9e14cd3cb7..af294aa8af 100644 --- a/src/mako/lib/util.py +++ b/src/mako/lib/util.py @@ -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