Skip to content

Commit dc8a34f

Browse files
committed
Avoid panic for unknown flags
1 parent 381a4bd commit dc8a34f

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

scraper/src/main.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ enum Output {
2424
Text,
2525
}
2626

27+
// Based on sysexits.h
28+
pub const EX_USAGE: i32 = 64;
29+
2730
fn query<T: Read>(input: &Input, output: &Output, selector: &Selector, file: &mut T) -> bool {
2831
let mut html = String::new();
2932
file.read_to_string(&mut html).unwrap();
@@ -70,7 +73,10 @@ fn main() {
7073
let args: Vec<String> = env::args().collect();
7174
let matches = match opts.parse(&args[1..]) {
7275
Ok(m) => m,
73-
Err(f) => panic!("{}", f.to_string()),
76+
Err(f) => {
77+
eprintln!("{}", f.to_string());
78+
process::exit(EX_USAGE);
79+
}
7480
};
7581
if matches.opt_present("h") {
7682
print!(

0 commit comments

Comments
 (0)