From 2f983a7f1b973d72d0c0a43d5679161acf4c653c Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Mon, 3 Aug 2020 20:00:01 +0200 Subject: Config: Add a version argument Allow getting the program version from the command line. --- src/config.rs | 8 ++++++++ src/lib.rs | 3 +++ 2 files changed, 11 insertions(+) (limited to 'src') diff --git a/src/config.rs b/src/config.rs index 39a8158..f451ea5 100644 --- a/src/config.rs +++ b/src/config.rs @@ -6,6 +6,7 @@ use git2::{self, Repository}; use thiserror::Error; use crate::owner_repo::{self, OwnerRepo}; +use crate::VERSION; /// Program-specific prefix for Git config values. @@ -56,6 +57,7 @@ impl Config { "REMOTE", ); opts.optflag("h", "help", "print this help menu"); + opts.optflag("V", "version", "show the program version"); let opt_matches = opts.parse(&args[1..])?; @@ -65,6 +67,12 @@ impl Config { process::exit(exitcode::USAGE); } + if opt_matches.opt_present("V") { + println!("{}", VERSION); + + process::exit(exitcode::OK); + } + if opt_matches.free.is_empty() { print_usage(&opts, usage_brief); diff --git a/src/lib.rs b/src/lib.rs index e9038dc..76e6fd4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,3 +9,6 @@ mod suggestion; pub use suggestion::for_suggestion; + + +const VERSION: &'static str = "0.1.0"; -- cgit v1.2.3