From 6ad5626a5d6ac98a9da445dc706a338d1475eb54 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Mon, 12 Apr 2021 23:11:32 +0200 Subject: Add `--help` and `--version` flags --- src/main.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index 96c0f98..e688968 100644 --- a/src/main.rs +++ b/src/main.rs @@ -52,8 +52,21 @@ fn run() -> anyhow::Result<()> { opts.optflag("", "fill", "fill in the form using a markup file"); opts.optflag("", "generate", "generate helper files to fill in the form"); + opts.optflag("h", "help", "print this help menu"); + opts.optflag("V", "version", "show the program version"); + let opt_matches = opts.parse(&args[1..])?; + if opt_matches.opt_present("h") { + print_usage(&opts); + process::exit(exitcode::USAGE); + } + + if opt_matches.opt_present("V") { + println!("{}", env!("CARGO_PKG_VERSION")); + process::exit(exitcode::OK); + } + if opt_matches.free.is_empty() { print_usage(&opts); -- cgit v1.2.3