From 2c049cf680a2c10dd2d7fa1e3d21bca77c3c0aa4 Mon Sep 17 00:00:00 2001 From: jdx <216188+jdx@users.noreply.github.com> Date: Sun, 12 Jan 2025 06:07:51 -0600 Subject: [PATCH 1/2] refactor: use better rust syntax --- src/cli/config/set.rs | 150 +++++++++++++++++++++--------------------- 1 file changed, 74 insertions(+), 76 deletions(-) diff --git a/src/cli/config/set.rs b/src/cli/config/set.rs index 52c65ffd2e..783eabbad8 100644 --- a/src/cli/config/set.rs +++ b/src/cli/config/set.rs @@ -47,89 +47,87 @@ impl ConfigSet { if file.is_none() { file = top_toml_config(); } - if let Some(file) = file { - let mut config: toml_edit::DocumentMut = std::fs::read_to_string(&file)?.parse()?; - let mut container = config.as_item_mut(); - let parts = self.key.split('.').collect::>(); - let last_key = parts.last().unwrap(); - for (idx, key) in parts.iter().take(parts.len() - 1).enumerate() { - container = container - .as_table_like_mut() - .unwrap() - .entry(key) - .or_insert({ - let mut t = toml_edit::Table::new(); - t.set_implicit(true); - toml_edit::Item::Table(t) - }); - // if the key is a tool with a simple value, we want to convert it to a inline table preserving the version - let is_simple_tool_version = - self.key.starts_with("tools.") && idx == 1 && !container.is_table_like(); - if is_simple_tool_version { - let mut inline_table = toml_edit::InlineTable::new(); - inline_table.insert("version", container.as_value().unwrap().clone()); - *container = - toml_edit::Item::Value(toml_edit::Value::InlineTable(inline_table)); - } + let Some(file) = file else { + bail!("No mise.toml file found"); + }; + let mut config: toml_edit::DocumentMut = std::fs::read_to_string(&file)?.parse()?; + let mut container = config.as_item_mut(); + let parts = self.key.split('.').collect::>(); + let last_key = parts.last().unwrap(); + for (idx, key) in parts.iter().take(parts.len() - 1).enumerate() { + container = container + .as_table_like_mut() + .unwrap() + .entry(key) + .or_insert({ + let mut t = toml_edit::Table::new(); + t.set_implicit(true); + toml_edit::Item::Table(t) + }); + // if the key is a tool with a simple value, we want to convert it to a inline table preserving the version + let is_simple_tool_version = + self.key.starts_with("tools.") && idx == 1 && !container.is_table_like(); + if is_simple_tool_version { + let mut inline_table = toml_edit::InlineTable::new(); + inline_table.insert("version", container.as_value().unwrap().clone()); + *container = toml_edit::Item::Value(toml_edit::Value::InlineTable(inline_table)); } + } - let type_to_use = match self.type_ { - TomlValueTypes::Infer => { - let expected_type = if !self.key.starts_with("settings.") { - None - } else { - SETTINGS_META.get(*last_key) - }; - match expected_type { - Some(meta) => match meta.type_ { - SettingsType::Bool => TomlValueTypes::Bool, - SettingsType::String => TomlValueTypes::String, - SettingsType::Integer => TomlValueTypes::Integer, - SettingsType::Duration => TomlValueTypes::String, - SettingsType::Path => TomlValueTypes::String, - SettingsType::Url => TomlValueTypes::String, - SettingsType::ListString => TomlValueTypes::List, - SettingsType::ListPath => TomlValueTypes::List, - }, - None => match self.value.as_str() { - "true" | "false" => TomlValueTypes::Bool, - _ => TomlValueTypes::String, - }, - } + let type_to_use = match self.type_ { + TomlValueTypes::Infer => { + let expected_type = if !self.key.starts_with("settings.") { + None + } else { + SETTINGS_META.get(*last_key) + }; + match expected_type { + Some(meta) => match meta.type_ { + SettingsType::Bool => TomlValueTypes::Bool, + SettingsType::String => TomlValueTypes::String, + SettingsType::Integer => TomlValueTypes::Integer, + SettingsType::Duration => TomlValueTypes::String, + SettingsType::Path => TomlValueTypes::String, + SettingsType::Url => TomlValueTypes::String, + SettingsType::ListString => TomlValueTypes::List, + SettingsType::ListPath => TomlValueTypes::List, + }, + None => match self.value.as_str() { + "true" | "false" => TomlValueTypes::Bool, + _ => TomlValueTypes::String, + }, } - _ => self.type_, - }; + } + _ => self.type_, + }; - let value = match type_to_use { - TomlValueTypes::String => toml_edit::value(self.value), - TomlValueTypes::Integer => toml_edit::value(self.value.parse::()?), - TomlValueTypes::Float => toml_edit::value(self.value.parse::()?), - TomlValueTypes::Bool => toml_edit::value(self.value.parse::()?), - TomlValueTypes::List => { - let mut list = toml_edit::Array::new(); - for item in self.value.split(',').map(|s| s.trim()) { - list.push(item); - } - toml_edit::Item::Value(toml_edit::Value::Array(list)) + let value = match type_to_use { + TomlValueTypes::String => toml_edit::value(self.value), + TomlValueTypes::Integer => toml_edit::value(self.value.parse::()?), + TomlValueTypes::Float => toml_edit::value(self.value.parse::()?), + TomlValueTypes::Bool => toml_edit::value(self.value.parse::()?), + TomlValueTypes::List => { + let mut list = toml_edit::Array::new(); + for item in self.value.split(',').map(|s| s.trim()) { + list.push(item); } - TomlValueTypes::Infer => bail!("Type not found"), - }; + toml_edit::Item::Value(toml_edit::Value::Array(list)) + } + TomlValueTypes::Infer => bail!("Type not found"), + }; - container - .as_table_like_mut() - .unwrap_or({ - let mut t = toml_edit::Table::new(); - t.set_implicit(true); - toml_edit::Item::Table(t).as_table_like_mut().unwrap() - }) - .insert(last_key, value); + container + .as_table_like_mut() + .unwrap_or({ + let mut t = toml_edit::Table::new(); + t.set_implicit(true); + toml_edit::Item::Table(t).as_table_like_mut().unwrap() + }) + .insert(last_key, value); - let raw = config.to_string(); - MiseToml::from_str(&raw, &file)?; - std::fs::write(&file, raw)?; - } else { - bail!("No mise.toml file found"); - } + let raw = config.to_string(); + MiseToml::from_str(&raw, &file)?; + std::fs::write(&file, raw)?; Ok(()) } } From 21c089befc9a898202cf45fc129405665e276aa9 Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Sun, 12 Jan 2025 12:14:31 +0000 Subject: [PATCH 2/2] [autofix.ci] apply automated fixes --- registry.toml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/registry.toml b/registry.toml index 1260f9621c..10cfb7fddb 100644 --- a/registry.toml +++ b/registry.toml @@ -584,7 +584,9 @@ etcd.backends = [ ] etcd.test = ["etcd --version", "etcd Version: {{version}}"] evans.backends = ["aqua:ktr0731/evans", "asdf:goki90210/asdf-evans"] -eza.backends = ["asdf:mise-plugins/mise-eza"] # eza does not offer precompiled macos binaries +eza.backends = [ + "asdf:mise-plugins/mise-eza" +] # eza does not offer precompiled macos binaries fd.backends = [ "aqua:sharkdp/fd", "ubi:sharkdp/fd",