From 586cc4161b62ddb214e6dc2bb5156390d7eac715 Mon Sep 17 00:00:00 2001 From: Akshay Date: Tue, 25 Aug 2020 09:49:09 +0530 Subject: add version flag --- src/cli.rs | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/cli.rs') diff --git a/src/cli.rs b/src/cli.rs index 79753d4..33310ca 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -6,6 +6,7 @@ use std::path::PathBuf; pub struct Config { pub help: bool, + pub version: bool, pub port: u16, pub db_path: PathBuf, } @@ -14,6 +15,7 @@ impl Default for Config { fn default() -> Self { Config { help: false, + version: false, port: 3000, db_path: "./urls.db_3".into(), } @@ -36,12 +38,14 @@ Options -h, --help Prints help information --port Port to start the server on (default: 3000) --database Path to database (default: urls.db_3) + -v, --version Print crate version "; fn parse_args() -> Result { let mut _a = pico_args::Arguments::from_env(); return Ok(Config { help: _a.contains(["-h", "--help"]), + version: _a.contains(["-v", "--version"]), port: _a .opt_value_from_fn("--port", str::parse::)? .unwrap_or(7878), @@ -50,3 +54,7 @@ fn parse_args() -> Result { .unwrap_or(PathBuf::from("./urls.db_3")), }); } + +pub fn version() { + println!("isostatic v{}", env!("CARGO_PKG_VERSION")); +} -- cgit v1.2.3