@@ -50,7 +50,11 @@ use errors::Result as ClapResult;
50
50
/// // Your program logic starts here...
51
51
/// ```
52
52
#[ allow( missing_debug_implementations) ]
53
- pub struct App < ' a , ' b > ( Parser < ' a , ' b > ) where ' a : ' b ;
53
+ pub struct App < ' a , ' b > where ' a : ' b {
54
+ #[ doc( hidden) ]
55
+ pub p : Parser < ' a , ' b >
56
+ }
57
+
54
58
55
59
impl < ' a , ' b > App < ' a , ' b > {
56
60
/// Creates a new instance of an application requiring a name. The name may be, but doesn't
@@ -64,7 +68,7 @@ impl<'a, 'b> App<'a, 'b> {
64
68
/// let prog = App::new("My Program")
65
69
/// # ;
66
70
/// ```
67
- pub fn new < S : Into < String > > ( n : S ) -> Self { App ( Parser :: with_name ( n. into ( ) ) ) }
71
+ pub fn new < S : Into < String > > ( n : S ) -> Self { App { p : Parser :: with_name ( n. into ( ) ) } }
68
72
69
73
/// Creates a new instace of `App` from a .yml (YAML) file. A full example of supported YAML
70
74
/// objects can be found in `examples/17_yaml.rs` and `examples/17_yaml.yml`. One great use for
@@ -114,7 +118,7 @@ impl<'a, 'b> App<'a, 'b> {
114
118
/// # ;
115
119
/// ```
116
120
pub fn author < S : Into < & ' b str > > ( mut self , author : S ) -> Self {
117
- self . 0 . meta . author = Some ( author. into ( ) ) ;
121
+ self . p . meta . author = Some ( author. into ( ) ) ;
118
122
self
119
123
}
120
124
@@ -136,7 +140,7 @@ impl<'a, 'b> App<'a, 'b> {
136
140
/// # ;
137
141
/// ```
138
142
pub fn bin_name < S : Into < String > > ( mut self , name : S ) -> Self {
139
- self . 0 . meta . bin_name = Some ( name. into ( ) ) ;
143
+ self . p . meta . bin_name = Some ( name. into ( ) ) ;
140
144
self
141
145
}
142
146
@@ -152,7 +156,7 @@ impl<'a, 'b> App<'a, 'b> {
152
156
/// # ;
153
157
/// ```
154
158
pub fn about < S : Into < & ' b str > > ( mut self , about : S ) -> Self {
155
- self . 0 . meta . about = Some ( about. into ( ) ) ;
159
+ self . p . meta . about = Some ( about. into ( ) ) ;
156
160
self
157
161
}
158
162
@@ -169,7 +173,7 @@ impl<'a, 'b> App<'a, 'b> {
169
173
/// # ;
170
174
/// ```
171
175
pub fn after_help < S : Into < & ' b str > > ( mut self , help : S ) -> Self {
172
- self . 0 . meta . more_help = Some ( help. into ( ) ) ;
176
+ self . p . meta . more_help = Some ( help. into ( ) ) ;
173
177
self
174
178
}
175
179
@@ -189,7 +193,7 @@ impl<'a, 'b> App<'a, 'b> {
189
193
/// # ;
190
194
/// ```
191
195
pub fn version < S : Into < & ' b str > > ( mut self , ver : S ) -> Self {
192
- self . 0 . meta . version = Some ( ver. into ( ) ) ;
196
+ self . p . meta . version = Some ( ver. into ( ) ) ;
193
197
self
194
198
}
195
199
@@ -217,7 +221,7 @@ impl<'a, 'b> App<'a, 'b> {
217
221
/// # ;
218
222
/// ```
219
223
pub fn usage < S : Into < & ' b str > > ( mut self , usage : S ) -> Self {
220
- self . 0 . meta . usage_str = Some ( usage. into ( ) ) ;
224
+ self . p . meta . usage_str = Some ( usage. into ( ) ) ;
221
225
self
222
226
}
223
227
@@ -255,7 +259,7 @@ impl<'a, 'b> App<'a, 'b> {
255
259
/// # ;
256
260
/// ```
257
261
pub fn help < S : Into < & ' b str > > ( mut self , help : S ) -> Self {
258
- self . 0 . meta . help_str = Some ( help. into ( ) ) ;
262
+ self . p . meta . help_str = Some ( help. into ( ) ) ;
259
263
self
260
264
}
261
265
@@ -277,7 +281,7 @@ impl<'a, 'b> App<'a, 'b> {
277
281
/// # ;
278
282
/// ```
279
283
pub fn help_short < S : AsRef < str > + ' b > ( mut self , s : S ) -> Self {
280
- self . 0 . help_short ( s. as_ref ( ) ) ;
284
+ self . p . help_short ( s. as_ref ( ) ) ;
281
285
self
282
286
}
283
287
@@ -299,7 +303,7 @@ impl<'a, 'b> App<'a, 'b> {
299
303
/// # ;
300
304
/// ```
301
305
pub fn version_short < S : AsRef < str > > ( mut self , s : S ) -> Self {
302
- self . 0 . version_short ( s. as_ref ( ) ) ;
306
+ self . p . version_short ( s. as_ref ( ) ) ;
303
307
self
304
308
}
305
309
@@ -317,7 +321,7 @@ impl<'a, 'b> App<'a, 'b> {
317
321
/// # ;
318
322
/// ```
319
323
pub fn setting ( mut self , setting : AppSettings ) -> Self {
320
- self . 0 . set ( setting) ;
324
+ self . p . set ( setting) ;
321
325
self
322
326
}
323
327
@@ -336,7 +340,7 @@ impl<'a, 'b> App<'a, 'b> {
336
340
/// ```
337
341
pub fn settings ( mut self , settings : & [ AppSettings ] ) -> Self {
338
342
for s in settings {
339
- self . 0 . set ( * s) ;
343
+ self . p . set ( * s) ;
340
344
}
341
345
self
342
346
}
@@ -362,7 +366,7 @@ impl<'a, 'b> App<'a, 'b> {
362
366
/// # ;
363
367
/// ```
364
368
pub fn arg < A : Borrow < Arg < ' a , ' b > > + ' a > ( mut self , a : A ) -> Self {
365
- self . 0 . add_arg ( a. borrow ( ) ) ;
369
+ self . p . add_arg ( a. borrow ( ) ) ;
366
370
self
367
371
}
368
372
@@ -381,7 +385,7 @@ impl<'a, 'b> App<'a, 'b> {
381
385
/// ```
382
386
pub fn args ( mut self , args : & [ Arg < ' a , ' b > ] ) -> Self {
383
387
for arg in args {
384
- self . 0 . add_arg ( arg) ;
388
+ self . p . add_arg ( arg) ;
385
389
}
386
390
self
387
391
}
@@ -401,7 +405,7 @@ impl<'a, 'b> App<'a, 'b> {
401
405
/// # ;
402
406
/// ```
403
407
pub fn arg_from_usage ( mut self , usage : & ' a str ) -> Self {
404
- self . 0 . add_arg ( & Arg :: from_usage ( usage) ) ;
408
+ self . p . add_arg ( & Arg :: from_usage ( usage) ) ;
405
409
self
406
410
}
407
411
@@ -426,7 +430,7 @@ impl<'a, 'b> App<'a, 'b> {
426
430
pub fn args_from_usage ( mut self , usage : & ' a str ) -> Self {
427
431
for l in usage. lines ( ) {
428
432
if l. len ( ) == 0 { continue ; }
429
- self . 0 . add_arg ( & Arg :: from_usage ( l. trim ( ) ) ) ;
433
+ self . p . add_arg ( & Arg :: from_usage ( l. trim ( ) ) ) ;
430
434
}
431
435
self
432
436
}
@@ -464,7 +468,7 @@ impl<'a, 'b> App<'a, 'b> {
464
468
/// # ;
465
469
/// ```
466
470
pub fn group ( mut self , group : ArgGroup < ' a > ) -> Self {
467
- self . 0 . add_group ( group) ;
471
+ self . p . add_group ( group) ;
468
472
self
469
473
}
470
474
@@ -514,7 +518,7 @@ impl<'a, 'b> App<'a, 'b> {
514
518
/// # ;
515
519
/// ```
516
520
pub fn subcommand ( mut self , subcmd : App < ' a , ' b > ) -> Self {
517
- self . 0 . add_subcommand ( subcmd) ;
521
+ self . p . add_subcommand ( subcmd) ;
518
522
self
519
523
}
520
524
@@ -536,7 +540,7 @@ impl<'a, 'b> App<'a, 'b> {
536
540
where I : IntoIterator < Item = App < ' a , ' b > >
537
541
{
538
542
for subcmd in subcmds. into_iter ( ) {
539
- self . 0 . add_subcommand ( subcmd) ;
543
+ self . p . add_subcommand ( subcmd) ;
540
544
}
541
545
self
542
546
}
@@ -569,7 +573,7 @@ impl<'a, 'b> App<'a, 'b> {
569
573
/// app.write_help(&mut out).ok().expect("failed to write to stdout");
570
574
/// ```
571
575
pub fn write_help < W : Write > ( & self , w : & mut W ) -> ClapResult < ( ) > {
572
- self . 0 . write_help ( w)
576
+ self . p . write_help ( w)
573
577
}
574
578
575
579
/// Starts the parsing process, upon a failed parse an error will be displayed to the user and
@@ -690,10 +694,10 @@ impl<'a, 'b> App<'a, 'b> {
690
694
T : Into < OsString >
691
695
{
692
696
// Verify all positional assertions pass
693
- self . 0 . verify_positionals ( ) ;
697
+ self . p . verify_positionals ( ) ;
694
698
// If there are global arguments, we need to propgate them down to subcommands
695
699
// before parsing incase we run into a subcommand
696
- self . 0 . propogate_globals ( ) ;
700
+ self . p . propogate_globals ( ) ;
697
701
698
702
let mut matcher = ArgMatcher :: new ( ) ;
699
703
@@ -705,22 +709,22 @@ impl<'a, 'b> App<'a, 'b> {
705
709
// will have two arguments, './target/release/my_prog', '-a' but we don't want
706
710
// to display
707
711
// the full path when displaying help messages and such
708
- if !self . 0 . is_set ( AppSettings :: NoBinaryName ) {
712
+ if !self . p . is_set ( AppSettings :: NoBinaryName ) {
709
713
if let Some ( name) = it. next ( ) {
710
714
let bn_os = name. into ( ) ;
711
715
let p = Path :: new ( & * bn_os) ;
712
716
if let Some ( f) = p. file_name ( ) {
713
717
if let Some ( s) = f. to_os_string ( ) . to_str ( ) {
714
- if let None = self . 0 . meta . bin_name {
715
- self . 0 . meta . bin_name = Some ( s. to_owned ( ) ) ;
718
+ if let None = self . p . meta . bin_name {
719
+ self . p . meta . bin_name = Some ( s. to_owned ( ) ) ;
716
720
}
717
721
}
718
722
}
719
723
}
720
724
}
721
725
722
726
// do the real parsing
723
- if let Err ( e) = self . 0 . get_matches_with ( & mut matcher, & mut it) {
727
+ if let Err ( e) = self . p . get_matches_with ( & mut matcher, & mut it) {
724
728
return Err ( e) ;
725
729
}
726
730
@@ -732,7 +736,7 @@ impl<'a, 'b> App<'a, 'b> {
732
736
fn maybe_wait_for_exit ( & self , e : Error ) -> ! {
733
737
if e. use_stderr ( ) {
734
738
wlnerr ! ( "{}" , e. message) ;
735
- if self . 0 . is_set ( AppSettings :: WaitOnError ) {
739
+ if self . p . is_set ( AppSettings :: WaitOnError ) {
736
740
wlnerr ! ( "\n Press [ENTER] / [RETURN] to continue..." ) ;
737
741
let mut s = String :: new ( ) ;
738
742
let i = io:: stdin ( ) ;
0 commit comments