Add --version flag

This commit is contained in:
Colin Woodbury
2020-08-24 14:17:55 -07:00
parent 8903c72da6
commit 06c5ab9b69

View File

@@ -9,8 +9,13 @@ use std::str;
#[derive(Options)]
struct Args {
/// Display this help message.
help: bool,
/// Display the current version of this software.
version: bool,
/// Unused.
#[options(free)]
args: Vec<String>,
@@ -74,7 +79,10 @@ impl Package {
fn main() {
let args = Args::parse_args_or_exit(ParsingStyle::AllOptions);
if let Err(e) = work(args) {
if args.version {
let version = env!("CARGO_PKG_VERSION");
println!("{}", version);
} else if let Err(e) = work(args) {
eprintln!("{}", e);
process::exit(1)
}