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
This commit is contained in:
Sebastian Thiel
2015-05-06 10:33:04 +02:00
parent f1fe6bac01
commit ef63790422
2 changed files with 8 additions and 7 deletions

View File

@@ -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('-'))

View File

@@ -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)}]
));
}
}
}