diff options
author | Akshay <[email protected]> | 2020-08-25 05:19:09 +0100 |
---|---|---|
committer | Akshay <[email protected]> | 2020-08-25 05:19:09 +0100 |
commit | 586cc4161b62ddb214e6dc2bb5156390d7eac715 (patch) | |
tree | 4de881a51c320d4427769003abb478e937731c72 /src/cli.rs | |
parent | 09e41a59e81f0e4858b33f01d94b0340c4e10fec (diff) |
add version flag
Diffstat (limited to 'src/cli.rs')
-rw-r--r-- | src/cli.rs | 8 |
1 files changed, 8 insertions, 0 deletions
@@ -6,6 +6,7 @@ use std::path::PathBuf; | |||
6 | 6 | ||
7 | pub struct Config { | 7 | pub struct Config { |
8 | pub help: bool, | 8 | pub help: bool, |
9 | pub version: bool, | ||
9 | pub port: u16, | 10 | pub port: u16, |
10 | pub db_path: PathBuf, | 11 | pub db_path: PathBuf, |
11 | } | 12 | } |
@@ -14,6 +15,7 @@ impl Default for Config { | |||
14 | fn default() -> Self { | 15 | fn default() -> Self { |
15 | Config { | 16 | Config { |
16 | help: false, | 17 | help: false, |
18 | version: false, | ||
17 | port: 3000, | 19 | port: 3000, |
18 | db_path: "./urls.db_3".into(), | 20 | db_path: "./urls.db_3".into(), |
19 | } | 21 | } |
@@ -36,12 +38,14 @@ Options | |||
36 | -h, --help Prints help information | 38 | -h, --help Prints help information |
37 | --port Port to start the server on (default: 3000) | 39 | --port Port to start the server on (default: 3000) |
38 | --database Path to database (default: urls.db_3) | 40 | --database Path to database (default: urls.db_3) |
41 | -v, --version Print crate version | ||
39 | "; | 42 | "; |
40 | 43 | ||
41 | fn parse_args() -> Result<Config> { | 44 | fn parse_args() -> Result<Config> { |
42 | let mut _a = pico_args::Arguments::from_env(); | 45 | let mut _a = pico_args::Arguments::from_env(); |
43 | return Ok(Config { | 46 | return Ok(Config { |
44 | help: _a.contains(["-h", "--help"]), | 47 | help: _a.contains(["-h", "--help"]), |
48 | version: _a.contains(["-v", "--version"]), | ||
45 | port: _a | 49 | port: _a |
46 | .opt_value_from_fn("--port", str::parse::<u16>)? | 50 | .opt_value_from_fn("--port", str::parse::<u16>)? |
47 | .unwrap_or(7878), | 51 | .unwrap_or(7878), |
@@ -50,3 +54,7 @@ fn parse_args() -> Result<Config> { | |||
50 | .unwrap_or(PathBuf::from("./urls.db_3")), | 54 | .unwrap_or(PathBuf::from("./urls.db_3")), |
51 | }); | 55 | }); |
52 | } | 56 | } |
57 | |||
58 | pub fn version() { | ||
59 | println!("isostatic v{}", env!("CARGO_PKG_VERSION")); | ||
60 | } | ||