Skip to content

Commit

Permalink
fix(CLI): NULL default values instead of randoms
Browse files Browse the repository at this point in the history
Instead of generating nonesense random values, we just map defaults
that represent the respective NULL value of a given type.
  • Loading branch information
Byron committed Apr 15, 2015
1 parent 6119bfb commit 4b87d90
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
11 changes: 11 additions & 0 deletions src/mako/cli/lib/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@
'int64' : lambda: randint(-101, -1),
'string': lambda: '%s' % choice(util.words).lower()}

JSON_TYPE_VALUE_MAP = {'boolean': 'false',
'integer' : '-0',
'uint32' : '0',
'uint64' : '0',
'float' : '0.0',
'double' : '0.0',
'number' : '0.0',
'int32' : '-0',
'int64' : '-0',
'string': ''}

assert len(set(JSON_TYPE_RND_MAP.keys()) ^ POD_TYPES) == 0

def new_method_context(resource, method, c):
Expand Down
4 changes: 2 additions & 2 deletions src/mako/cli/lib/engine.mako
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
upload_action_fn)
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_RND_MAP)
cmd_ident, call_method_ident, arg_ident, POD_TYPES, flag_ident, ident, JSON_TYPE_VALUE_MAP)
v_arg = '<%s>' % VALUE_ARG
SOPT = 'self.opt.'
Expand Down Expand Up @@ -184,7 +184,7 @@ for parg in ${SOPT + arg_ident(VALUE_ARG)}.iter() {
ptype = p.type
if p.type == 'string' and 'Count' in p.name:
ptype = 'int64'
value_unwrap = 'value.unwrap_or("%s")' % JSON_TYPE_RND_MAP[ptype]()
value_unwrap = 'value.unwrap_or("%s")' % JSON_TYPE_VALUE_MAP[ptype]
%>\
"${mangle_subcommand(p.name)}" => {
% if p.name == 'alt':
Expand Down
1 change: 0 additions & 1 deletion src/mako/cli/main.rs.mako
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ ${engine.new(c)}\

fn main() {
let opts: Options = Options::docopt().decode().unwrap_or_else(|e| e.exit());
println!("DEBUG: {:?}", opts);
match Engine::new(opts) {
Err(err) => {
write!(io::stderr(), "{}", err).ok();
Expand Down
2 changes: 1 addition & 1 deletion src/rust/cli/cmn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ impl fmt::Display for CLIError {
CLIError::UnknownParameter(ref param_name)
=> writeln!(f, "Parameter '{}' is unknown.", param_name),
CLIError::InvalidKeyValueSyntax(ref kv)
=> writeln!(f, "'{}' does not match <key>=<value>", kv),
=> writeln!(f, "'{}' does not match pattern <key>=<value>", kv),

}
}
Expand Down

0 comments on commit 4b87d90

Please sign in to comment.