From 9718d2477026b4695a508bd40097b54f8ca6768e Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 15 Apr 2018 14:30:06 +0200 Subject: Always print help message if `-h` or `--help` flags passed Since we've set up required arguments, 'getopts' fails fast and complains about missing required args even if the only one used was `-h` or `--help`. Why should you care about required arguments? You wanted help in the first place, how are you going to know? Thankfully, this message from 'prasannavl' pointed me in the right direction: https://github.com/rust-lang-nursery/getopts/issues/46#issuecomment-343842947 If there's an option parse failure, we can just look for the help flags in the args vec to see if we should display the help. --- src/main.rs | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 32134c2..55f8093 100644 --- a/src/main.rs +++ b/src/main.rs @@ -64,6 +64,13 @@ fn run() -> Result<()> { let opt_matches = match opts.parse(&args[1..]) { Ok(m) => m, Err(f) => { + if args.contains(&"-h".to_owned()) || + args.contains(&"--help".to_owned()) { + print_usage(opts); + + return Ok(()); + } + eprintln!("meetup-find-events-rss: error: {}", f.to_string()); exit(1); }, -- cgit v1.2.3