diff --git a/src/config.rs b/src/config.rs index a17a43b..fb31d2c 100644 --- a/src/config.rs +++ b/src/config.rs @@ -94,7 +94,7 @@ impl SharedSettings { pub fn new_with_defaults(cli_args: &ArgMatches, config_file_defaults: &Self) -> Self { let default_hostname = DEFAULT_HOST.to_string(); let should_use_tls = - *cli_args.get_one::("tls").unwrap() || config_file_defaults.tls || false; + *cli_args.get_one::("tls").unwrap() || config_file_defaults.tls; let scheme = if should_use_tls { "https" } else { "http" }; let hostname = cli_args .get_one::("host") @@ -105,7 +105,7 @@ impl SharedSettings { .get_one::("port") .cloned() .or(config_file_defaults.port) - .or_else(|| { + .or({ if should_use_tls { Some(DEFAULT_HTTPS_PORT) } else { @@ -162,7 +162,7 @@ impl SharedSettings { let port: u16 = cli_args .get_one::("port") .cloned() - .or_else(|| { + .or({ if should_use_tls { Some(DEFAULT_HTTPS_PORT) } else { @@ -213,7 +213,7 @@ impl SharedSettings { let hostname = url.host_str().unwrap_or(DEFAULT_HOST).to_string(); let port = url .port() - .or_else(|| { + .or({ if should_use_tls { Some(DEFAULT_HTTPS_PORT) } else { @@ -263,7 +263,7 @@ impl SharedSettings { let hostname = url.host_str().unwrap_or(DEFAULT_HOST).to_string(); let port = url .port() - .or_else(|| { + .or({ if should_use_tls { Some(DEFAULT_HTTPS_PORT) } else { @@ -330,8 +330,7 @@ fn from_local_path(path: &PathBuf) -> Result fn read_from_local_path(path: &PathBuf) -> Result { let contents = std::fs::read_to_string(path)?; toml::from_str(&contents) - .and_then(|t| Ok(t)) - .map_err(|e| ConfigFileError::from(e)) + .map_err(ConfigFileError::from) } fn default_scheme() -> String { diff --git a/src/main.rs b/src/main.rs index d265e99..f824267 100644 --- a/src/main.rs +++ b/src/main.rs @@ -66,8 +66,8 @@ fn main() { ); process::exit(1) } - let sf = if cf_ss.is_ok() { - SharedSettings::from_args_with_defaults(&cli, &cf_ss.unwrap()) + let sf = if let Ok(val) = cf_ss { + SharedSettings::from_args_with_defaults(&cli, &val) } else { SharedSettings::from_args(&cli) };