File tree Expand file tree Collapse file tree 3 files changed +29
-12
lines changed Expand file tree Collapse file tree 3 files changed +29
-12
lines changed Original file line number Diff line number Diff line change @@ -371,6 +371,21 @@ impl ArgAction {
371
371
}
372
372
}
373
373
374
+ #[ cfg( debug_assertions) ]
375
+ pub ( crate ) fn max_num_args ( & self ) -> ValueRange {
376
+ match self {
377
+ Self :: Set => ValueRange :: FULL ,
378
+ Self :: Append => ValueRange :: FULL ,
379
+ Self :: SetTrue => ValueRange :: EMPTY ,
380
+ Self :: SetFalse => ValueRange :: EMPTY ,
381
+ Self :: Count => ValueRange :: EMPTY ,
382
+ Self :: Help => ValueRange :: EMPTY ,
383
+ Self :: HelpShort => ValueRange :: EMPTY ,
384
+ Self :: HelpLong => ValueRange :: EMPTY ,
385
+ Self :: Version => ValueRange :: EMPTY ,
386
+ }
387
+ }
388
+
374
389
pub ( crate ) fn default_num_args ( & self ) -> ValueRange {
375
390
match self {
376
391
Self :: Set => ValueRange :: SINGLE ,
Original file line number Diff line number Diff line change @@ -690,15 +690,14 @@ fn assert_arg(arg: &Arg) {
690
690
arg. get_id( ) ,
691
691
) ;
692
692
693
- if arg. is_takes_value_set ( ) {
694
- assert ! (
695
- arg. get_action( ) . takes_values( ) ,
696
- "Argument `{}`'s action {:?} is incompatible with `num_args({:?})`" ,
697
- arg. get_id( ) ,
698
- arg. get_action( ) ,
699
- arg. get_num_args( ) . unwrap_or( 1 . into( ) )
700
- ) ;
701
- }
693
+ assert ! (
694
+ arg. get_num_args( ) . unwrap_or( 1 . into( ) ) . max_values( )
695
+ <= arg. get_action( ) . max_num_args( ) . max_values( ) ,
696
+ "Argument `{}`'s action {:?} is incompatible with `num_args({:?})`" ,
697
+ arg. get_id( ) ,
698
+ arg. get_action( ) ,
699
+ arg. get_num_args( ) . unwrap_or( 1 . into( ) )
700
+ ) ;
702
701
if let Some ( action_type_id) = arg. get_action ( ) . value_type_id ( ) {
703
702
assert_eq ! (
704
703
action_type_id,
Original file line number Diff line number Diff line change @@ -18,6 +18,11 @@ impl ValueRange {
18
18
end_inclusive : 1 ,
19
19
} ;
20
20
21
+ pub ( crate ) const FULL : Self = Self {
22
+ start_inclusive : 0 ,
23
+ end_inclusive : usize:: MAX ,
24
+ } ;
25
+
21
26
/// Create a range
22
27
///
23
28
/// # Panics
@@ -135,9 +140,7 @@ impl From<std::ops::Range<usize>> for ValueRange {
135
140
136
141
impl From < std:: ops:: RangeFull > for ValueRange {
137
142
fn from ( _: std:: ops:: RangeFull ) -> Self {
138
- let start_inclusive = 0 ;
139
- let end_inclusive = usize:: MAX ;
140
- Self :: raw ( start_inclusive, end_inclusive)
143
+ Self :: FULL
141
144
}
142
145
}
143
146
You can’t perform that action at this time.
0 commit comments