|
|
@ -24,33 +24,17 @@ fn get_config_for_number<T: FromStr>(arg_value: Option<&str>, config_value: Opti |
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn get_number<T: FromStr>(arg_value: Option<&str>, default_value: T) -> T {
|
|
|
|
match arg_value {
|
|
|
|
Some(value) => value.parse::<T>().unwrap_or(default_value),
|
|
|
|
None => default_value
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get_host(args: &ArgMatches, config: &Option<Config>, default_host: &str) -> String {
|
|
|
|
pub fn get_host(args: &ArgMatches, config: &Config, default_host: &str) -> String {
|
|
|
|
let arg_value = args.value_of("host");
|
|
|
|
match &config {
|
|
|
|
Some(c) => get_config_for_string(arg_value, &c.server.host, default_host),
|
|
|
|
None => String::from(arg_value.unwrap_or(default_host))
|
|
|
|
}.clone()
|
|
|
|
get_config_for_string(arg_value, &config.server.host, default_host).clone()
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get_port(args: &ArgMatches, config: &Option<Config>, default_port: i16) -> i16 {
|
|
|
|
pub fn get_port(args: &ArgMatches, config: &Config, default_port: i16) -> i16 {
|
|
|
|
let arg_value = args.value_of("port");
|
|
|
|
match &config {
|
|
|
|
Some(c) => get_config_for_number(arg_value, c.server.port, default_port),
|
|
|
|
None => get_number(arg_value, default_port)
|
|
|
|
}
|
|
|
|
get_config_for_number(arg_value, config.server.port, default_port)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get_workers(args: &ArgMatches, config: &Option<Config>, default_workers: usize) -> usize {
|
|
|
|
pub fn get_workers(args: &ArgMatches, config: &Config, default_workers: usize) -> usize {
|
|
|
|
let arg_value = args.value_of("workers");
|
|
|
|
match &config {
|
|
|
|
Some(c) => get_config_for_number(arg_value, c.server.workers, default_workers),
|
|
|
|
None => get_number(arg_value, default_workers)
|
|
|
|
}
|
|
|
|
get_config_for_number(arg_value, config.server.workers, default_workers)
|
|
|
|
}
|