Skip to content

Commit 9267085

Browse files
committed
Avoid panic for unknown flags
1 parent 85e6967 commit 9267085

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+
const 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();
@@ -71,7 +74,10 @@ fn main() {
7174
let args: Vec<String> = env::args().collect();
7275
let matches = match opts.parse(&args[1..]) {
7376
Ok(m) => m,
74-
Err(f) => panic!("{}", f.to_string()),
77+
Err(f) => {
78+
eprintln!("{}", f);
79+
process::exit(USAGE);
80+
}
7581
};
7682
if matches.opt_present("h") {
7783
print!(

0 commit comments

Comments
 (0)