aboutsummaryrefslogtreecommitdiff
path: root/src/cli.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/cli.rs')
-rw-r--r--src/cli.rs35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/cli.rs b/src/cli.rs
new file mode 100644
index 0000000..009397d
--- /dev/null
+++ b/src/cli.rs
@@ -0,0 +1,35 @@
1use anyhow::Result;
2use lazy_static::lazy_static;
3
4use std::default::Default;
5use std::path::PathBuf;
6
7pub struct Config {
8 pub port: u16,
9 pub db_path: PathBuf,
10}
11
12impl Default for Config {
13 fn default() -> Self {
14 Config {
15 port: 3000,
16 db_path: "./urls.db_3".into(),
17 }
18 }
19}
20
21lazy_static! {
22 pub static ref CONFIG: Config = parse_args().unwrap_or(Default::default());
23}
24
25fn parse_args() -> Result<Config> {
26 let mut _a = pico_args::Arguments::from_env();
27 return Ok(Config {
28 port: _a
29 .opt_value_from_fn("--port", str::parse::<u16>)?
30 .unwrap_or(7878),
31 db_path: _a
32 .opt_value_from_str("--database")?
33 .unwrap_or(PathBuf::from("./urls.db_3")),
34 });
35}