Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions e2e/cli/test_settings_set
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ assert_contains "mise settings -T" "all_compile = true"
mise settings unset all_compile
assert "mise settings get all_compile" "false"
assert_fail "mise settings get abcdefg" "mise ERROR Unknown setting: abcdefg"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

If the error message for unknown settings is updated to include brackets for consistency, this test case should be updated to match the new output.

assert_fail "mise settings get abcdefg" "mise ERROR Unknown setting: [abcdefg]"

assert_fail "mise settings get python.compyle" "mise ERROR Unknown setting: python.compyle"
assert_fail "mise settings get python.compile" "mise ERROR Setting [python.compile] is not set"
assert_fail "mise settings get cargo.registry_name" "mise ERROR Setting [cargo.registry_name] is not set"
Comment on lines 15 to +18

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To fully verify that the logic correctly distinguishes between unset known settings and actual typos (unknown settings), it is recommended to add a test case where a key has a valid prefix but an invalid leaf name (e.g., python.compyle). This ensures that the else block in src/cli/settings/get.rs is correctly reached when the full key is not present in SETTINGS_META.

assert_fail "mise settings get abcdefg" "mise ERROR Unknown setting: abcdefg"
assert_fail "mise settings get python.compyle" "mise ERROR Unknown setting: python.compyle"
assert_fail "mise settings get python.compile" "mise ERROR Setting [python.compile] is not set"
assert_fail "mise settings get cargo.registry_name" "mise ERROR Setting [cargo.registry_name] is not set"

assert "mise settings all_compile" "false"
assert "mise settings all_compile=1"
assert "mise settings all_compile" "true"
Expand Down
2 changes: 1 addition & 1 deletion e2e/cli/test_settings_unset
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
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"
assert_fail "mise settings get python.compile" "mise ERROR Setting [python.compile] is not set"
11 changes: 11 additions & 0 deletions src/cli/settings/get.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::config;
use crate::config::Settings;
use crate::config::settings::SETTINGS_META;
use eyre::bail;

/// Show a current setting
Expand Down Expand Up @@ -37,6 +38,8 @@ impl SettingsGet {
if let Some(v) = value.as_table().and_then(|t| t.get(k.0)) {
key = k.1;
value = v.clone()
} else if is_known_setting(&self.setting) {
bail!("Setting [{}] is not set", self.setting);
} else {
bail!("Unknown setting: {}", self.setting);
}
Expand All @@ -50,6 +53,14 @@ impl SettingsGet {
}
}

fn is_known_setting(key: &str) -> bool {
if SETTINGS_META.contains_key(key) {
return true;
}
let prefix = format!("{key}.");
SETTINGS_META.keys().any(|k| k.starts_with(&prefix))
}

static AFTER_LONG_HELP: &str = color_print::cstr!(
r#"<bold><underline>Examples:</underline></bold>

Expand Down
Loading