Skip to content

Commit

Permalink
feat(vfox): added aliases like vfox:cmake -> vfox:version-fox/vfox-cmake
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed Aug 28, 2024
1 parent 914d0b4 commit 0654f6c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
5 changes: 5 additions & 0 deletions e2e/backend/test_vfox_cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

assert "mise x vfox:cmake@3.30.2 -- cmake --version" "cmake version 3.30.2
CMake suite maintained and supported by Kitware (kitware.com/cmake)."
17 changes: 11 additions & 6 deletions src/backend/vfox.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::env;
use eyre::{eyre, Report};
use heck::ToKebabCase;
use rayon::prelude::*;
use std::collections::BTreeMap;
use std::env;
use std::fmt::Debug;
use std::path::PathBuf;
use std::sync::{Arc, Mutex, MutexGuard, OnceLock};
Expand All @@ -16,7 +16,7 @@ use crate::config::{Config, Settings};
use crate::git::Git;
use crate::install_context::InstallContext;
use crate::toolset::{ToolVersion, Toolset};
use crate::{dirs, file};
use crate::{dirs, file, registry};
use vfox::Vfox;

#[derive(Debug)]
Expand Down Expand Up @@ -87,15 +87,19 @@ impl Backend for VfoxBackend {
}
}

fn vfox_to_url(version: &str) -> eyre::Result<Url> {
let res = if let Some(caps) = regex!(r#"^([^/]+)/([^/]+)$"#).captures(version) {
fn vfox_to_url(name: &str) -> eyre::Result<Url> {
if let Some(full) = registry::REGISTRY_VFOX.get(name) {
// bun -> version-fox/vfox-bun
return vfox_to_url(full.split_once(':').unwrap().1);
}
let res = if let Some(caps) = regex!(r#"^([^/]+)/([^/]+)$"#).captures(name) {
let user = caps.get(1).unwrap().as_str();
let repo = caps.get(2).unwrap().as_str();
format!("https://github.com/{user}/{repo}").parse()
} else {
version.to_string().parse()
name.to_string().parse()
};
res.map_err(|e| eyre!("Invalid version: {}: {}", version, e))
res.map_err(|e| eyre!("Invalid version: {}: {}", name, e))
}

impl VfoxBackend {
Expand All @@ -120,6 +124,7 @@ impl VfoxBackend {
remote_version_cache: CacheManager::new(
ba.cache_path.join("remote_versions-$KEY.msgpack.z"),
)
.with_fresh_duration(*env::MISE_FETCH_REMOTE_VERSIONS_CACHE)
.with_fresh_file(dirs::DATA.to_path_buf())
.with_fresh_file(plugin_path.to_path_buf())
.with_fresh_file(ba.installs_path.to_path_buf()),
Expand Down
3 changes: 3 additions & 0 deletions src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,6 @@ pub static REGISTRY: Lazy<BTreeMap<&str, String>> = Lazy::new(|| {
.map(|(k, v)| (*k, v.to_string()))
.collect()
});

pub static REGISTRY_VFOX: Lazy<BTreeMap<&str, &str>> =
Lazy::new(|| _REGISTRY_VFOX.iter().map(|(k, v)| (*k, *v)).collect());

0 comments on commit 0654f6c

Please sign in to comment.