diff options
author | Akshay <[email protected]> | 2020-08-24 09:16:44 +0100 |
---|---|---|
committer | Akshay <[email protected]> | 2020-08-24 09:16:44 +0100 |
commit | 9c71fb1a39964a8cb5696315c9a998a4872d7aab (patch) | |
tree | 2f13a9f31e6ac51db28058b4b4077b27b8765211 /src/cli.rs | |
parent | 7308121fa3efc785bf964b8ab32505ba25513fdc (diff) |
add help text
Diffstat (limited to 'src/cli.rs')
-rw-r--r-- | src/cli.rs | 17 |
1 files changed, 17 insertions, 0 deletions
@@ -5,6 +5,7 @@ use std::default::Default; | |||
5 | use std::path::PathBuf; | 5 | use std::path::PathBuf; |
6 | 6 | ||
7 | pub struct Config { | 7 | pub struct Config { |
8 | pub help: bool, | ||
8 | pub port: u16, | 9 | pub port: u16, |
9 | pub db_path: PathBuf, | 10 | pub db_path: PathBuf, |
10 | } | 11 | } |
@@ -12,6 +13,7 @@ pub struct Config { | |||
12 | impl Default for Config { | 13 | impl Default for Config { |
13 | fn default() -> Self { | 14 | fn default() -> Self { |
14 | Config { | 15 | Config { |
16 | help: false, | ||
15 | port: 3000, | 17 | port: 3000, |
16 | db_path: "./urls.db_3".into(), | 18 | db_path: "./urls.db_3".into(), |
17 | } | 19 | } |
@@ -22,9 +24,24 @@ lazy_static! { | |||
22 | pub static ref CONFIG: Config = parse_args().unwrap_or(Default::default()); | 24 | pub static ref CONFIG: Config = parse_args().unwrap_or(Default::default()); |
23 | } | 25 | } |
24 | 26 | ||
27 | pub static HELP_TEXT: &'static str = " | ||
28 | Usage | ||
29 | ----- | ||
30 | |||
31 | hedge [-h | --help] [--port <number>] [--database <path>] | ||
32 | |||
33 | Options | ||
34 | ------- | ||
35 | |||
36 | -h, --help Prints help information | ||
37 | --port Port to start the server on (default: 3000) | ||
38 | --database Path to database (default: urls.db_3) | ||
39 | "; | ||
40 | |||
25 | fn parse_args() -> Result<Config> { | 41 | fn parse_args() -> Result<Config> { |
26 | let mut _a = pico_args::Arguments::from_env(); | 42 | let mut _a = pico_args::Arguments::from_env(); |
27 | return Ok(Config { | 43 | return Ok(Config { |
44 | help: _a.contains(["-h", "--help"]), | ||
28 | port: _a | 45 | port: _a |
29 | .opt_value_from_fn("--port", str::parse::<u16>)? | 46 | .opt_value_from_fn("--port", str::parse::<u16>)? |
30 | .unwrap_or(7878), | 47 | .unwrap_or(7878), |