use config::builder::DefaultState;
use config::ConfigBuilder;
use slog::Logger;
use std::collections::HashMap;
use mithril_client::MithrilResult;
use crate::configuration::ConfigParameters;
pub struct CommandContext {
config_builder: ConfigBuilder<DefaultState>,
unstable_enabled: bool,
logger: Logger,
}
impl CommandContext {
pub fn new(
config_builder: ConfigBuilder<DefaultState>,
unstable_enabled: bool,
logger: Logger,
) -> Self {
Self {
config_builder,
unstable_enabled,
logger,
}
}
pub fn is_unstable_enabled(&self) -> bool {
self.unstable_enabled
}
pub fn config_parameters(&self) -> MithrilResult<ConfigParameters> {
let config = self.config_builder.clone().build()?;
let config_hash_map = config.try_deserialize::<HashMap<String, String>>()?;
Ok(ConfigParameters::new(config_hash_map))
}
pub fn logger(&self) -> &Logger {
&self.logger
}
}