From ef63790422db56158e2e1a6d651e329e14cd7ec0 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Wed, 6 May 2015 10:33:04 +0200 Subject: [PATCH] refactor(CLI): better vector building Instead of using multiple lines to add vectors up involving iterators, I just add slices together. This should produce less, and possibly faster machine code, with less ascii code. Downloads tested with drive2, and are verified to be working ! Close #97 --- src/mako/cli/lib/cli.py | 5 ++++- src/mako/cli/lib/engine.mako | 10 ++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/mako/cli/lib/cli.py b/src/mako/cli/lib/cli.py index f24626eaa0..1eb3253444 100644 --- a/src/mako/cli/lib/cli.py +++ b/src/mako/cli/lib/cli.py @@ -82,10 +82,13 @@ def new_method_context(resource, method, c): return MethodContext(m, response_schema, params, request_value, media_params, required_props, optional_props, part_prop) +def comma_sep_fields(fields): + return ', '.join('"%s"' % mangle_subcommand(f) for f in fields) + # Returns a string representing a string-vector of mangled names # fields is an iterator def field_vec(fields): - return "vec![%s]" % ', '.join('"%s"' % mangle_subcommand(f) for f in fields) + return "vec![%s]" % comma_sep_fields(fields) def pretty(n): return ' '.join(s.capitalize() for s in mangle_subcommand(n).split('-')) diff --git a/src/mako/cli/lib/engine.mako b/src/mako/cli/lib/engine.mako index c7256a0273..44709bde2b 100644 --- a/src/mako/cli/lib/engine.mako +++ b/src/mako/cli/lib/engine.mako @@ -8,7 +8,7 @@ call_method_ident, POD_TYPES, opt_value, ident, JSON_TYPE_VALUE_MAP, KEY_VALUE_ARG, to_cli_schema, SchemaEntry, CTYPE_POD, actual_json_type, CTYPE_MAP, CTYPE_ARRAY, application_secret_path, DEBUG_FLAG, DEBUG_AUTH_FLAG, CONFIG_DIR_FLAG, req_value, MODE_ARG, - opt_values, SCOPE_ARG, CONFIG_DIR_ARG, DEFAULT_MIME, field_vec) + opt_values, SCOPE_ARG, CONFIG_DIR_ARG, DEFAULT_MIME, field_vec, comma_sep_fields) v_arg = '<%s>' % VALUE_ARG SOPT = 'self.opt' @@ -262,11 +262,9 @@ ${value_unwrap}\ } } if !found { - err.issues.push(CLIError::UnknownParameter(key.to_string(), { - let mut v = Vec::new(); - v.extend(self.gp.iter().cloned()); - v.extend(${field_vec(optional_prop_names)}.iter().cloned()); - v })); + err.issues.push(CLIError::UnknownParameter(key.to_string(), + Vec::new() + &self.gp + &[${comma_sep_fields(optional_prop_names)}] + )); } } }