@@ -1559,21 +1559,25 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{
1559
1559
-> ClapError {
1560
1560
let msg = match error_type {
1561
1561
ClapErrorType :: ArgumentError => {
1562
+ assert_eq ! ( data. len( ) , 1 ) ;
1562
1563
format ! ( "{}" , data[ 0 ] . as_ref( ) )
1563
1564
} ,
1564
1565
ClapErrorType :: InvalidValue => {
1566
+ assert_eq ! ( data. len( ) , 4 ) ;
1565
1567
format ! ( "'{}' isn't a valid value for '{}'{}{}" ,
1566
1568
Format :: Warning ( data[ 0 ] . as_ref( ) ) ,
1567
1569
Format :: Warning ( data[ 1 ] . as_ref( ) ) ,
1568
1570
format!( "\n \t [valid values:{}]\n " , data[ 2 ] . as_ref( ) ) ,
1569
1571
data[ 3 ] . as_ref( ) )
1570
1572
} ,
1571
1573
ClapErrorType :: InvalidArgument => {
1574
+ assert_eq ! ( data. len( ) , 2 ) ;
1572
1575
format ! ( "The argument '{}' isn't valid{}" ,
1573
1576
Format :: Warning ( data[ 0 ] . as_ref( ) ) ,
1574
1577
data[ 1 ] . as_ref( ) )
1575
1578
} ,
1576
1579
ClapErrorType :: InvalidSubcommand => {
1580
+ assert_eq ! ( data. len( ) , 2 ) ;
1577
1581
format ! ( "The subcommand '{}' isn't valid\n \t Did you mean '{}' ?\n \n \
1578
1582
If you received this message in error, try \
1579
1583
re-running with '{} {} {}'",
@@ -1584,37 +1588,46 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{
1584
1588
data[ 0 ] . as_ref( ) )
1585
1589
} ,
1586
1590
ClapErrorType :: EmptyValue => {
1591
+ assert_eq ! ( data. len( ) , 1 ) ;
1587
1592
format ! ( "The argument '{}' requires a value but none was supplied" ,
1588
1593
Format :: Warning ( data[ 0 ] . as_ref( ) ) )
1589
1594
} ,
1590
- ClapErrorType :: ValueValidationError => data[ 0 ] . as_ref ( ) . to_owned ( ) ,
1595
+ ClapErrorType :: ValueValidationError => {
1596
+ assert_eq ! ( data. len( ) , 1 ) ;
1597
+ data[ 0 ] . as_ref ( ) . to_owned ( )
1598
+ } ,
1591
1599
ClapErrorType :: TooManyArgs => {
1600
+ assert_eq ! ( data. len( ) , 2 ) ;
1592
1601
format ! ( "The argument '{}' was found, but '{}' wasn't expecting any more values" ,
1593
1602
Format :: Warning ( data[ 0 ] . as_ref( ) ) ,
1594
1603
Format :: Warning ( data[ 1 ] . as_ref( ) ) )
1595
1604
} ,
1596
1605
ClapErrorType :: TooFewValues => {
1606
+ assert_eq ! ( data. len( ) , 4 ) ;
1597
1607
format ! ( "The argument '{}' requires at least {} values, but {} w{} provided" ,
1598
1608
Format :: Warning ( data[ 0 ] . as_ref( ) ) ,
1599
1609
Format :: Good ( data[ 1 ] . as_ref( ) ) ,
1600
1610
Format :: Error ( data[ 2 ] . as_ref( ) ) ,
1601
1611
data[ 3 ] . as_ref( ) )
1602
1612
} ,
1603
1613
ClapErrorType :: TooManyValues => {
1614
+ assert_eq ! ( data. len( ) , 4 ) ;
1604
1615
format ! ( "The argument '{}' only requires {} values, but {} w{} provided" ,
1605
1616
Format :: Warning ( data[ 0 ] . as_ref( ) ) ,
1606
1617
Format :: Good ( data[ 1 ] . as_ref( ) ) ,
1607
1618
Format :: Error ( data[ 2 ] . as_ref( ) ) ,
1608
1619
data[ 3 ] . as_ref( ) )
1609
1620
} ,
1610
1621
ClapErrorType :: WrongNumValues => {
1622
+ assert_eq ! ( data. len( ) , 4 ) ;
1611
1623
format ! ( "The argument '{}' requires {} values, but {} w{} provided" ,
1612
1624
Format :: Warning ( data[ 0 ] . as_ref( ) ) ,
1613
1625
Format :: Good ( data[ 1 ] . as_ref( ) ) ,
1614
1626
Format :: Error ( data[ 2 ] . as_ref( ) ) ,
1615
1627
data[ 3 ] . as_ref( ) )
1616
1628
} ,
1617
1629
ClapErrorType :: ArgumentConflict => {
1630
+ assert_eq ! ( data. len( ) , 2 ) ;
1618
1631
format ! ( "The argument '{}' cannot be used with {}" ,
1619
1632
Format :: Warning ( data[ 0 ] . as_ref( ) ) ,
1620
1633
match self . blacklisted_from( data[ 1 ] . as_ref( ) , & matches) {
@@ -1624,6 +1637,8 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{
1624
1637
} )
1625
1638
} ,
1626
1639
ClapErrorType :: MissingRequiredArgument => {
1640
+ // Callers still use &[""]
1641
+ assert_eq ! ( data. len( ) , 1 ) ;
1627
1642
format ! ( "The following required arguments were not supplied:{}" ,
1628
1643
self . get_required_from( self . required. iter( )
1629
1644
. map( |s| * s)
@@ -1634,21 +1649,26 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{
1634
1649
Format :: Error ( s) ) [ ..] ) )
1635
1650
} ,
1636
1651
ClapErrorType :: MissingSubcommand => {
1652
+ assert_eq ! ( data. len( ) , 1 ) ;
1637
1653
format ! ( "'{}' requires a subcommand but none was provided" ,
1638
1654
Format :: Warning ( data[ 0 ] . as_ref( ) ) )
1639
1655
} ,
1640
1656
ClapErrorType :: MissingArgumentOrSubcommand => "" . to_owned ( ) ,
1641
1657
ClapErrorType :: UnexpectedArgument => {
1658
+ assert_eq ! ( data. len( ) , 1 ) ;
1642
1659
format ! ( "Found argument '{}', but {} wasn't expecting any" ,
1643
1660
Format :: Warning ( data[ 0 ] . as_ref( ) ) ,
1644
1661
self . bin_name. as_ref( ) . unwrap_or( & self . name) )
1645
1662
} ,
1646
1663
ClapErrorType :: UnexpectedMultipleUsage => {
1664
+ assert_eq ! ( data. len( ) , 1 ) ;
1647
1665
format ! ( "The argument '{}' was supplied more \
1648
1666
than once, but does not support multiple values",
1649
1667
Format :: Warning ( data[ 0 ] . as_ref( ) ) )
1650
1668
} ,
1651
1669
ClapErrorType :: InvalidUnicode => {
1670
+ // Callers still use &[""]
1671
+ assert_eq ! ( data. len( ) , 1 ) ;
1652
1672
"Invalid unicode character in one or more arguments" . to_owned ( )
1653
1673
}
1654
1674
} ;
@@ -3173,7 +3193,7 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{
3173
3193
if !b {
3174
3194
return Err (
3175
3195
self . create_error (
3176
- & [ & * format ! ( "-{}" , c) ] ,
3196
+ & [ & * format ! ( "-{}" , c) , "" ] ,
3177
3197
ClapErrorType :: InvalidArgument ,
3178
3198
matches) ) ;
3179
3199
}
0 commit comments