Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do not add tool options to toml when they are the defaults #2982

Merged
merged 1 commit into from
Nov 10, 2024
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
10 changes: 10 additions & 0 deletions e2e/cli/test_use
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,13 @@ mise use -g dummy@1
assert "cat ~/.config/mise/config.toml" '[tools]
dummy = "1"'
rm -f ~/.config/mise/config.toml

mise use -g "ubi:cli/cli[exe=gh]"
assert "cat ~/.config/mise/config.toml" '[tools]
"ubi:cli/cli" = { version = "latest", exe = "gh" }'
rm -f ~/.config/mise/config.toml

mise use -g gh@2
assert "cat ~/.config/mise/config.toml" '[tools]
gh = "2"'
rm -f ~/.config/mise/config.toml
19 changes: 16 additions & 3 deletions src/config/config_file/mise_toml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use crate::config::env_directive::{EnvDirective, PathEntry};
use crate::config::settings::SettingsPartial;
use crate::config::AliasMap;
use crate::file::{create_dir_all, display_path};
use crate::registry::REGISTRY_BACKEND_MAP;
use crate::task::Task;
use crate::tera::{get_tera, BASE_CONTEXT};
use crate::toolset::{ToolRequest, ToolRequestSet, ToolSource, ToolVersionOptions};
Expand Down Expand Up @@ -285,11 +286,23 @@ impl ConfigFile for MiseToml {
versions: &[(String, ToolVersionOptions)],
) -> eyre::Result<()> {
let existing = self.tools.entry(fa.clone()).or_default();
let output_empty_opts = |opts: &ToolVersionOptions| {
if let Some(reg_ba) = REGISTRY_BACKEND_MAP
.get(fa.short.as_str())
.and_then(|b| b.first())
{
if reg_ba.opts.as_ref().is_some_and(|o| o == opts) {
// in this case the options specified are the same as in the registry so output no options and rely on the defaults
return true;
}
}
opts.is_empty()
};
existing.0 = versions
.iter()
.map(|(v, opts)| MiseTomlTool {
tt: ToolVersionType::Version(v.clone()),
options: if !opts.is_empty() {
options: if !output_empty_opts(opts) {
Some(opts.clone())
} else {
None
Expand All @@ -307,7 +320,7 @@ impl ConfigFile for MiseToml {
tools.remove(&fa.full.to_string());

if versions.len() == 1 {
if versions[0].1.is_empty() {
if output_empty_opts(&versions[0].1) {
tools.insert(&fa.short, value(versions[0].0.clone()));
} else {
let mut table = InlineTable::new();
Expand All @@ -320,7 +333,7 @@ impl ConfigFile for MiseToml {
} else {
let mut arr = Array::new();
for (v, opts) in versions {
if opts.is_empty() {
if output_empty_opts(opts) {
arr.push(v.to_string());
} else {
let mut table = InlineTable::new();
Expand Down
2 changes: 1 addition & 1 deletion src/toolset/tool_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ impl ToolVersion {
pub fn style(&self) -> String {
format!(
"{}{}",
style(&self.backend().full).blue().for_stderr(),
style(&self.backend().short).blue().for_stderr(),
style(&format!("@{}", &self.version)).for_stderr()
)
}
Expand Down
Loading