summaryrefslogtreecommitdiffstats
path: root/crates/core/tedge/src/cli/config/commands/set.rs
blob: 715f26649a8bd8cd6019018b25213c4db4c33b5e (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
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(())
    }
}