1+ #![ allow( unknown_lints) ]
12#![ recursion_limit = "1024" ]
23#![ cfg_attr( feature = "nightly" , feature( start) ) ]
34#![ cfg_attr( feature = "nightly" , feature( alloc_system) ) ]
@@ -212,15 +213,34 @@ fn main() {
212213 :: std:: process:: exit ( 0 ) ;
213214}
214215
216+ #[ allow( needless_pass_by_value) ]
215217fn id_validator ( val : String ) -> StdResult < ( ) , String > {
216218 if val. contains ( ".." ) || val. contains ( '/' ) {
217219 return Err ( format ! ( "id {} may cannot contain '..' or '/'" , val) ) ;
218220 }
219221 Ok ( ( ) )
220222}
223+
221224fn run ( ) -> Result < ( ) > {
225+ let id_arg = Arg :: with_name ( "id" )
226+ . required ( true )
227+ . takes_value ( true )
228+ . validator ( id_validator)
229+ . help ( "Unique identifier" ) ;
230+ let bundle_arg = Arg :: with_name ( "bundle" )
231+ . default_value ( "." )
232+ . required ( true )
233+ . long ( "bundle" )
234+ . short ( "b" ) ;
235+ let pid_arg = Arg :: with_name ( "p" )
236+ . help ( "Additional location to write pid" )
237+ . long ( "pid-file" )
238+ . short ( "p" )
239+ . takes_value ( true ) ;
240+
222241 let matches = App :: new ( "Railcar" )
223242 . about ( "Railcar - run conatiner from oci runtime spec" )
243+ . setting ( AppSettings :: ColoredHelp )
224244 . author ( crate_authors ! ( "\n " ) )
225245 . setting ( AppSettings :: SubcommandRequired )
226246 . version ( crate_version ! ( ) )
@@ -232,115 +252,86 @@ fn run() -> Result<()> {
232252 )
233253 . arg (
234254 Arg :: with_name ( "d" )
235- . help ( "daemonize the process" )
255+ . help ( "Daemonize the process" )
236256 . long ( "daemonize" )
237257 . short ( "d" ) ,
238258 )
239259 . arg (
240260 Arg :: with_name ( "log" )
241- . help ( "compatibility (ignored)" )
261+ . help ( "Compatibility (ignored)" )
242262 . long ( "log" )
243263 . takes_value ( true ) ,
244264 )
245265 . arg (
246266 Arg :: with_name ( "log-format" )
247- . help ( "compatibility (ignored)" )
267+ . help ( "Compatibility (ignored)" )
248268 . long ( "log-format" )
249269 . takes_value ( true ) ,
250270 )
251271 . arg (
252272 Arg :: with_name ( "n" )
253- . help ( "do not create an init process" )
273+ . help ( "Do not create an init process" )
254274 . long ( "no-init" )
255275 . short ( "n" ) ,
256276 )
257277 . arg (
258278 Arg :: with_name ( "o" )
259- . help ( "do not exec process (exits on signal)" )
279+ . help ( "Do not exec process (exits on signal)" )
260280 . long ( "only-init" )
261281 . short ( "o" ) ,
262282 )
263283 . arg (
264284 Arg :: with_name ( "r" )
265285 . default_value ( "/run/railcar" )
266- . help ( "dir for state" )
286+ . help ( "Dir for state" )
267287 . long ( "root" )
268288 . short ( "r" )
269289 . takes_value ( true ) ,
270290 )
271291 . subcommand (
272292 SubCommand :: with_name ( "run" )
273- . arg (
274- Arg :: with_name ( "bundle" )
275- . default_value ( "." )
276- . required ( true )
277- . long ( "bundle" )
278- . short ( "b" ) ,
279- )
280- . arg ( Arg :: with_name ( "id" ) . required ( true ) . takes_value ( true ) )
281- . arg (
282- Arg :: with_name ( "p" )
283- . help ( "additional location to write pid" )
284- . long ( "pid-file" )
285- . short ( "p" )
286- . takes_value ( true ) ,
287- )
288- . help ( "run a container" ) ,
293+ . setting ( AppSettings :: ColoredHelp )
294+ . arg ( & id_arg)
295+ . arg ( & bundle_arg)
296+ . arg ( & pid_arg)
297+ . about ( "Run a container" ) ,
289298 )
290299 . subcommand (
291300 SubCommand :: with_name ( "create" )
292- . arg (
293- Arg :: with_name ( "bundle" )
294- . default_value ( "." )
295- . required ( true )
296- . long ( "bundle" )
297- . short ( "b" ) ,
298- )
301+ . setting ( AppSettings :: ColoredHelp )
302+ . arg ( & id_arg)
303+ . arg ( & bundle_arg)
304+ . arg ( & pid_arg)
299305 . arg (
300306 Arg :: with_name ( "c" )
301307 . help ( "console to use" )
302308 . long ( "console" )
303309 . short ( "c" )
304310 . takes_value ( true ) ,
305311 )
306- . arg ( Arg :: with_name ( "id" ) . required ( true ) . takes_value ( true ) )
307- . arg (
308- Arg :: with_name ( "p" )
309- . help ( "additional location to write pid" )
310- . long ( "pid-file" )
311- . short ( "p" )
312- . takes_value ( true ) ,
313- )
314- . help ( "create a container (to be started later)" ) ,
312+ . about ( "Create a container (to be started later)" ) ,
315313 )
316314 . subcommand (
317315 SubCommand :: with_name ( "start" )
318- . arg ( Arg :: with_name ( "id" ) . required ( true ) . takes_value ( true ) )
319- . help ( "start a (previously created) container" ) ,
316+ . setting ( AppSettings :: ColoredHelp )
317+ . arg ( & id_arg)
318+ . about ( "Start a (previously created) container" ) ,
320319 )
321320 . subcommand (
322321 SubCommand :: with_name ( "state" )
323- . arg (
324- Arg :: with_name ( "id" )
325- . required ( true )
326- . takes_value ( true )
327- . validator ( id_validator) ,
328- )
329- . help (
330- "get the (json) state of a (previously created) container" ,
322+ . setting ( AppSettings :: ColoredHelp )
323+ . arg ( & id_arg)
324+ . about (
325+ "Get the (json) state of a (previously created) container" ,
331326 ) ,
332327 )
333328 . subcommand (
334329 SubCommand :: with_name ( "kill" )
335- . arg (
336- Arg :: with_name ( "id" )
337- . required ( true )
338- . takes_value ( true )
339- . validator ( id_validator) ,
340- )
330+ . setting ( AppSettings :: ColoredHelp )
331+ . arg ( & id_arg)
341332 . arg (
342333 Arg :: with_name ( "a" )
343- . help ( "compatibility (ignored)" )
334+ . help ( "Compatibility (ignored)" )
344335 . long ( "all" )
345336 . short ( "a" )
346337 . takes_value ( true ) ,
@@ -349,36 +340,29 @@ fn run() -> Result<()> {
349340 Arg :: with_name ( "signal" )
350341 . default_value ( "TERM" )
351342 . required ( true )
352- . takes_value ( true ) ,
343+ . takes_value ( true )
344+ . help ( "Signal to send to container" ) ,
353345 )
354- . help ( "signal a (previously created) container") ,
346+ . about ( "Signal a (previously created) container") ,
355347 )
356348 . subcommand (
357349 SubCommand :: with_name ( "delete" )
358- . arg (
359- Arg :: with_name ( "id" )
360- . required ( true )
361- . takes_value ( true )
362- . validator ( id_validator) ,
363- )
364- . help ( "delete a (previously created) container" ) ,
350+ . setting ( AppSettings :: ColoredHelp )
351+ . arg ( & id_arg)
352+ . about ( "Delete a (previously created) container" ) ,
365353 )
366354 . subcommand (
367355 SubCommand :: with_name ( "ps" )
368- . arg (
369- Arg :: with_name ( "id" )
370- . required ( true )
371- . takes_value ( true )
372- . validator ( id_validator) ,
373- )
356+ . setting ( AppSettings :: ColoredHelp )
357+ . arg ( & id_arg)
374358 . arg (
375359 Arg :: with_name ( "f" )
376- . help ( "compatibility (ignored)" )
360+ . help ( "Compatibility (ignored)" )
377361 . long ( "format" )
378362 . short ( "f" )
379363 . takes_value ( true ) ,
380364 )
381- . help ( "list processes in a (previously created) container") ,
365+ . about ( "List processes in a (previously created) container") ,
382366 )
383367 . get_matches_from ( get_args ( ) ) ;
384368 let level = match matches. occurrences_of ( "v" ) {
0 commit comments