Skip to content

Commit

Permalink
fix: mise settings unset does not seem to work
Browse files Browse the repository at this point in the history
  • Loading branch information
roele committed Dec 30, 2024
1 parent 101167c commit 18003be
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 19 deletions.
6 changes: 6 additions & 0 deletions e2e/cli/test_settings_unset
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

mise settings set python.compile true
assert "mise settings get python.compile" "true"
mise settings unset python.compile
assert_fail "mise settings get python.compile" "mise ERROR Unknown setting: python.compile"
38 changes: 19 additions & 19 deletions src/cli/settings/unset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,26 @@ pub fn unset(mut key: &str, local: bool) -> Result<()> {
};
let raw = file::read_to_string(&path)?;
let mut config: DocumentMut = raw.parse()?;
if !config.contains_key("settings") {
return Ok(());
if let Some(mut settings) = config["settings"].as_table_mut() {
if let Some((parent_key, child_key)) = key.split_once('.') {
key = child_key;
settings = settings
.entry(parent_key)
.or_insert({
let mut t = toml_edit::Table::new();
t.set_implicit(true);
toml_edit::Item::Table(t)
})
.as_table_mut()
.unwrap();
}
settings.remove(key);
// validate
let _: SettingsFile = toml::from_str(&config.to_string())?;

file::write(&path, config.to_string())?;
}
let mut settings = config["settings"].as_table_mut().unwrap();
if key.contains(".") {
let (parent_key, child_key) = key.split_once('.').unwrap();

key = child_key;
settings = settings
.entry(parent_key)
.or_insert(toml_edit::Item::Table(toml_edit::Table::new()))
.as_table_mut()
.unwrap();
}
settings.remove(key);

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

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

static AFTER_LONG_HELP: &str = color_print::cstr!(
Expand Down

0 comments on commit 18003be

Please sign in to comment.