iqlusioninc / abscissa

Application microframework with command-line option parsing, configuration, error handling, logging, and shell interactions
Apache License 2.0
573 stars 39 forks source link

config::Override implementation not being called #819

Open cbrit opened 1 year ago

cbrit commented 1 year ago

Rust: 1.67 Abscissa: 0.6.0

I have a bool config field config.simulate.enabled that I'd like to override with the start command flag --simulate. My override looks like this:

impl config::Override<StewardConfig> for StartCmd {
    fn override_config(&self, mut config: StewardConfig) -> Result<StewardConfig, FrameworkError> {
        if self.simulate {
            config.simulate.enabled = self.simulate;
        }

        Ok(config)
    }
}

The config value is not being updated even though the flag is set. I've tried logging inside of override_config() to see if it is entered at all in case the value is is overwritten somewhere else, and it seems that the method is never actually called.

2023-02-08T15:05:23.769547Z  INFO steward::commands::start: simulate flag: true, simulate enabled in config: false

If it were working, both would be true

aawsome commented 1 year ago

I think you should call it by yourself, e.g. by using/providing process_config() in your Configurable impl, e.g. something like

process_config(&self, config: StewardConfig) -> ... {
  match &self.cmd {
    ...:Start(cmd) => cmd.override_config(config),
    _ => Ok(config),
  }
}