aboutsummaryrefslogtreecommitdiff
path: root/src/cli.rs
diff options
context:
space:
mode:
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),