Skip to content

Commit

Permalink
fix: retain "os" options in mise up --bump (#3688)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx authored Dec 18, 2024
1 parent ab902be commit 1670ae4
Show file tree
Hide file tree
Showing 12 changed files with 77 additions and 106 deletions.
10 changes: 10 additions & 0 deletions e2e/cli/test_upgrade
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,13 @@ Would install dummy@2.0.0
Would bump dummy@prefix:2 in ~/workdir/mise.toml"
mise up dummy --bump
assert "mise ls dummy" "dummy 2.0.0 ~/workdir/mise.toml prefix:2"

cat <<EOF >mise.toml
[tools]
dummy = "latest"
EOF
assert "mise uninstall dummy --all"
assert "mise i dummy@1.0.0"
assert "mise up --bump"
assert "cat mise.toml" '[tools]
dummy = "latest"'
2 changes: 1 addition & 1 deletion src/backend/asdf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ impl AsdfBackend {
let k = format!("MISE_TOOL_OPTS__{}", key.to_uppercase());
sm = sm.with_env(k, value.clone());
}
for (key, value) in tv.request.options().env {
for (key, value) in tv.request.options().install_env {
sm = sm.with_env(key, value.clone());
}
if let Some(project_root) = &config.project_root {
Expand Down
1 change: 0 additions & 1 deletion src/cli/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ impl Install {
let tvr = ToolRequest::Version {
backend: ta.ba.clone(),
version: "latest".into(),
os: None,
options: ta.ba.opts(),
source: ToolSource::Argument,
};
Expand Down
2 changes: 0 additions & 2 deletions src/cli/use.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,13 @@ impl Use {
if let ToolRequest::Version {
version: _version,
source,
os,
options,
backend,
} = request
{
request = ToolRequest::Version {
version: tv.version.clone(),
source,
os,
options,
backend,
};
Expand Down
70 changes: 31 additions & 39 deletions src/config/config_file/mise_toml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ pub struct MiseTomlToolList(Vec<MiseTomlTool>);
#[derive(Debug, Clone)]
pub struct MiseTomlTool {
pub tt: ToolVersionType,
pub os: Option<Vec<String>>,
pub options: Option<ToolVersionOptions>,
}

Expand Down Expand Up @@ -329,6 +328,9 @@ impl ConfigFile for MiseToml {
let is_tools_sorted = is_tools_sorted(&self.tools); // was it previously sorted (if so we'll keep it sorted)
let existing = self.tools.entry(ba.clone()).or_default();
let output_empty_opts = |opts: &ToolVersionOptions| {
if opts.os.is_some() || !opts.install_env.is_empty() {
return false;
}
if let Some(reg_ba) = REGISTRY.get(ba.short.as_str()).and_then(|b| b.ba()) {
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
Expand Down Expand Up @@ -357,14 +359,29 @@ impl ConfigFile for MiseToml {
}

if versions.len() == 1 {
if output_empty_opts(&versions[0].options()) {
let options = versions[0].options();
if output_empty_opts(&options) {
tools.insert_formatted(&key, value(versions[0].version()));
} else {
let mut table = InlineTable::new();
table.insert("version", versions[0].version().into());
for (k, v) in versions[0].options().opts {
for (k, v) in options.opts {
table.insert(k, v.into());
}
if let Some(os) = options.os {
let mut arr = Array::new();
for o in os {
arr.push(Value::from(o));
}
table.insert("os", Value::Array(arr));
}
if !options.install_env.is_empty() {
let mut env = InlineTable::new();
for (k, v) in options.install_env {
env.insert(k, v.into());
}
table.insert("install_env", env.into());
}
tools.insert_formatted(&key, table.into());
}
} else {
Expand Down Expand Up @@ -416,15 +433,14 @@ impl ConfigFile for MiseToml {
for (ba, tvp) in &self.tools {
for tool in &tvp.0 {
let version = self.parse_template(&tool.tt.to_string())?;
let mut tvr = if let Some(mut options) = tool.options.clone() {
let tvr = if let Some(mut options) = tool.options.clone() {
for v in options.opts.values_mut() {
*v = self.parse_template(v)?;
}
ToolRequest::new_opts(ba.clone(), &version, options, source.clone())?
} else {
ToolRequest::new(ba.clone(), &version, source.clone())?
};
tvr = tvr.with_os(tool.os.clone());
trs.add_version(tvr, &source);
}
}
Expand Down Expand Up @@ -572,13 +588,11 @@ impl From<ToolRequest> for MiseTomlTool {
match tr {
ToolRequest::Version {
version,
os,
options,
backend: _backend,
source: _source,
} => Self {
tt: ToolVersionType::Version(version),
os,
options: if options.is_empty() {
None
} else {
Expand All @@ -587,13 +601,11 @@ impl From<ToolRequest> for MiseTomlTool {
},
ToolRequest::Path {
path,
os,
options,
backend: _backend,
source: _source,
} => Self {
tt: ToolVersionType::Path(path),
os,
options: if options.is_empty() {
None
} else {
Expand All @@ -602,13 +614,11 @@ impl From<ToolRequest> for MiseTomlTool {
},
ToolRequest::Prefix {
prefix,
os,
options,
backend: _backend,
source: _source,
} => Self {
tt: ToolVersionType::Prefix(prefix),
os,
options: if options.is_empty() {
None
} else {
Expand All @@ -618,13 +628,11 @@ impl From<ToolRequest> for MiseTomlTool {
ToolRequest::Ref {
ref_,
ref_type,
os,
options,
backend: _backend,
source: _source,
} => Self {
tt: ToolVersionType::Ref(ref_, ref_type),
os,
options: if options.is_empty() {
None
} else {
Expand All @@ -633,28 +641,24 @@ impl From<ToolRequest> for MiseTomlTool {
},
ToolRequest::Sub {
sub,
os,
options,
orig_version,
backend: _backend,
source: _source,
} => Self {
tt: ToolVersionType::Sub { sub, orig_version },
os,
options: if options.is_empty() {
None
} else {
Some(options)
},
},
ToolRequest::System {
os,
options,
backend: _backend,
source: _source,
} => Self {
tt: ToolVersionType::System,
os,
options: if options.is_empty() {
None
} else {
Expand Down Expand Up @@ -1049,11 +1053,7 @@ impl<'de> de::Deserialize<'de> for MiseTomlToolList {
let tt: ToolVersionType = v
.parse()
.map_err(|e| de::Error::custom(format!("invalid tool: {e}")))?;
Ok(MiseTomlToolList(vec![MiseTomlTool {
tt,
os: None,
options: None,
}]))
Ok(MiseTomlToolList(vec![MiseTomlTool { tt, options: None }]))
}

fn visit_seq<S>(self, mut seq: S) -> std::result::Result<Self::Value, S::Error>
Expand All @@ -1072,7 +1072,6 @@ impl<'de> de::Deserialize<'de> for MiseTomlToolList {
M: de::MapAccess<'de>,
{
let mut options: ToolVersionOptions = Default::default();
let mut os: Option<Vec<String>> = None;
let mut tt: Option<ToolVersionType> = None;
while let Some((k, v)) = map.next_entry::<String, toml::Value>()? {
match k.as_str() {
Expand All @@ -1088,7 +1087,7 @@ impl<'de> de::Deserialize<'de> for MiseTomlToolList {
}
"os" => match v {
toml::Value::Array(s) => {
os = Some(
options.os = Some(
s.iter().map(|v| v.as_str().unwrap().to_string()).collect(),
);
}
Expand All @@ -1104,13 +1103,13 @@ impl<'de> de::Deserialize<'de> for MiseTomlToolList {
for (k, v) in env {
match v {
toml::Value::Boolean(v) => {
options.env.insert(k, v.to_string());
options.install_env.insert(k, v.to_string());
}
toml::Value::Integer(v) => {
options.env.insert(k, v.to_string());
options.install_env.insert(k, v.to_string());
}
toml::Value::String(v) => {
options.env.insert(k, v);
options.install_env.insert(k, v);
}
_ => {
return Err(de::Error::custom("invalid value type"));
Expand Down Expand Up @@ -1141,7 +1140,6 @@ impl<'de> de::Deserialize<'de> for MiseTomlToolList {
if let Some(tt) = tt {
Ok(MiseTomlToolList(vec![MiseTomlTool {
tt,
os,
options: Some(options),
}]))
} else {
Expand Down Expand Up @@ -1242,19 +1240,14 @@ impl<'de> de::Deserialize<'de> for MiseTomlTool {
let tt: ToolVersionType = v
.parse()
.map_err(|e| de::Error::custom(format!("invalid tool: {e}")))?;
Ok(MiseTomlTool {
tt,
os: None,
options: None,
})
Ok(MiseTomlTool { tt, options: None })
}

fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
where
M: de::MapAccess<'de>,
{
let mut options: ToolVersionOptions = Default::default();
let mut os: Option<Vec<String>> = None;
let mut tt = ToolVersionType::System;
while let Some((k, v)) = map.next_entry::<String, toml::Value>()? {
match k.as_str() {
Expand All @@ -1268,7 +1261,7 @@ impl<'de> de::Deserialize<'de> for MiseTomlTool {
}
"os" => match v {
toml::Value::Array(s) => {
os = Some(
options.os = Some(
s.iter().map(|v| v.as_str().unwrap().to_string()).collect(),
);
}
Expand All @@ -1284,13 +1277,13 @@ impl<'de> de::Deserialize<'de> for MiseTomlTool {
for (k, v) in env {
match v {
toml::Value::Boolean(v) => {
options.env.insert(k, v.to_string());
options.install_env.insert(k, v.to_string());
}
toml::Value::Integer(v) => {
options.env.insert(k, v.to_string());
options.install_env.insert(k, v.to_string());
}
toml::Value::String(v) => {
options.env.insert(k, v);
options.install_env.insert(k, v);
}
_ => {
return Err(de::Error::custom("invalid value type"));
Expand All @@ -1309,7 +1302,6 @@ impl<'de> de::Deserialize<'de> for MiseTomlTool {
}
Ok(MiseTomlTool {
tt,
os,
options: Some(options),
})
}
Expand Down
2 changes: 0 additions & 2 deletions src/config/config_file/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,13 @@ impl dyn ConfigFile {
if let ToolRequest::Version {
version: _version,
source,
os,
options,
backend,
} = tr
{
tr = ToolRequest::Version {
version: tv.version,
source,
os,
options,
backend,
};
Expand Down
Loading

0 comments on commit 1670ae4

Please sign in to comment.