@@ -2161,7 +2161,10 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{
2161
2161
// Make sure this one doesn't conflict with anything
2162
2162
self . blacklist . dedup ( ) ;
2163
2163
if self . blacklist . contains ( & p. name ) {
2164
- matches. args . remove ( p. name ) ;
2164
+ // we shouldn't need to remove this arg...since it should be matched yet
2165
+ // anyways
2166
+ // matches.args.remove(p.name);
2167
+
2165
2168
self . report_error ( format ! ( "The argument '{}' cannot be used with {}" ,
2166
2169
Format :: Warning ( p. to_string( ) ) ,
2167
2170
match self . blacklisted_from( p. name, & matches) {
@@ -2173,6 +2176,7 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{
2173
2176
Some ( matches. args . keys ( ) . map ( |k| * k) . collect ( ) ) ) ;
2174
2177
}
2175
2178
2179
+
2176
2180
if let Some ( ref p_vals) = p. possible_vals {
2177
2181
if !p_vals. is_empty ( ) {
2178
2182
if !p_vals. contains ( arg_slice) {
@@ -2181,6 +2185,7 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{
2181
2185
}
2182
2186
}
2183
2187
}
2188
+
2184
2189
// Have we made the update yet?
2185
2190
let mut done = false ;
2186
2191
if p. multiple {
@@ -2216,12 +2221,27 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{
2216
2221
vals. insert ( len, arg_slice. to_owned ( ) ) ;
2217
2222
}
2218
2223
}
2224
+
2219
2225
} else {
2220
2226
// Only increment the positional counter if it doesn't allow multiples
2221
2227
pos_counter += 1 ;
2222
2228
}
2223
2229
// Was an update made, or is this the first occurrence?
2224
2230
if !done {
2231
+ self . overrides . dedup ( ) ;
2232
+ if self . overrides . contains ( & p. name ) {
2233
+ if let Some ( name) = self . overriden_from ( p. name , matches) {
2234
+ matches. args . remove ( & * name) ;
2235
+ remove_override ! ( self , & * name) ;
2236
+ }
2237
+ }
2238
+ if let Some ( ref or) = p. overrides {
2239
+ for pa in or {
2240
+ matches. args . remove ( pa) ;
2241
+ remove_override ! ( self , pa) ;
2242
+ self . overrides . push ( pa) ;
2243
+ }
2244
+ }
2225
2245
let mut bm = BTreeMap :: new ( ) ;
2226
2246
if !p. empty_vals && arg_slice. is_empty ( ) {
2227
2247
self . report_error ( format ! ( "The argument '{}' does not allow empty \
@@ -2243,29 +2263,29 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{
2243
2263
occurrences : 1 ,
2244
2264
values : Some ( bm) ,
2245
2265
} ) ;
2246
- }
2247
2266
2248
- if let Some ( ref bl) = p. blacklist {
2249
- for name in bl {
2250
- self . blacklist . push ( name) ;
2251
- vec_remove ! ( self . required, name) ;
2267
+ if let Some ( ref bl) = p. blacklist {
2268
+ for name in bl {
2269
+ self . blacklist . push ( name) ;
2270
+ vec_remove ! ( self . required, name) ;
2271
+ }
2252
2272
}
2253
- }
2254
2273
2255
- // Because of the macro call, we have to create a temp variable
2256
- let pname = & p. name ;
2257
- vec_remove ! ( self . required, pname) ;
2258
- if let Some ( ref reqs) = p. requires {
2259
- // Add all required args which aren't already found in matches to the
2260
- // final required list
2261
- for n in reqs {
2262
- if matches. args . contains_key ( n) { continue ; }
2274
+ // Because of the macro call, we have to create a temp variable
2275
+ let pname = & p. name ;
2276
+ vec_remove ! ( self . required, pname) ;
2277
+ if let Some ( ref reqs) = p. requires {
2278
+ // Add all required args which aren't already found in matches to the
2279
+ // final required list
2280
+ for n in reqs {
2281
+ if matches. args . contains_key ( n) { continue ; }
2263
2282
2264
- self . required . push ( n) ;
2283
+ self . required . push ( n) ;
2284
+ }
2265
2285
}
2266
- }
2267
2286
2268
- parse_group_reqs ! ( self , p) ;
2287
+ parse_group_reqs ! ( self , p) ;
2288
+ }
2269
2289
2270
2290
} else {
2271
2291
self . report_error ( format ! ( "The argument '{}' was found, but '{}' wasn't \
@@ -2323,7 +2343,6 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{
2323
2343
self . validate_blacklist ( matches) ;
2324
2344
self . validate_num_args ( matches) ;
2325
2345
2326
-
2327
2346
matches. usage = Some ( self . create_usage ( None ) ) ;
2328
2347
2329
2348
if let Some ( sc_name) = subcmd_name {
@@ -2422,6 +2441,35 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{
2422
2441
None
2423
2442
}
2424
2443
2444
+ fn overriden_from ( & self , name : & ' ar str , matches : & ArgMatches ) -> Option < & ' ar str > {
2445
+ for k in matches. args . keys ( ) {
2446
+ if let Some ( f) = self . flags . get ( k) {
2447
+ if let Some ( ref bl) = f. overrides {
2448
+ if bl. contains ( & name) {
2449
+ return Some ( f. name )
2450
+ }
2451
+ }
2452
+ }
2453
+ if let Some ( o) = self . opts . get ( k) {
2454
+ if let Some ( ref bl) = o. overrides {
2455
+ if bl. contains ( & name) {
2456
+ return Some ( o. name )
2457
+ }
2458
+ }
2459
+ }
2460
+ if let Some ( idx) = self . positionals_name . get ( k) {
2461
+ if let Some ( pos) = self . positionals_idx . get ( idx) {
2462
+ if let Some ( ref bl) = pos. overrides {
2463
+ if bl. contains ( & name) {
2464
+ return Some ( pos. name )
2465
+ }
2466
+ }
2467
+ }
2468
+ }
2469
+ }
2470
+ None
2471
+ }
2472
+
2425
2473
fn create_help_and_version ( & mut self ) {
2426
2474
// name is "hclap_help" because flags are sorted by name
2427
2475
if self . needs_long_help {
@@ -2522,8 +2570,12 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{
2522
2570
true ,
2523
2571
Some ( matches. args . keys ( ) . map ( |k| * k) . collect ( ) ) ) ;
2524
2572
}
2525
- if self . overrides . contains ( & v. name ) {
2526
- matches. args . remove ( v. name ) ;
2573
+ if let Some ( ref or) = v. overrides {
2574
+ for pa in or {
2575
+ matches. args . remove ( pa) ;
2576
+ remove_override ! ( self , pa) ;
2577
+ self . overrides . push ( pa) ;
2578
+ }
2527
2579
}
2528
2580
2529
2581
if matches. args . contains_key ( v. name ) {
@@ -2594,12 +2646,6 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{
2594
2646
}
2595
2647
} ) ;
2596
2648
}
2597
- if let Some ( ref ov) = v. overrides {
2598
- for name in ov {
2599
- self . overrides . push ( name) ;
2600
- vec_remove ! ( self . required, name) ;
2601
- }
2602
- }
2603
2649
if let Some ( ref bl) = v. blacklist {
2604
2650
for name in bl {
2605
2651
self . blacklist . push ( name) ;
@@ -2645,9 +2691,12 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{
2645
2691
true ,
2646
2692
Some ( matches. args . keys ( ) . map ( |k| * k) . collect ( ) ) ) ;
2647
2693
}
2648
- self . overrides . dedup ( ) ;
2649
- if self . overrides . contains ( & v. name ) {
2650
- matches. args . remove ( v. name ) ;
2694
+ if let Some ( ref or) = v. overrides {
2695
+ for pa in or {
2696
+ matches. args . remove ( pa) ;
2697
+ remove_override ! ( self , pa) ;
2698
+ self . overrides . push ( pa) ;
2699
+ }
2651
2700
}
2652
2701
2653
2702
// Make sure this isn't one being added multiple times if it doesn't suppor it
@@ -2793,7 +2842,17 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{
2793
2842
}
2794
2843
self . overrides . dedup ( ) ;
2795
2844
if self . overrides . contains ( & v. name ) {
2796
- matches. args . remove ( v. name ) ;
2845
+ if let Some ( name) = self . overriden_from ( v. name , matches) {
2846
+ matches. args . remove ( & * name) ;
2847
+ remove_override ! ( self , & * name) ;
2848
+ }
2849
+ }
2850
+ if let Some ( ref or) = v. overrides {
2851
+ for pa in or {
2852
+ matches. args . remove ( pa) ;
2853
+ remove_override ! ( self , pa) ;
2854
+ self . overrides . push ( pa) ;
2855
+ }
2797
2856
}
2798
2857
2799
2858
if matches. args . contains_key ( v. name ) {
@@ -2811,12 +2870,6 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{
2811
2870
values : Some ( BTreeMap :: new ( ) )
2812
2871
} ) ;
2813
2872
}
2814
- if let Some ( ref ov) = v. overrides {
2815
- for name in ov {
2816
- self . overrides . push ( name) ;
2817
- vec_remove ! ( self . required, name) ;
2818
- }
2819
- }
2820
2873
if let Some ( ref bl) = v. blacklist {
2821
2874
for name in bl {
2822
2875
self . blacklist . push ( name) ;
@@ -2853,9 +2906,9 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{
2853
2906
}
2854
2907
2855
2908
fn parse_single_short_flag ( & mut self , matches : & mut ArgMatches < ' ar , ' ar > , arg : char ) -> bool {
2856
- for v in self . flags . values ( )
2909
+ if let Some ( v ) = self . flags . values ( )
2857
2910
. filter ( |& v| v. short . is_some ( ) )
2858
- . filter ( |& v| v. short . unwrap ( ) == arg) {
2911
+ . filter ( |& v| v. short . unwrap ( ) == arg) . nth ( 0 ) {
2859
2912
// Ensure this flag isn't on the mutually excludes list
2860
2913
self . blacklist . dedup ( ) ;
2861
2914
if self . blacklist . contains ( & v. name ) {
@@ -2871,8 +2924,22 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{
2871
2924
Some ( matches. args . keys ( ) . map ( |k| * k) . collect ( ) ) ) ;
2872
2925
}
2873
2926
self . overrides . dedup ( ) ;
2927
+ debugln ! ( "checking if {} is in overrides" , v. name) ;
2874
2928
if self . overrides . contains ( & v. name ) {
2875
- matches. args . remove ( v. name ) ;
2929
+ debugln ! ( "it is..." ) ;
2930
+ debugln ! ( "checking who defined it..." ) ;
2931
+ if let Some ( name) = self . overriden_from ( v. name , matches) {
2932
+ debugln ! ( "found {}" , name) ;
2933
+ matches. args . remove ( name) ;
2934
+ remove_override ! ( self , name) ;
2935
+ }
2936
+ }
2937
+ if let Some ( ref or) = v. overrides {
2938
+ for pa in or {
2939
+ matches. args . remove ( pa) ;
2940
+ remove_override ! ( self , pa) ;
2941
+ self . overrides . push ( pa) ;
2942
+ }
2876
2943
}
2877
2944
2878
2945
// Make sure this isn't one being added multiple times if it doesn't suppor it
@@ -2902,13 +2969,6 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{
2902
2969
let vname = & v. name ;
2903
2970
vec_remove ! ( self . required, vname) ;
2904
2971
2905
- // Add all of this flags "mutually excludes" list to the master list
2906
- if let Some ( ref ov) = v. overrides {
2907
- for name in ov {
2908
- self . overrides . push ( name) ;
2909
- vec_remove ! ( self . required, name) ;
2910
- }
2911
- }
2912
2972
if let Some ( ref bl) = v. blacklist {
2913
2973
for name in bl {
2914
2974
self . blacklist . push ( name) ;
@@ -3076,7 +3136,6 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{
3076
3136
fn validate_required ( & self , matches : & ArgMatches < ' ar , ' ar > ) -> bool {
3077
3137
for name in self . required . iter ( ) {
3078
3138
validate_reqs ! ( self , flags, matches, name) ;
3079
-
3080
3139
validate_reqs ! ( self , opts, matches, name) ;
3081
3140
3082
3141
// because positions use different keys, we dont use the macro
@@ -3126,4 +3185,5 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{
3126
3185
None => ( String :: new ( ) , None ) ,
3127
3186
}
3128
3187
}
3188
+
3129
3189
}
0 commit comments