summaryrefslogtreecommitdiffstats
path: root/crates/core/tedge/src/cli/config/commands/set.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/core/tedge/src/cli/config/commands/set.rs')
-rw-r--r--crates/core/tedge/src/cli/config/commands/set.rs25
1 files changed, 25 insertions, 0 deletions
diff --git a/crates/core/tedge/src/cli/config/commands/set.rs b/crates/core/tedge/src/cli/config/commands/set.rs
new file mode 100644
index 00000000..715f2664
--- /dev/null
+++ b/crates/core/tedge/src/cli/config/commands/set.rs
@@ -0,0 +1,25 @@
+use crate::cli::config::ConfigKey;
+use crate::command::Command;
+use tedge_config::*;
+
+pub struct SetConfigCommand {
+ pub config_key: ConfigKey,
+ pub value: String,
+ pub config_repository: TEdgeConfigRepository,
+}
+
+impl Command for SetConfigCommand {
+ fn description(&self) -> String {
+ format!(
+ "set the configuration key: {} with value: {}.",
+ self.config_key.key, self.value
+ )
+ }
+
+ fn execute(&self) -> anyhow::Result<()> {
+ let mut config = self.config_repository.load()?;
+ let () = (self.config_key.set)(&mut config, self.value.to_string())?;
+ self.config_repository.store(&config)?;
+ Ok(())
+ }
+}