mithril_client_cli/
command_context.rs

1use config::builder::DefaultState;
2use config::ConfigBuilder;
3use slog::Logger;
4use std::collections::HashMap;
5
6use mithril_client::MithrilResult;
7
8use crate::configuration::ConfigParameters;
9
10/// Context for the command execution
11pub struct CommandContext {
12    config_builder: ConfigBuilder<DefaultState>,
13    unstable_enabled: bool,
14    logger: Logger,
15}
16
17impl CommandContext {
18    /// Create a new command context
19    pub fn new(
20        config_builder: ConfigBuilder<DefaultState>,
21        unstable_enabled: bool,
22        logger: Logger,
23    ) -> Self {
24        Self {
25            config_builder,
26            unstable_enabled,
27            logger,
28        }
29    }
30
31    /// Check if unstable commands are enabled
32    pub fn is_unstable_enabled(&self) -> bool {
33        self.unstable_enabled
34    }
35
36    /// Get the configured parameters
37    pub fn config_parameters(&self) -> MithrilResult<ConfigParameters> {
38        let config = self.config_builder.clone().build()?;
39        let config_hash_map = config.try_deserialize::<HashMap<String, String>>()?;
40        Ok(ConfigParameters::new(config_hash_map))
41    }
42
43    /// Get the shared logger
44    pub fn logger(&self) -> &Logger {
45        &self.logger
46    }
47}