wala-rust

Unnamed repository; edit this file 'description' to name the repository.
Info | Log | Files | Refs | README | LICENSE

commit efa3f6a09919a257b73d81020e1f9365714178b9
parent 73be106c9b105f4a5c99fc157952c99d75e2fbcf
Author: lash <dev@holbrook.no>
Date:   Wed,  6 Jul 2022 06:19:04 +0000

Add data dir switch

Diffstat:
Msrc/arg.rs | 19+++++++++++++++++++
Msrc/main.rs | 5+++--
2 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/src/arg.rs b/src/arg.rs @@ -1,3 +1,4 @@ +use std::path::PathBuf; use clap::{ App, Arg, @@ -8,10 +9,12 @@ use clap::{ pub struct Settings { pub host: String, pub port: u16, + pub dir: PathBuf, } const BIND_HOST: &str = "0.0.0.0"; const BIND_PORT: u16 = 8000; +const DATA_DIR: &str = "."; impl Settings { @@ -19,6 +22,7 @@ impl Settings { Settings { host: BIND_HOST.to_string(), port: BIND_PORT, + dir: PathBuf::from(DATA_DIR), } } @@ -37,6 +41,14 @@ impl Settings { }, _ => {}, }; + + match arg.value_of("datadir") { + Some(v) => { + self.dir = PathBuf::from(v); + }, + _ => {}, + + }; } pub fn from_args() -> Settings { @@ -57,6 +69,13 @@ impl Settings { .value_name("Port to bind server to") .takes_value(true) ); + o = o.arg( + Arg::with_name("datadir") + .long("data-dir") + .short("d") + .value_name("Data directory") + .takes_value(true) + ); let arg_matches = o.get_matches(); let mut settings = Settings::new(); diff --git a/src/main.rs b/src/main.rs @@ -43,7 +43,7 @@ use request::process_method; mod arg; use arg::Settings; -use log::{debug, info, error}; +use log::{info, error}; use tempfile::tempfile; @@ -265,7 +265,8 @@ fn main() { env_logger::init(); let settings = Settings::from_args(); - let base_path = Path::new("."); + let base_path = settings.dir.as_path(); + info!("Using data dir: {:?}", &base_path); let ip_addr = Ipv4Addr::from_str(&settings.host).unwrap(); let tcp_port: u16 = settings.port;