mirror of
https://github.com/nitnelave/lldap.git
synced 2023-04-12 14:25:13 +00:00
Fix bug in config from cli flags
The flag value (true/false) was always provided to the configuration, which means that the cli was overriding everything else.
This commit is contained in:
parent
009ffd793b
commit
ffce735b79
@ -10,7 +10,7 @@ use crate::infra::cli::CLIOpts;
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
pub struct Configuration {
|
||||
pub log_level_verbose: bool,
|
||||
pub verbose: bool,
|
||||
pub secret_pepper: String,
|
||||
pub some_text: String,
|
||||
}
|
||||
@ -18,7 +18,7 @@ pub struct Configuration {
|
||||
impl Default for Configuration {
|
||||
fn default() -> Self {
|
||||
Configuration {
|
||||
log_level_verbose: false,
|
||||
verbose: false,
|
||||
secret_pepper: String::from("secretsecretpepper"),
|
||||
some_text: String::new(),
|
||||
}
|
||||
@ -27,9 +27,13 @@ impl Default for Configuration {
|
||||
|
||||
impl Configuration {
|
||||
fn from_cli(cli_opts: CLIOpts) -> Figment {
|
||||
let config_opts_from_cli = map! {
|
||||
"log_level_verbose" => cli_opts.verbose
|
||||
};
|
||||
let mut config_opts_from_cli = map!();
|
||||
|
||||
// XXX only add the option if given so that the `false` value don't override a
|
||||
// previous configuration
|
||||
if cli_opts.verbose {
|
||||
config_opts_from_cli.insert("verbose", true);
|
||||
}
|
||||
|
||||
Figment::new().join(Serialized::defaults(config_opts_from_cli))
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ pub fn init(config: Configuration) -> anyhow::Result<()> {
|
||||
}
|
||||
|
||||
fn log_level_from_config(config: Configuration) -> tracing::Level {
|
||||
if config.log_level_verbose {
|
||||
if config.verbose {
|
||||
tracing::Level::DEBUG
|
||||
} else {
|
||||
tracing::Level::INFO
|
||||
|
@ -8,9 +8,10 @@ fn main() -> Result<()> {
|
||||
let config = infra::configuration::init(cli_opts.clone())?;
|
||||
infra::logging::init(config.clone())?;
|
||||
|
||||
info!("Starting....");
|
||||
debug!("Config: {:?}", config);
|
||||
debug!("CLI: {:?}", cli_opts);
|
||||
info!("Starting LLDAP....");
|
||||
|
||||
debug!("CLI: {:#?}", cli_opts);
|
||||
debug!("Configuration: {:#?}", config);
|
||||
info!("End.");
|
||||
Ok(())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user