Skip to content

Commit

Permalink
fix: settings unset does not work (jdx#2230)
Browse files Browse the repository at this point in the history
  • Loading branch information
roele authored May 31, 2024
1 parent cca3a8a commit a7a90a8
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/cli/settings/unset.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use eyre::Result;
use toml_edit::DocumentMut;

use crate::{env, file};
use crate::{config::settings::SettingsFile, env, file};

/// Clears a setting
///
Expand All @@ -17,9 +17,17 @@ impl SettingsUnset {
pub fn run(self) -> Result<()> {
let path = env::MISE_CONFIG_DIR.join("config.toml");
let raw = file::read_to_string(&path)?;
let mut settings: DocumentMut = raw.parse()?;
let mut config: DocumentMut = raw.parse()?;
if !config.contains_key("settings") {
return Ok(());
}
let settings = config["settings"].as_table_mut().unwrap();
settings.remove(&self.setting);
file::write(&path, settings.to_string())

// validate
let _: SettingsFile = toml::from_str(&config.to_string())?;

file::write(&path, config.to_string())
}
}

Expand All @@ -38,7 +46,7 @@ mod tests {
fn test_settings_unset() {
reset();

assert_cli!("settings", "unset", "legacy_version_file");
assert_cli!("settings", "unset", "jobs");

assert_cli_snapshot!("settings", @r###"
activate_aggressive = false
Expand All @@ -58,7 +66,7 @@ mod tests {
go_set_goroot = true
go_skip_checksum = false
http_timeout = 30
jobs = 2
jobs = 4
legacy_version_file = true
legacy_version_file_disable_tools = []
node_compile = false
Expand Down

0 comments on commit a7a90a8

Please sign in to comment.