Skip to content

Commit

Permalink
fix: retain "os" options in mise up --bump
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed Dec 18, 2024
1 parent ab902be commit 14e96d2
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 75 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
60 changes: 29 additions & 31 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 @@ -1051,7 +1055,6 @@ impl<'de> de::Deserialize<'de> for MiseTomlToolList {
.map_err(|e| de::Error::custom(format!("invalid tool: {e}")))?;
Ok(MiseTomlToolList(vec![MiseTomlTool {
tt,
os: None,
options: None,
}]))
}
Expand All @@ -1072,7 +1075,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 +1090,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 +1106,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 +1143,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 @@ -1244,7 +1245,6 @@ impl<'de> de::Deserialize<'de> for MiseTomlTool {
.map_err(|e| de::Error::custom(format!("invalid tool: {e}")))?;
Ok(MiseTomlTool {
tt,
os: None,
options: None,
})
}
Expand All @@ -1254,7 +1254,6 @@ impl<'de> de::Deserialize<'de> for MiseTomlTool {
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 +1267,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 +1283,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 +1308,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
6 changes: 3 additions & 3 deletions src/toolset/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,15 @@ mod tool_version_list;

#[derive(Debug, Default, Clone, Hash, PartialEq, Eq, serde::Deserialize, serde::Serialize)]
pub struct ToolVersionOptions {
pub env: BTreeMap<String, String>,
pub os: Option<Vec<String>>,
pub install_env: BTreeMap<String, String>,
#[serde(flatten)]
pub opts: BTreeMap<String, String>,
}

impl ToolVersionOptions {
pub fn is_empty(&self) -> bool {
self.env.is_empty() && self.opts.is_empty()
self.install_env.is_empty() && self.opts.is_empty()
}

pub fn get(&self, key: &str) -> Option<&String> {
Expand Down Expand Up @@ -407,7 +408,6 @@ impl Toolset {
backend: p.ba().clone(),
ref_: r.to_string(),
ref_type: ref_type.to_string(),
os: v.request.os().clone(),
options: v.request.options().clone(),
source: v.request.source().clone(),
};
Expand Down
7 changes: 3 additions & 4 deletions src/toolset/outdated_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,12 @@ impl OutdatedInfo {
backend,
options,
source,
os,
} => {
oi.tool_request = ToolRequest::Version {
backend,
options,
source,
version: format!("{prefix}{bumped_version}"),
os,
};
Some(oi.tool_request.version())
}
Expand All @@ -105,14 +103,12 @@ impl OutdatedInfo {
backend,
options,
source,
os,
} => {
oi.tool_request = ToolRequest::Prefix {
backend,
options,
source,
prefix: format!("{prefix}{bumped_version}"),
os,
};
Some(oi.tool_request.version())
}
Expand Down Expand Up @@ -165,6 +161,9 @@ impl Display for OutdatedInfo {
/// used with `mise outdated --bump` to determine what new semver range to use
/// given old: "20" and new: "21.2.3", return Some("21")
fn check_semver_bump(old: &str, new: &str) -> Option<String> {
if old == "latest" {
return Some("latest".to_string());
}
if let Some(("prefix", old_)) = old.split_once(':') {
return check_semver_bump(old_, new);
}
Expand Down
Loading

0 comments on commit 14e96d2

Please sign in to comment.