Skip to content

Commit 4b87d90

Browse files
committed
fix(CLI): NULL default values instead of randoms
Instead of generating nonesense random values, we just map defaults that represent the respective NULL value of a given type.
1 parent 6119bfb commit 4b87d90

4 files changed

Lines changed: 14 additions & 4 deletions

File tree

src/mako/cli/lib/cli.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,17 @@
4949
'int64' : lambda: randint(-101, -1),
5050
'string': lambda: '%s' % choice(util.words).lower()}
5151

52+
JSON_TYPE_VALUE_MAP = {'boolean': 'false',
53+
'integer' : '-0',
54+
'uint32' : '0',
55+
'uint64' : '0',
56+
'float' : '0.0',
57+
'double' : '0.0',
58+
'number' : '0.0',
59+
'int32' : '-0',
60+
'int64' : '-0',
61+
'string': ''}
62+
5263
assert len(set(JSON_TYPE_RND_MAP.keys()) ^ POD_TYPES) == 0
5364

5465
def new_method_context(resource, method, c):

src/mako/cli/lib/engine.mako

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
upload_action_fn)
55
from cli import (mangle_subcommand, new_method_context, PARAM_FLAG, STRUCT_FLAG, UPLOAD_FLAG, OUTPUT_FLAG, VALUE_ARG,
66
CONFIG_DIR, SCOPE_FLAG, is_request_value_property, FIELD_SEP, docopt_mode, FILE_ARG, MIME_ARG, OUT_ARG,
7-
cmd_ident, call_method_ident, arg_ident, POD_TYPES, flag_ident, ident, JSON_TYPE_RND_MAP)
7+
cmd_ident, call_method_ident, arg_ident, POD_TYPES, flag_ident, ident, JSON_TYPE_VALUE_MAP)
88
99
v_arg = '<%s>' % VALUE_ARG
1010
SOPT = 'self.opt.'
@@ -184,7 +184,7 @@ for parg in ${SOPT + arg_ident(VALUE_ARG)}.iter() {
184184
ptype = p.type
185185
if p.type == 'string' and 'Count' in p.name:
186186
ptype = 'int64'
187-
value_unwrap = 'value.unwrap_or("%s")' % JSON_TYPE_RND_MAP[ptype]()
187+
value_unwrap = 'value.unwrap_or("%s")' % JSON_TYPE_VALUE_MAP[ptype]
188188
%>\
189189
"${mangle_subcommand(p.name)}" => {
190190
% if p.name == 'alt':

src/mako/cli/main.rs.mako

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ ${engine.new(c)}\
3131

3232
fn main() {
3333
let opts: Options = Options::docopt().decode().unwrap_or_else(|e| e.exit());
34-
println!("DEBUG: {:?}", opts);
3534
match Engine::new(opts) {
3635
Err(err) => {
3736
write!(io::stderr(), "{}", err).ok();

src/rust/cli/cmn.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ impl fmt::Display for CLIError {
196196
CLIError::UnknownParameter(ref param_name)
197197
=> writeln!(f, "Parameter '{}' is unknown.", param_name),
198198
CLIError::InvalidKeyValueSyntax(ref kv)
199-
=> writeln!(f, "'{}' does not match <key>=<value>", kv),
199+
=> writeln!(f, "'{}' does not match pattern <key>=<value>", kv),
200200

201201
}
202202
}

0 commit comments

Comments
 (0)