Skip to content

Commit

Permalink
fix(CLI): use only one request structure
Browse files Browse the repository at this point in the history
This works as we can just put all request-structure parsing to the top
of the function.
That way, we don't put the request struture twice.
  • Loading branch information
Byron committed Apr 25, 2015
1 parent be7ccb0 commit 0bb30da
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/mako/cli/lib/engine.mako
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ if opt.flag_${flag_name} {
%>\
% if is_request_value_property(mc, p):
<% request_prop_type = prop_type %>\
let ${prop_name} = api::${prop_type}::default();
${self._request_value_impl(c, request_cli_schema, prop_name, request_prop_type)}\
% elif p.type != 'string':
% if p.get('repeated', False):
let ${prop_name}: Vec<${prop_type} = Vec::new();
Expand Down Expand Up @@ -259,9 +259,6 @@ ${value_unwrap}\
}
}
% endif # handle call parameters
% if mc.request_value:
${self._request_value_impl(c, request_cli_schema, request_prop_type)}\
% endif # handle struct parsing
% if mc.media_params:
let protocol =
% for p in mc.media_params:
Expand Down Expand Up @@ -337,7 +334,7 @@ if dry_run {
}\
</%def>

<%def name="_request_value_impl(c, request_cli_schema, request_prop_type)">
<%def name="_request_value_impl(c, request_cli_schema, request_prop_name, request_prop_type)">
<%
allow_optionals_fn = lambda s: is_schema_with_optionals(schema_markers(s, c, transitive=False))
Expand Down Expand Up @@ -384,7 +381,7 @@ if dry_run {
init_fn_map = dict()
flatten_schema_fields(request_cli_schema, schema_fields, init_fn_map)
%>\
let mut request = api::${request_prop_type}::default();
let mut ${request_prop_name} = api::${request_prop_type}::default();
let mut field_name = FieldCursor::default();
for kvarg in ${SOPT + arg_ident(KEY_VALUE_ARG)}.iter() {
let (key, value) = parse_kv_arg(&*kvarg, err, false);
Expand Down Expand Up @@ -446,5 +443,4 @@ ${opt_suffix}\
}
}
}
call = call.request(request);
</%def>

0 comments on commit 0bb30da

Please sign in to comment.