File tree 1 file changed +27
-0
lines changed
1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change
1
+ use std:: process;
1
2
use std:: error:: Error ;
2
3
use std:: fmt;
3
4
@@ -135,6 +136,24 @@ pub enum ClapErrorType {
135
136
/// .get_matches_from_safe(vec![""]);
136
137
/// ```
137
138
MissingSubcommand ,
139
+ /// Occurs when no argument or subcommand has been supplied and
140
+ /// `AppSettings::ArgRequiredElseHelp` was used
141
+ ///
142
+ ///
143
+ /// # Example
144
+ ///
145
+ /// ```no_run
146
+ /// # use clap::{App, Arg, AppSettings, SubCommand};
147
+ /// let result = App::new("myprog")
148
+ /// .setting(AppSettings::ArgRequiredElseHelp)
149
+ /// .subcommand(SubCommand::with_name("conifg")
150
+ /// .about("Used for configuration")
151
+ /// .arg(Arg::with_name("config_file")
152
+ /// .help("The configuration file to use")
153
+ /// .index(1)))
154
+ /// .get_matches_from_safe(vec![""]);
155
+ /// ```
156
+ MissingArgumentOrSubcommand ,
138
157
/// Error occurs when clap find argument while is was not expecting any
139
158
///
140
159
///
@@ -170,6 +189,14 @@ pub struct ClapError {
170
189
pub error_type : ClapErrorType ,
171
190
}
172
191
192
+ impl ClapError {
193
+ /// Prints the error to `stderr` and exits with a status of `1`
194
+ pub fn exit ( & self ) -> ! {
195
+ wlnerr ! ( "{}" , self . error) ;
196
+ process:: exit ( 1 ) ;
197
+ }
198
+ }
199
+
173
200
impl Error for ClapError {
174
201
fn description ( & self ) -> & str {
175
202
& * self . error
You can’t perform that action at this time.
0 commit comments