66 cmd_ident, call_method_ident, arg_ident, POD_TYPES )
77
88 v_arg = ' <%s >' % VALUE_ARG
9+ def to_opt_ident (p ):
10+ return ' self.opt.' + arg_ident(p.name)
911%> \
1012<%def name = "new(c ) "> \
1113<%
1214 hub_type_name = ' api::' + hub_type(c.schemas, util.canonical_name())
1315%> \
1416mod cmn;
15- use cmn::{InvalidOptionsError, CLIError, JsonTokenStorage};
17+ use cmn::{InvalidOptionsError, CLIError, JsonTokenStorage, arg_from_str };
1618use std::default::Default;
1719use std::str::FromStr;
1820
@@ -126,35 +128,26 @@ self.opt.${cmd_ident(method)} {
126128<%
127129 prop_name = mangle_ident(p.name)
128130 prop_type = activity_rust_type(c.schemas, p, allow_optionals = False )
129- opt_ident = ' self.opt. ' + arg_ident(p.name )
131+ opt_ident = to_opt_ident(p )
130132%> \
131133 % if is_request_value_property(mc, p):
132134let ${ prop_name} : api::${ prop_type} = Default::default();
133- % else :
134- let ${ prop_name} : ${ prop_type} = \
135- % if p.type == ' string' :
136- ${ opt_ident} .clone();
137- % else :
138-
139- match FromStr::from_str(& ${ opt_ident} ) {
140- Err(perr) => {
141- err.issues.push(CLIError::ParseError(format!("Failed to parse argument <${ mangle_subcommand(p.name)} > as ${ p.type} with error: {}", perr)));
142- Default::default()
143- },
144- Ok(v) => v,
145- };
146- % endif # handle argument type
135+ % elif p.type != ' string' :
136+ let ${ prop_name} : ${ prop_type} = arg_from_str(& ${ opt_ident} , err, "<${ mangle_subcommand(p.name)} >", "${ p.type} ");
147137 % endif # handle request value
148138% endfor # each required parameter
149139<%
150140 call_args = list ()
151141 for p in mc.required_props:
152142 borrow = ' '
153143 # if type is not available, we know it's the request value, which should also be borrowed
154- ptype = p.get(' type' , ' string ' )
155- if ptype not in POD_TYPES or ptype == ' string' :
144+ ptype = p.get(' type' , None )
145+ if ptype not in POD_TYPES or ptype in ( ' string' , None ) :
156146 borrow = ' &'
157- call_args.append(borrow + mangle_ident(p.name))
147+ arg_name = mangle_ident(p.name)
148+ if ptype == ' string' :
149+ arg_name = to_opt_ident(p)
150+ call_args.append(borrow + arg_name)
158151 # end for each required prop
159152%> \
160153let call = self.hub.${ mangle_ident(resource)} ().${ mangle_ident(method)} (${ ' , ' .join(call_args)} );
@@ -163,6 +156,7 @@ let call = self.hub.${mangle_ident(resource)}().${mangle_ident(method)}(${', '.j
163156if dry_run {
164157 None
165158} else {
159+ assert!(err.issues.len() == 0);
166160 ## Make the call, handle uploads, handle downloads (also media downloads|json decoding)
167161 ## TODO: unify error handling
168162 % if mc.media_params:
0 commit comments