Skip to content

Commit

Permalink
fix(CLI): request value cursor handling and docs
Browse files Browse the repository at this point in the history
* now the cursor will only be set permanently if the -r flag is used in
  'cursor' mode. In 'cursor=value' mode, the cursor change doesn't
  persist among the flags. That way, one can easily distinguish
  between setting the cursor, and setting a field. However,
  '...sublevel.level=value' will still work as it did previously, yet
  the cursor change will not persist.
* Documentation was adjusted to represent the new cursor style.

Fixes #86
  • Loading branch information
Byron committed Apr 26, 2015
1 parent 2f3b2d2 commit b6a48bd
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 14 deletions.
5 changes: 4 additions & 1 deletion src/mako/api/lib/rbuild.mako
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,17 @@ impl${rb_params} ${ThisType} {
% endfor
% endif
pub fn ${mangle_ident(a)}${type_params}(&self${method_args}) -> ${RType}${mb_tparams} {
% if part_prop and request_value:
let parts = ${mangle_ident(REQUEST_VALUE_PROPERTY_NAME)}.to_parts();
% endif
${RType} {
hub: self.hub,
% for p in required_props:
${property(p.name)}: ${rust_copy_value_s(mangle_ident(p.name), activity_input_type(schemas, p), p)},
% endfor
## auto-generate parts from request resources
% if part_prop and request_value:
${property(part_prop.name)}: ${mangle_ident(REQUEST_VALUE_PROPERTY_NAME)}.to_parts(),
${property(part_prop.name)}: parts,
% endif
% for p in optional_props:
${property(p.name)}: Default::default(),
Expand Down
21 changes: 13 additions & 8 deletions src/mako/cli/docs/commands.md.mako
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ The method's return value is a byte stream of the downloadable resource.
% if oprops:
# Optional Method Properties

You may set the following properties to further configure the call.
You may set the following properties to further configure the call. Please note that `-${PARAM_FLAG}` is followed by one
or more key-value-pairs, and is called like this `-${PARAM_FLAG} k1=v1 k2=v2` even though the listing below repeats the
`-${PARAM_FLAG}` for completeness.

% for p in sorted(oprops):
${self._md_property(p)}
Expand Down Expand Up @@ -162,19 +164,20 @@ ${SPLIT_END}
- ${p.get('description') or NO_DESC | xml_escape ,indent_all_but_first_by(2)}
</%def>

<%def name="_list_schem_args(schema, cursor_tokens=list())">\
<%def name="_list_schem_args(schema, cursor_tokens=list(), first_flag=None)">\
<%
if len(cursor_tokens) == 0:
cursor_tokens = [FIELD_SEP]
if first_flag is None:
first_flag = '-%s ' % STRUCT_FLAG
def cursor_fmt(cursor):
fndfi = 0 # first non-dot field index
for (fndfi, v) in enumerate(cursor):
if v != FIELD_SEP:
break
res = ''.join(cursor[:fndfi]) + FIELD_SEP.join(cursor[fndfi:])
if not res.endswith(FIELD_SEP):
res += FIELD_SEP
res += ' '
return res
def cursor_arg(field):
Expand All @@ -184,12 +187,14 @@ ${SPLIT_END}
del cursor_tokens[:]
return prefix + field
%>\
% for fn in sorted(schema.fields.keys()):
% for fni, fn in enumerate(sorted(schema.fields.keys())):
<%
f = schema.fields[fn]
f = schema.fields[fn]
if fni > 0:
first_flag = ''
%>\
% if isinstance(f, SchemaEntry):
* **-${STRUCT_FLAG} ${cursor_arg(mangle_subcommand(fn))}=${field_to_value(f)}**
* **${first_flag}${cursor_arg(mangle_subcommand(fn))}=${field_to_value(f)}**
- ${f.property.get('description', NO_DESC) | xml_escape, indent_all_but_first_by(2)}
% if f.container_type == CTYPE_ARRAY:
- Each invocation of this argument appends the given value to the array.
Expand All @@ -200,7 +205,7 @@ ${SPLIT_END}
<%
cursor_tokens.append(mangle_subcommand(fn))
%>\
${self._list_schem_args(f, cursor_tokens)}
${self._list_schem_args(f, cursor_tokens, first_flag)}
<%
assert not cursor_tokens or cursor_tokens[-1] == FIELD_SEP
if not cursor_tokens:
Expand Down
17 changes: 13 additions & 4 deletions src/mako/cli/lib/engine.mako
Original file line number Diff line number Diff line change
Expand Up @@ -382,16 +382,25 @@ if dry_run {
flatten_schema_fields(request_cli_schema, schema_fields, init_fn_map)
%>\
let mut ${request_prop_name} = api::${request_prop_type}::default();
let mut field_name = FieldCursor::default();
let mut field_cursor = FieldCursor::default();
for kvarg in ${SOPT + arg_ident(KEY_VALUE_ARG)}.iter() {
let last_errc = err.issues.len();
let (key, value) = parse_kv_arg(&*kvarg, err, false);
if let Err(field_err) = field_name.set(&*key) {
let mut temp_cursor = field_cursor.clone();
if let Err(field_err) = temp_cursor.set(&*key) {
err.issues.push(field_err);
}
if value.is_none() {
field_cursor = temp_cursor.clone();
if err.issues.len() > last_errc {
err.issues.remove(last_errc);
}
continue;
}
% for name in sorted(init_fn_map.keys()):
${init_fn_map[name] | indent_by(4)}
% endfor
match &field_name.to_string()[..] {
match &temp_cursor.to_string()[..] {
% for init_call, schema, fe, f in schema_fields:
<%
ptype = actual_json_type(f[-1][1], fe.actual_property.type)
Expand Down Expand Up @@ -439,7 +448,7 @@ ${opt_suffix}\
},
% endfor # each nested field
_ => {
err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string())));
err.issues.push(CLIError::Field(FieldError::Unknown(temp_cursor.to_string())));
}
}
}
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 @@ -103,7 +103,7 @@ pub fn parse_kv_arg<'a>(kv: &'a str, err: &mut InvalidOptionsError, for_hashmap:
let key = &kv[..pos];
if kv.len() <= pos + 1 {
add_err();
return (key, None)
return (key, Some(""))
}
(key, Some(&kv[pos+1..]))
}
Expand Down

0 comments on commit b6a48bd

Please sign in to comment.