aboutsummaryrefslogtreecommitdiff
path: root/src/cli.rs
diff options
context:
space:
mode:
authorAkshay <[email protected]>2020-08-24 09:16:44 +0100
committerAkshay <[email protected]>2020-08-24 09:16:44 +0100
commit9c71fb1a39964a8cb5696315c9a998a4872d7aab (patch)
tree2f13a9f31e6ac51db28058b4b4077b27b8765211 /src/cli.rs
parent7308121fa3efc785bf964b8ab32505ba25513fdc (diff)
add help text
Diffstat (limited to 'src/cli.rs')
-rw-r--r--src/cli.rs17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/cli.rs b/src/cli.rs
index 009397d..e0b745d 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -5,6 +5,7 @@ use std::default::Default;
5use std::path::PathBuf; 5use std::path::PathBuf;
6 6
7pub struct Config { 7pub 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 {
12impl Default for Config { 13impl 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
27pub static HELP_TEXT: &'static str = "
28Usage
29-----
30
31hedge [-h | --help] [--port <number>] [--database <path>]
32
33Options
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
25fn parse_args() -> Result<Config> { 41fn 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),