@@ -106,29 +106,29 @@ impl<B: OperationBe> Default for OperationInboxImpl<B> {
106106 }
107107}
108108
109- #[ derive( Default ) ]
110- pub struct AndHelpOptions < P : Validates > {
111- p : P ,
112- help : bool ,
109+ impl < B : OperationBe + ' static > OperationInboxImpl < B > where <B :: Options as Validates >:: Target : Send + Sync {
110+ fn new_options ( ) -> OptionsPile < B :: Options > {
111+ let mut opt = OptionsPile :: < B :: Options > :: new ( ) ;
112+ B :: options ( & mut opt) ;
113+ opt. match_zero ( & [ "help" ] , |_p| {
114+ return ValidationError :: help ( Self :: static_help ( ) ) ;
115+ } , "show help" ) ;
116+ return opt;
117+ }
118+
119+ fn static_help ( ) -> Vec < String > {
120+ let mut lines = Vec :: new ( ) ;
121+ lines. push ( format ! ( "{}:" , B :: names( ) [ 0 ] ) ) ;
122+ lines. append ( & mut Self :: new_options ( ) . dump_help ( ) ) ;
123+ return lines;
124+ }
113125}
114126
115127impl < B : OperationBe + ' static > OperationInbox for OperationInboxImpl < B > where <B :: Options as Validates >:: Target : Send + Sync {
116128 fn parse ( & self , args : & mut Vec < String > ) -> ValidationResult < StreamWrapper > {
117- let mut opt = OptionsPile :: < AndHelpOptions < B :: Options > > :: new ( ) ;
118- opt. add_sub ( |p| & mut p. p , B :: new_options ( ) ) ;
119- opt. match_zero ( & [ "help" ] , |p| {
120- p. help = true ;
121- return Result :: Ok ( ( ) ) ;
122- } , "show help" ) ;
129+ let opt = Self :: new_options ( ) ;
123130 let o = opt. to_parser ( ) . parse ( args) ;
124131 let o = o. map_err ( |e| e. label ( "While parsing arguments" ) ) ?;
125- if o. help {
126- let mut lines = Vec :: new ( ) ;
127- lines. push ( format ! ( "{}:" , B :: names( ) [ 0 ] ) ) ;
128- lines. append ( & mut opt. dump_help ( ) ) ;
129- return ValidationError :: help ( lines) ;
130- }
131- let o = o. p ;
132132 let o = o. validate ( ) ;
133133 let o = o. map_err ( |e| e. label ( "While validating arguments" ) ) ?;
134134 let o = Arc :: new ( o) ;
0 commit comments