@@ -322,21 +322,31 @@ fn get_args_of(p: &Parser) -> String {
322
322
ret. join ( "\n " )
323
323
}
324
324
325
- // Escape string inside single quotes and brackets
326
- fn escape_string ( string : & str ) -> String {
325
+ // Escape help string inside single quotes and brackets
326
+ fn escape_help ( string : & str ) -> String {
327
327
string
328
328
. replace ( "\\ " , "\\ \\ " )
329
329
. replace ( "'" , "'\\ ''" )
330
330
. replace ( "[" , "\\ [" )
331
331
. replace ( "]" , "\\ ]" )
332
332
}
333
333
334
+ // Escape value string inside single quotes and parentheses
335
+ fn escape_value ( string : & str ) -> String {
336
+ string
337
+ . replace ( "\\ " , "\\ \\ " )
338
+ . replace ( "'" , "'\\ ''" )
339
+ . replace ( "(" , "\\ (" )
340
+ . replace ( ")" , "\\ )" )
341
+ . replace ( " " , "\\ " )
342
+ }
343
+
334
344
fn write_opts_of ( p : & Parser ) -> String {
335
345
debugln ! ( "write_opts_of;" ) ;
336
346
let mut ret = vec ! [ ] ;
337
347
for o in p. opts ( ) {
338
348
debugln ! ( "write_opts_of:iter: o={}" , o. name( ) ) ;
339
- let help = o. help ( ) . map_or ( String :: new ( ) , escape_string ) ;
349
+ let help = o. help ( ) . map_or ( String :: new ( ) , escape_help ) ;
340
350
let mut conflicts = get_zsh_arg_conflicts ! ( p, o, INTERNAL_ERROR_MSG ) ;
341
351
conflicts = if conflicts. is_empty ( ) {
342
352
String :: new ( )
@@ -390,7 +400,7 @@ fn write_flags_of(p: &Parser) -> String {
390
400
let mut ret = vec ! [ ] ;
391
401
for f in p. flags ( ) {
392
402
debugln ! ( "write_flags_of:iter: f={}" , f. name( ) ) ;
393
- let help = f. help ( ) . map_or ( String :: new ( ) , escape_string ) ;
403
+ let help = f. help ( ) . map_or ( String :: new ( ) , escape_help ) ;
394
404
let mut conflicts = get_zsh_arg_conflicts ! ( p, f, INTERNAL_ERROR_MSG ) ;
395
405
conflicts = if conflicts. is_empty ( ) {
396
406
String :: new ( )
@@ -439,14 +449,18 @@ fn write_positionals_of(p: &Parser) -> String {
439
449
for arg in p. positionals ( ) {
440
450
debugln ! ( "write_positionals_of:iter: arg={}" , arg. b. name) ;
441
451
let a = format ! (
442
- "\" {optional}:{name}{help}:_files \" \\ " ,
452
+ "' {optional}:{name}{help}:{action}' \\ " ,
443
453
optional = if !arg. b. is_set( ArgSettings :: Required ) { ":" } else { "" } ,
444
454
name = arg. b. name,
445
455
help = arg. b
446
456
. help
447
457
. map_or( "" . to_owned( ) , |v| " -- " . to_owned( ) + v)
448
458
. replace( "[" , "\\ [" )
449
- . replace( "]" , "\\ ]" )
459
+ . replace( "]" , "\\ ]" ) ,
460
+ action = arg. possible_vals( ) . map_or( "_files" . to_owned( ) , |values| {
461
+ format!( "({})" ,
462
+ values. iter( ) . map( |v| escape_value( * v) ) . collect:: <Vec <String >>( ) . join( " " ) )
463
+ } )
450
464
) ;
451
465
452
466
debugln ! ( "write_positionals_of:iter: Wrote...{}" , a) ;
0 commit comments