@@ -1152,17 +1152,17 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{
1152
1152
// Reports and error to the users screen along with an optional usage statement and quits
1153
1153
#[ cfg( not( feature = "color" ) ) ]
1154
1154
fn report_error ( & self , msg : String , usage : bool , quit : bool , matches : Option < Vec < & str > > ) {
1155
- println ! ( "{}" , msg) ;
1155
+ println ! ( "{}\n " , msg) ;
1156
1156
if usage { self . print_usage ( true , matches) ; }
1157
1157
if quit { self . exit ( 1 ) ; }
1158
1158
}
1159
1159
1160
1160
#[ cfg( feature = "color" ) ]
1161
1161
fn report_error ( & self , msg : String , usage : bool , quit : bool , matches : Option < Vec < & str > > ) {
1162
- println ! ( "{}" , Red . paint( & msg[ ..] ) ) ;
1162
+ println ! ( "{}\n " , Red . paint( & msg[ ..] ) ) ;
1163
1163
if usage {
1164
- print ! ( "{}" , Red . paint ( & self . create_usage( matches) [ ..] ) ) ;
1165
- println ! ( "{}" , Red . paint ( " \ n For more information try --help") ) ;
1164
+ print ! ( "{}" , & self . create_usage( matches) [ ..] ) ;
1165
+ println ! ( "{}" , " \n \ n For more information try --help") ;
1166
1166
}
1167
1167
if quit { self . exit ( 1 ) ; }
1168
1168
}
@@ -1233,7 +1233,7 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{
1233
1233
1234
1234
/// Returns a suffix that can be empty, or is the standard 'did you mean phrase
1235
1235
fn did_you_mean_suffix < ' z , T , I > ( arg : & str , values : I , style : DidYouMeanMessageStyle )
1236
- -> String
1236
+ -> ( String , Option < & ' z str > )
1237
1237
where T : AsRef < str > + ' z ,
1238
1238
I : IntoIterator < Item =& ' z T > {
1239
1239
match did_you_mean ( arg, values) {
@@ -1248,9 +1248,9 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{
1248
1248
suffix. push ( '\'' ) ;
1249
1249
}
1250
1250
suffix. push_str ( " ?" ) ;
1251
- suffix
1251
+ ( suffix, Some ( candidate ) )
1252
1252
} ,
1253
- None => String :: new ( ) ,
1253
+ None => ( String :: new ( ) , None ) ,
1254
1254
}
1255
1255
}
1256
1256
@@ -1267,7 +1267,7 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{
1267
1267
. fold( String :: new( ) , |acc, name| {
1268
1268
acc + & format!( " {}" , name) [ ..]
1269
1269
} ) ) ,
1270
- suffix) ,
1270
+ suffix. 0 ) ,
1271
1271
true ,
1272
1272
true ,
1273
1273
Some ( matches. args . keys ( ) . map ( |k| * k) . collect ( ) ) ) ;
@@ -1283,7 +1283,7 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{
1283
1283
while let Some ( arg) = it. next ( ) {
1284
1284
let arg_slice = & arg[ ..] ;
1285
1285
let mut skip = false ;
1286
- if !pos_only && !arg_slice. starts_with ( "-" ) {
1286
+ if !pos_only && !arg_slice. starts_with ( "-" ) && ! self . subcommands . contains_key ( arg_slice ) {
1287
1287
if let Some ( nvo) = needs_val_of {
1288
1288
if let Some ( ref opt) = self . opts . get ( nvo) {
1289
1289
if let Some ( ref p_vals) = opt. possible_vals {
@@ -1349,7 +1349,7 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{
1349
1349
if let Some ( ref o) = self . opts . get ( name) {
1350
1350
if !o. multiple {
1351
1351
self . report_error (
1352
- format ! ( "Argument '{}' requires a value but none was supplied" , o) ,
1352
+ format ! ( "The argument '{}' requires a value but none was supplied" , o) ,
1353
1353
true ,
1354
1354
true ,
1355
1355
Some ( matches. args . keys ( ) . map ( |k| * k) . collect ( ) ) ) ;
@@ -1384,7 +1384,7 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{
1384
1384
self . report_error (
1385
1385
format ! ( "The subcommand '{}' isn't valid\n \t Did you mean '{}' ?\n \n \
1386
1386
If you received this message in error, try \
1387
- re-running with '{} -- {}'\n ",
1387
+ re-running with '{} -- {}'",
1388
1388
arg,
1389
1389
candidate_subcommand,
1390
1390
self . bin_name. clone( ) . unwrap_or( self . name. clone( ) ) ,
@@ -1512,34 +1512,35 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{
1512
1512
} ;
1513
1513
if should_err {
1514
1514
self . report_error (
1515
- format ! ( "Argument '{}' requires a value but none was supplied" , o) ,
1515
+ format ! ( "The argument '{}' requires a value but none was \
1516
+ supplied", o) ,
1516
1517
true ,
1517
1518
true ,
1518
1519
Some ( matches. args . keys ( ) . map ( |k| * k) . collect ( ) ) ) ;
1519
1520
}
1520
1521
}
1521
1522
else if !o. multiple {
1522
1523
self . report_error (
1523
- format ! ( "Argument '{}' requires a value but none was supplied" , o) ,
1524
+ format ! ( "The argument '{}' requires a value but none was supplied" , o) ,
1524
1525
true ,
1525
1526
true ,
1526
1527
Some ( matches. args . keys ( ) . map ( |k| * k) . collect ( ) ) ) ;
1527
1528
}
1528
1529
else {
1529
1530
self . report_error ( format ! ( "The following required arguments were not \
1530
- supplied:\n {}",
1531
+ supplied:{}",
1531
1532
self . get_required_from( self . required. iter( )
1532
1533
. map( |s| * s)
1533
1534
. collect:: <HashSet <_>>( ) )
1534
1535
. iter( )
1535
- . fold( String :: new( ) , |acc, s| acc + & format!( "\t '{}'\n " , s) [ ..] ) ) ,
1536
+ . fold( String :: new( ) , |acc, s| acc + & format!( "\n \ t '{}'" , s) [ ..] ) ) ,
1536
1537
true ,
1537
1538
true ,
1538
1539
Some ( matches. args . keys ( ) . map ( |k| * k) . collect ( ) ) ) ;
1539
1540
}
1540
1541
} else {
1541
1542
self . report_error (
1542
- format ! ( "Argument '{}' requires a value but none was supplied" ,
1543
+ format ! ( "The argument '{}' requires a value but none was supplied" ,
1543
1544
format!( "{}" , self . positionals_idx. get(
1544
1545
self . positionals_name. get( a) . unwrap( ) ) . unwrap( ) ) ) ,
1545
1546
true ,
@@ -1556,12 +1557,12 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{
1556
1557
if !self . required . is_empty ( ) {
1557
1558
if self . validate_required ( & matches) {
1558
1559
self . report_error ( format ! ( "The following required arguments were not \
1559
- supplied:\n {}",
1560
+ supplied:{}",
1560
1561
self . get_required_from( self . required. iter( )
1561
1562
. map( |s| * s)
1562
1563
. collect:: <HashSet <_>>( ) )
1563
1564
. iter( )
1564
- . fold( String :: new( ) , |acc, s| acc + & format!( "\t '{}'\n " , s) [ ..] ) ) ,
1565
+ . fold( String :: new( ) , |acc, s| acc + & format!( "\n \ t '{}'" , s) [ ..] ) ) ,
1565
1566
true ,
1566
1567
true ,
1567
1568
Some ( matches. args . keys ( ) . map ( |k| * k) . collect ( ) ) ) ;
@@ -1683,8 +1684,8 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{
1683
1684
arg = arg_vec[ 0 ] ;
1684
1685
// prevents "--config= value" typo
1685
1686
if arg_vec[ 1 ] . len ( ) == 0 {
1686
- self . report_error ( format ! ( "Argument --{} requires a value, but none was supplied" ,
1687
- arg) ,
1687
+ self . report_error ( format ! ( "The argument --{} requires a value, but none was \
1688
+ supplied" , arg) ,
1688
1689
true ,
1689
1690
true ,
1690
1691
Some ( matches. args . keys ( ) . map ( |k| * k) . collect ( ) ) ) ;
@@ -1705,7 +1706,7 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{
1705
1706
1706
1707
if matches. args . contains_key ( v. name ) {
1707
1708
if !v. multiple {
1708
- self . report_error ( format ! ( "Argument --{} was supplied more than once, but \
1709
+ self . report_error ( format ! ( "The argument --{} was supplied more than once, but \
1709
1710
does not support multiple values", arg) ,
1710
1711
true ,
1711
1712
true ,
@@ -1788,7 +1789,7 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{
1788
1789
1789
1790
// Make sure this isn't one being added multiple times if it doesn't suppor it
1790
1791
if matches. args . contains_key ( v. name ) && !v. multiple {
1791
- self . report_error ( format ! ( "Argument '{}' was supplied more than once, but does \
1792
+ self . report_error ( format ! ( "The argument '{}' was supplied more than once, but does \
1792
1793
not support multiple values", v) ,
1793
1794
true ,
1794
1795
true ,
@@ -1835,27 +1836,40 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{
1835
1836
return None ;
1836
1837
}
1837
1838
1838
- let mut suffix = App :: did_you_mean_suffix ( arg, self . opts . values ( )
1839
- . filter_map ( |v|
1840
- if let Some ( ref l) = v. long {
1841
- Some ( l)
1842
- } else {
1843
- None
1844
- }
1845
- ) , DidYouMeanMessageStyle :: LongFlag ) ;
1846
-
1847
- // If it didn't find a good match for opts, try flags
1848
- if suffix. is_empty ( ) {
1849
- suffix = App :: did_you_mean_suffix ( arg, self . flags . values ( )
1850
- . filter_map ( |v|
1851
- if let Some ( ref l) = v. long {
1852
- Some ( l)
1853
- } else {
1854
- None
1855
- }
1856
- ) , DidYouMeanMessageStyle :: LongFlag ) ;
1857
- }
1858
- self . report_error ( format ! ( "The argument --{} isn't valid{}" , arg, suffix) ,
1839
+ let suffix = App :: did_you_mean_suffix ( arg,
1840
+ self . long_list . iter ( ) ,
1841
+ DidYouMeanMessageStyle :: LongFlag ) ;
1842
+ if let Some ( name) = suffix. 1 {
1843
+ if let Some ( ref opt) = self . opts . values ( )
1844
+ . filter_map ( |ref o| {
1845
+ if o. long . is_some ( ) && o. long . unwrap ( ) == name {
1846
+ Some ( o. name )
1847
+ } else {
1848
+ None
1849
+ }
1850
+ } )
1851
+ . next ( ) {
1852
+ matches. args . insert ( opt, MatchedArg {
1853
+ occurrences : 0 ,
1854
+ values : None
1855
+ } ) ;
1856
+ } else if let Some ( ref flg) = self . flags . values ( )
1857
+ . filter_map ( |ref f| {
1858
+ if f. long . is_some ( ) && f. long . unwrap ( ) == name {
1859
+ Some ( f. name )
1860
+ } else {
1861
+ None
1862
+ }
1863
+ } )
1864
+ . next ( ) {
1865
+ matches. args . insert ( flg, MatchedArg {
1866
+ occurrences : 0 ,
1867
+ values : None
1868
+ } ) ;
1869
+ }
1870
+ }
1871
+
1872
+ self . report_error ( format ! ( "The argument --{} isn't valid{}" , arg, suffix. 0 ) ,
1859
1873
true ,
1860
1874
true ,
1861
1875
Some ( matches. args . keys ( ) . map ( |k| * k) . collect ( ) ) ) ;
0 commit comments