77
88 def rust_boolean (v ):
99 return v and ' true' or ' false'
10+
11+ def rust_optional (v ):
12+ if v is None :
13+ return ' None'
14+ if isinstance (v, bool ):
15+ v = v and ' true' or ' false'
16+ elif isinstance (v, basestring ):
17+ v = ' "%s "' % v
18+ return ' Some(%s )' % v
1019%> \
1120<%def name = "grammar(c ) "> \
1221% for resource in sorted (c.rta_map.keys()):
@@ -109,7 +118,7 @@ Configuration:
109118 None
110119 ))
111120%> \
112- App::new("${ util.program_name()} ")
121+ let mut app = App::new("${ util.program_name()} ")
113122<%block filter =" indent_by(7)" > \
114123.author("${ ' , ' .join(cargo.authors)} ")
115124.version("${ cargo.build_version} ")
@@ -121,11 +130,17 @@ App::new("${util.program_name()}")
121130.arg(Arg::with_name("${ arg_name or flag} ")
122131 .long("${ flag} ")
123132 .help("${ desc} ")
124- .takes_value(${ rust_boolean(arg_name)} ))
133+ .takes_value(${ rust_boolean(arg_name)} ))\
134+ % if loop.last:
135+ ;
136+ % else :
137+
138+ % endif
125139% endfor
140+ let arg_data = [
126141% for resource in sorted (c.rta_map.keys()):
127- .subcommand(
128- SubCommand::new ("${ mangle_subcommand(resource)} ")
142+ <% block filter = " indent_by(4) " > \
143+ ("${ mangle_subcommand(resource)} ", vec![
129144 % for method in sorted (c.rta_map[resource]):
130145<%
131146 mc = new_method_context(resource, method, c)
@@ -193,30 +208,23 @@ App::new("${util.program_name()}")
193208 ))
194209 # handle output
195210%> \
196- .subcommand(
197- SubCommand::new("${ mangle_subcommand(method)} ")
198- % if mc.m.get(' description' ) is not None :
199- .about("${ mc.m.description} ")
200- % endif
211+ ("${ mangle_subcommand(method)} ", ${ rust_optional(mc.m.get(' description' ))} ,
212+ vec![
201213 % for flag, desc, arg_name, required, multi in args:
202- .arg(
203- Arg::with_name("${ arg_name or flag} ")
204- % if flag:
205- .short("${ flag} ")
206- % endif
207- % if desc:
208- .help("${ desc} ")
209- % endif
210- % if flag is not None :
211- .takes_value(${ rust_boolean(arg_name)} )
212- % endif
213- .required(${ rust_boolean(required)} )
214- .multiple(${ rust_boolean(multi)} ))
214+ (${ rust_optional(arg_name)} ,
215+ ${ rust_optional(flag)} ,
216+ ${ rust_optional(desc)} ,
217+ ${ rust_optional(required)} ,
218+ ${ rust_optional(multi)} ),
219+ % if not loop.last:
220+
221+ % endif
215222 % endfor
216- )
223+ ]),
217224 % endfor # each method
218- )
225+ ]),
226+ </%block >
219227% endfor # end for each resource
220- .get_matches() ;
228+ ] ;
221229</%block >
222230</%def >
0 commit comments