summaryrefslogtreecommitdiffstats
path: root/crates/core/tedge/src/cli/config/commands/unset.rs
blob: 222d8a3ecb67dfd3d3849ece8dc042868700b05f (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
use crate::cli::config::ConfigKey;
use crate::command::Command;
use tedge_config::*;

pub struct UnsetConfigCommand {
    pub config_key: ConfigKey,
    pub config_repository: TEdgeConfigRepository,
}

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

    fn execute(&self) -> anyhow::Result<()> {
        let mut config = self.config_repository.load()?;
        let () = (self.config_key.unset)(&mut config)?;
        self.config_repository.store(&config)?;
        Ok(())
    }
}