diff --git a/e2e/cli/test_settings_set b/e2e/cli/test_settings_set index d7f8b64099..6b69bb8960 100644 --- a/e2e/cli/test_settings_set +++ b/e2e/cli/test_settings_set @@ -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" +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" diff --git a/e2e/cli/test_settings_unset b/e2e/cli/test_settings_unset index 3a53c153a5..6dff414f1e 100644 --- a/e2e/cli/test_settings_unset +++ b/e2e/cli/test_settings_unset @@ -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" diff --git a/src/cli/settings/get.rs b/src/cli/settings/get.rs index b8603e85fb..7761a61807 100644 --- a/src/cli/settings/get.rs +++ b/src/cli/settings/get.rs @@ -1,5 +1,6 @@ use crate::config; use crate::config::Settings; +use crate::config::settings::SETTINGS_META; use eyre::bail; /// Show a current setting @@ -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); } @@ -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#"Examples: