@@ -36,7 +36,7 @@ use args::{PosArg, PosBuilder};
36
36
///
37
37
/// // Your pogram logic starts here...
38
38
/// ```
39
- pub struct App < ' a , ' v , ' ab , ' u > {
39
+ pub struct App < ' a , ' v , ' ab , ' u , ' ar > {
40
40
// The name displayed to the user when showing version and help/usage information
41
41
name : String ,
42
42
// A string of author(s) if desired. Displayed when showing help/usage information
@@ -45,26 +45,26 @@ pub struct App<'a, 'v, 'ab, 'u> {
45
45
version : Option < & ' v str > ,
46
46
// A brief explaination of the program that gets displayed to the user when shown help/usage information
47
47
about : Option < & ' ab str > ,
48
- flags : HashMap < & ' static str , FlagBuilder > ,
49
- opts : HashMap < & ' static str , OptBuilder > ,
50
- positionals_idx : BTreeMap < u8 , PosBuilder > ,
51
- subcommands : HashMap < String , App < ' a , ' v , ' ab , ' u > > ,
48
+ flags : HashMap < & ' ar str , FlagBuilder < ' ar > > ,
49
+ opts : HashMap < & ' ar str , OptBuilder < ' ar > > ,
50
+ positionals_idx : BTreeMap < u8 , PosBuilder < ' ar > > ,
51
+ subcommands : HashMap < String , App < ' a , ' v , ' ab , ' u , ' ar > > ,
52
52
needs_long_help : bool ,
53
53
needs_long_version : bool ,
54
54
needs_short_help : bool ,
55
55
needs_short_version : bool ,
56
56
needs_subcmd_help : bool ,
57
- required : HashSet < & ' static str > ,
58
- arg_list : HashSet < & ' static str > ,
57
+ required : HashSet < & ' ar str > ,
58
+ arg_list : HashSet < & ' ar str > ,
59
59
short_list : HashSet < char > ,
60
- long_list : HashSet < & ' static str > ,
61
- blacklist : HashSet < & ' static str > ,
60
+ long_list : HashSet < & ' ar str > ,
61
+ blacklist : HashSet < & ' ar str > ,
62
62
usage_str : Option < & ' u str > ,
63
63
bin_name : Option < String >
64
64
65
65
}
66
66
67
- impl < ' a , ' v , ' ab , ' u > App < ' a , ' v , ' ab , ' u > {
67
+ impl < ' a , ' v , ' ab , ' u , ' ar > App < ' a , ' v , ' ab , ' u , ' ar > {
68
68
/// Creates a new instance of an application requiring a name (such as the binary). Will be displayed
69
69
/// to the user when they print version or help and usage information.
70
70
///
@@ -75,7 +75,7 @@ impl<'a, 'v, 'ab, 'u> App<'a, 'v, 'ab, 'u>{
75
75
/// let prog = App::new("myprog")
76
76
/// # .get_matches();
77
77
/// ```
78
- pub fn new < ' n > ( n : & ' n str ) -> App < ' a , ' v , ' ab , ' u > {
78
+ pub fn new < ' n > ( n : & ' n str ) -> App < ' a , ' v , ' ab , ' u , ' ar > {
79
79
App {
80
80
name : n. to_owned ( ) ,
81
81
author : None ,
@@ -110,7 +110,7 @@ impl<'a, 'v, 'ab, 'u> App<'a, 'v, 'ab, 'u>{
110
110
/// .author("Kevin <[email protected] >")
111
111
/// # .get_matches();
112
112
/// ```
113
- pub fn author ( mut self , a : & ' a str ) -> App < ' a , ' v , ' ab , ' u > {
113
+ pub fn author ( mut self , a : & ' a str ) -> App < ' a , ' v , ' ab , ' u , ' ar > {
114
114
self . author = Some ( a) ;
115
115
self
116
116
}
@@ -125,7 +125,7 @@ impl<'a, 'v, 'ab, 'u> App<'a, 'v, 'ab, 'u>{
125
125
/// .about("Does really amazing things to great people")
126
126
/// # .get_matches();
127
127
/// ```
128
- pub fn about ( mut self , a : & ' ab str ) -> App < ' a , ' v , ' ab , ' u > {
128
+ pub fn about ( mut self , a : & ' ab str ) -> App < ' a , ' v , ' ab , ' u , ' ar > {
129
129
self . about = Some ( a) ;
130
130
self
131
131
}
@@ -140,7 +140,7 @@ impl<'a, 'v, 'ab, 'u> App<'a, 'v, 'ab, 'u>{
140
140
/// .version("v0.1.24")
141
141
/// # .get_matches();
142
142
/// ```
143
- pub fn version ( mut self , v : & ' v str ) -> App < ' a , ' v , ' ab , ' u > {
143
+ pub fn version ( mut self , v : & ' v str ) -> App < ' a , ' v , ' ab , ' u , ' ar > {
144
144
self . version = Some ( v) ;
145
145
self
146
146
}
@@ -162,7 +162,7 @@ impl<'a, 'v, 'ab, 'u> App<'a, 'v, 'ab, 'u>{
162
162
/// .usage("myapp [-clDas] <some_file>")
163
163
/// # .get_matches();
164
164
/// ```
165
- pub fn usage ( mut self , u : & ' u str ) -> App < ' a , ' v , ' ab , ' u > {
165
+ pub fn usage ( mut self , u : & ' u str ) -> App < ' a , ' v , ' ab , ' u , ' ar > {
166
166
self . usage_str = Some ( u) ;
167
167
self
168
168
}
@@ -180,7 +180,7 @@ impl<'a, 'v, 'ab, 'u> App<'a, 'v, 'ab, 'u>{
180
180
/// )
181
181
/// # .get_matches();
182
182
/// ```
183
- pub fn arg ( mut self , a : Arg ) -> App < ' a , ' v , ' ab , ' u > {
183
+ pub fn arg < ' l , ' h , ' b , ' r > ( mut self , a : Arg < ' ar , ' ar , ' ar , ' ar , ' ar > ) -> App < ' a , ' v , ' ab , ' u , ' ar > {
184
184
if self . arg_list . contains ( a. name ) {
185
185
panic ! ( "Argument name must be unique, \" {}\" is already in use" , a. name) ;
186
186
} else {
@@ -289,7 +289,7 @@ impl<'a, 'v, 'ab, 'u> App<'a, 'v, 'ab, 'u>{
289
289
/// Arg::new("debug").short("d")])
290
290
/// # .get_matches();
291
291
/// ```
292
- pub fn args ( mut self , args : Vec < Arg > ) -> App < ' a , ' v , ' ab , ' u > {
292
+ pub fn args ( mut self , args : Vec < Arg < ' ar , ' ar , ' ar , ' ar , ' ar > > ) -> App < ' a , ' v , ' ab , ' u , ' ar > {
293
293
for arg in args. into_iter ( ) {
294
294
self = self . arg ( arg) ;
295
295
}
@@ -314,7 +314,7 @@ impl<'a, 'v, 'ab, 'u> App<'a, 'v, 'ab, 'u>{
314
314
/// // Additional subcommand configuration goes here, such as arguments...
315
315
/// # .get_matches();
316
316
/// ```
317
- pub fn subcommand ( mut self , subcmd : App < ' a , ' v , ' ab , ' u > ) -> App < ' a , ' v , ' ab , ' u > {
317
+ pub fn subcommand ( mut self , subcmd : App < ' a , ' v , ' ab , ' u , ' ar > ) -> App < ' a , ' v , ' ab , ' u , ' ar > {
318
318
if subcmd. name == "help" { self . needs_subcmd_help = false ; }
319
319
self . subcommands . insert ( subcmd. name . clone ( ) , subcmd) ;
320
320
self
@@ -333,7 +333,7 @@ impl<'a, 'v, 'ab, 'u> App<'a, 'v, 'ab, 'u>{
333
333
/// SubCommand::new("debug").about("Controls debug functionality")])
334
334
/// # .get_matches();
335
335
/// ```
336
- pub fn subcommands ( mut self , subcmds : Vec < App < ' a , ' v , ' ab , ' u > > ) -> App < ' a , ' v , ' ab , ' u > {
336
+ pub fn subcommands ( mut self , subcmds : Vec < App < ' a , ' v , ' ab , ' u , ' ar > > ) -> App < ' a , ' v , ' ab , ' u , ' ar > {
337
337
for subcmd in subcmds. into_iter ( ) {
338
338
self = self . subcommand ( subcmd) ;
339
339
}
@@ -449,7 +449,7 @@ impl<'a, 'v, 'ab, 'u> App<'a, 'v, 'ab, 'u>{
449
449
if quit { env:: set_exit_status ( 1 ) ; self . exit ( ) ; }
450
450
}
451
451
452
- pub fn get_matches ( mut self ) -> ArgMatches {
452
+ pub fn get_matches ( mut self ) -> ArgMatches < ' ar > {
453
453
let mut matches = ArgMatches :: new ( ) ;
454
454
455
455
let args = env:: args ( ) . collect :: < Vec < _ > > ( ) ;
@@ -468,12 +468,12 @@ impl<'a, 'v, 'ab, 'u> App<'a, 'v, 'ab, 'u>{
468
468
matches
469
469
}
470
470
471
- fn get_matches_from ( & mut self , matches : & mut ArgMatches , it : & mut IntoIter < String > ) {
471
+ fn get_matches_from ( & mut self , matches : & mut ArgMatches < ' ar > , it : & mut IntoIter < String > ) {
472
472
self . create_help_and_version ( ) ;
473
473
474
474
let mut pos_only = false ;
475
475
let mut subcmd_name: Option < String > = None ;
476
- let mut needs_val_of: Option < & ' static str > = None ;
476
+ let mut needs_val_of: Option < & str > = None ;
477
477
let mut pos_counter = 1 ;
478
478
while let Some ( arg) = it. next ( ) {
479
479
let arg_slice = & arg[ ..] ;
@@ -518,14 +518,14 @@ impl<'a, 'v, 'ab, 'u> App<'a, 'v, 'ab, 'u>{
518
518
format ! ( "Found positional argument {}, but {} doesn't accept any" , arg, self . name) ,
519
519
true , true ) ;
520
520
}
521
- if let Some ( ref p) = self . positionals_idx . get ( & pos_counter) {
521
+ if let Some ( p) = self . positionals_idx . get ( & pos_counter) {
522
522
if self . blacklist . contains ( p. name ) {
523
523
self . report_error ( format ! ( "The argument \" {}\" is mutually exclusive with one or more other arguments" , arg) ,
524
524
true , true ) ;
525
525
}
526
526
527
527
matches. positionals . insert ( p. name , PosArg {
528
- name : p. name ,
528
+ name : p. name . to_owned ( ) ,
529
529
value : arg. clone ( ) ,
530
530
} ) ;
531
531
@@ -616,7 +616,7 @@ impl<'a, 'v, 'ab, 'u> App<'a, 'v, 'ab, 'u>{
616
616
}
617
617
}
618
618
619
- fn parse_long_arg ( & mut self , matches : & mut ArgMatches , full_arg : & String ) -> Option < & ' static str > {
619
+ fn parse_long_arg ( & mut self , matches : & mut ArgMatches < ' ar > , full_arg : & String ) -> Option < & ' ar str > {
620
620
let mut arg = full_arg. trim_left_matches ( |c| c == '-' ) ;
621
621
622
622
if arg == "help" && self . needs_long_help {
@@ -656,7 +656,7 @@ impl<'a, 'v, 'ab, 'u> App<'a, 'v, 'ab, 'u>{
656
656
}
657
657
} else {
658
658
matches. opts . insert ( v. name , OptArg {
659
- name : v. name ,
659
+ name : v. name . to_owned ( ) ,
660
660
occurrences : 1 ,
661
661
values : if arg_val. is_some ( ) { vec ! [ arg_val. clone( ) . unwrap( ) ] } else { vec ! [ ] }
662
662
} ) ;
@@ -706,7 +706,7 @@ impl<'a, 'v, 'ab, 'u> App<'a, 'v, 'ab, 'u>{
706
706
}
707
707
if !done {
708
708
matches. flags . insert ( v. name , FlagArg {
709
- name : v. name ,
709
+ name : v. name . to_owned ( ) ,
710
710
occurrences : 1
711
711
} ) ;
712
712
}
@@ -742,7 +742,7 @@ impl<'a, 'v, 'ab, 'u> App<'a, 'v, 'ab, 'u>{
742
742
unreachable ! ( ) ;
743
743
}
744
744
745
- fn parse_short_arg ( & mut self , matches : & mut ArgMatches , full_arg : & String ) -> Option < & ' static str > {
745
+ fn parse_short_arg ( & mut self , matches : & mut ArgMatches < ' ar > , full_arg : & String ) -> Option < & ' ar str > {
746
746
let arg = & full_arg[ ..] . trim_left_matches ( |c| c == '-' ) ;
747
747
if arg. len ( ) > 1 {
748
748
// Multiple flags using short i.e. -bgHlS
@@ -778,7 +778,7 @@ impl<'a, 'v, 'ab, 'u> App<'a, 'v, 'ab, 'u>{
778
778
}
779
779
} else {
780
780
matches. opts . insert ( v. name , OptArg {
781
- name : v. name ,
781
+ name : v. name . to_owned ( ) ,
782
782
occurrences : 1 ,
783
783
values : vec ! [ ]
784
784
} ) ;
@@ -811,7 +811,7 @@ impl<'a, 'v, 'ab, 'u> App<'a, 'v, 'ab, 'u>{
811
811
unreachable ! ( ) ;
812
812
}
813
813
814
- fn parse_single_short_flag ( & mut self , matches : & mut ArgMatches , arg : char ) -> bool {
814
+ fn parse_single_short_flag ( & mut self , matches : & mut ArgMatches < ' ar > , arg : char ) -> bool {
815
815
for v in self . flags . values ( ) . filter ( |& v| v. short . is_some ( ) ) . filter ( |& v| v. short . unwrap ( ) == arg) {
816
816
// Ensure this flag isn't on the mutually excludes list
817
817
if self . blacklist . contains ( v. name ) {
@@ -831,7 +831,7 @@ impl<'a, 'v, 'ab, 'u> App<'a, 'v, 'ab, 'u>{
831
831
}
832
832
if !done {
833
833
matches. flags . insert ( v. name , FlagArg {
834
- name : v. name ,
834
+ name : v. name . to_owned ( ) ,
835
835
occurrences : 1
836
836
} ) ;
837
837
}
@@ -864,7 +864,7 @@ impl<'a, 'v, 'ab, 'u> App<'a, 'v, 'ab, 'u>{
864
864
false
865
865
}
866
866
867
- fn validate_blacklist ( & self , matches : & ArgMatches ) {
867
+ fn validate_blacklist ( & self , matches : & ArgMatches < ' ar > ) {
868
868
for name in self . blacklist . iter ( ) {
869
869
if matches. flags . contains_key ( name) {
870
870
self . report_error ( format ! ( "The argument {} is mutually exclusive with one or more other arguments" ,
0 commit comments