Skip to content

Commit

Permalink
fix(exec): do not default to "latest" if a version is already configured
Browse files Browse the repository at this point in the history
Fixes #2033
  • Loading branch information
jdx committed May 13, 2024
1 parent 55b3a4b commit f55e8ef
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/toolset/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,19 +110,18 @@ impl ToolsetBuilder {
if let Some(tvr) = &arg.tvr {
arg_ts.add_version(tvr.clone());
} else if self.default_to_latest {
// TODO: see if there is a cleaner way to handle this scenario
// this logic is required for `mise x` because with that specific command mise
// should default to installing the "latest" version if no version is specified
// in .mise.toml
let versions_by_plugin = ts.list_versions_by_plugin();
let set_as_latest = versions_by_plugin.iter().find(|(_ta, fa)| {
!fa.iter().any(|f|
// Same forget type and same forgeArg name
f.forge.forge_type == arg.forge.forge_type &&
f.forge.name == arg.forge.name)
});

if let Some((_ta, _fa)) = set_as_latest {

// determine if we already have some active version in config
let set_as_latest = !ts
.list_current_requests()
.iter()
.any(|tvr| tvr.forge() == &arg.forge);

if set_as_latest {
// no active version, so use "latest"
arg_ts.add_version(ToolVersionRequest::new(arg.forge.clone(), "latest"));
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/toolset/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,12 @@ impl Toolset {
.map(|(p, _)| p)
.collect()
}
pub fn list_current_requests(&self) -> Vec<&ToolVersionRequest> {
self.versions
.values()
.flat_map(|tvl| &tvl.requests)
.collect()
}
pub fn list_versions_by_plugin(&self) -> Vec<(Arc<dyn Forge>, &Vec<ToolVersion>)> {
self.versions
.iter()
Expand Down

0 comments on commit f55e8ef

Please sign in to comment.