diff options
| author | Teddy Wing | 2021-04-12 23:11:32 +0200 | 
|---|---|---|
| committer | Teddy Wing | 2021-04-12 23:11:32 +0200 | 
| commit | 6ad5626a5d6ac98a9da445dc706a338d1475eb54 (patch) | |
| tree | fb28f0c29dae7a8aa034b1fc2d86bbaa7e38c7ad /src | |
| parent | 0c8a97cd2f67481722a9c1eda6cea4d93a2955cf (diff) | |
| download | formurapid-6ad5626a5d6ac98a9da445dc706a338d1475eb54.tar.bz2 | |
Add `--help` and `--version` flags
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.rs | 13 | 
1 files changed, 13 insertions, 0 deletions
| 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); | 
