Browse Source

Fixing config values not being preferred over defaults.

develop
Drew Short 6 years ago
parent
commit
da1a8e9e58
  1. 5
      src/args/mod.rs
  2. 4
      src/args/parse.rs

5
src/args/mod.rs

@ -1,9 +1,9 @@
use clap::{App, Arg};
use crate::VERSION;
use crate::DEFAULT_HOST;
use crate::DEFAULT_PORT_STR;
use crate::DEFAULT_WORKERS_STR;
use crate::VERSION;
pub mod parse;
@ -24,21 +24,18 @@ pub fn get_app() -> App<'static, 'static> {
.short("h")
.long("host")
.value_name("HOST")
.default_value(&DEFAULT_HOST)
.help("The address the server listens on.")
.takes_value(true),
Arg::with_name("port")
.short("p")
.long("port")
.value_name("PORT")
.default_value(&DEFAULT_PORT_STR)
.help("The port to run the server on.")
.takes_value(true),
Arg::with_name("workers")
.short("w")
.long("workers")
.value_name("NUMBER")
.default_value(&DEFAULT_WORKERS_STR)
.help("The number of workers to serve requests with (Defaults to the number of cores on the system).")
.takes_value(true),
])

4
src/args/parse.rs

@ -5,6 +5,7 @@ use clap::ArgMatches;
use crate::config::model::Config;
fn get_config_for_string(arg_value: Option<&str>, config_value: &Option<String>, default_value: &str) -> String {
debug!("arg: {:?}; config: {:?}; default: {}", arg_value, config_value, default_value);
String::from(match arg_value {
Some(v) => v,
None => match config_value {
@ -14,7 +15,8 @@ fn get_config_for_string(arg_value: Option<&str>, config_value: &Option<String>,
})
}
fn get_config_for_number<T: FromStr>(arg_value: Option<&str>, config_value: Option<T>, default_value: T) -> T {
fn get_config_for_number<T: FromStr + std::fmt::Debug>(arg_value: Option<&str>, config_value: Option<T>, default_value: T) -> T {
debug!("arg: {:?}; config: {:?}; default: {:?}", arg_value, config_value, default_value);
match arg_value {
Some(v) => v.parse::<T>().unwrap_or(default_value),
None => match config_value {

Loading…
Cancel
Save