diff options
Diffstat (limited to 'crates/core/tedge/src/cli/config/commands/get.rs')
-rw-r--r-- | crates/core/tedge/src/cli/config/commands/get.rs | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/crates/core/tedge/src/cli/config/commands/get.rs b/crates/core/tedge/src/cli/config/commands/get.rs new file mode 100644 index 00000000..4cb0f1cc --- /dev/null +++ b/crates/core/tedge/src/cli/config/commands/get.rs @@ -0,0 +1,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(()) + } +} |