aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2018-04-15 14:30:06 +0200
committerTeddy Wing2018-04-15 14:30:06 +0200
commit9718d2477026b4695a508bd40097b54f8ca6768e (patch)
tree07644fb05bdc2a5af063425b8f84a65318f37ad2
parentfc614ba9d8e60e11f15fcfb883b27e3f3cf010b3 (diff)
downloadmeetup-find-events-rss-9718d2477026b4695a508bd40097b54f8ca6768e.tar.bz2
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.
-rw-r--r--src/main.rs7
1 files changed, 7 insertions, 0 deletions
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);
},