summaryrefslogtreecommitdiffstats
path: root/crates/core/tedge/src/cli/config/commands/get.rs
blob: 4cb0f1cc2456006fdea0ff26fe8991c96901eea9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
use crate::cli::config::ConfigKey;
use crate::command::Command;

pub struct GetConfigCommand {
    pub config_key: ConfigKey,
    pub config: tedge_config::TEdgeConfig,
}

impl Command for GetConfigCommand {
    fn description(&self) -> String {
        format!(
            "get the configuration value for key: {}",
            self.config_key.key
        )
    }

    fn execute(&self) -> anyhow::Result<()> {
        match (self.config_key.get)(&self.config) {
            Ok(value) => {
                println!("{}", value);
            }
            Err(tedge_config::ConfigSettingError::ConfigNotSet { .. }) => {
                println!(
                    "The provided config key: '{}' is not set",
                    self.config_key.key
                );
            }
            Err(tedge_config::ConfigSettingError::SettingIsNotConfigurable { .. }) => {
                println!(
                    "The provided config key: '{}' is not configurable",
                    self.config_key.key
                );
            }
            Err(err) => return Err(err.into()),
        }

        Ok(())
    }
}