diff --git a/src/forge/go.rs b/src/forge/go.rs index f40519612a..657332d998 100644 --- a/src/forge/go.rs +++ b/src/forge/go.rs @@ -7,6 +7,7 @@ use crate::config::{Config, Settings}; use crate::forge::{Forge, ForgeType}; use crate::install_context::InstallContext; +use crate::plugins::VERSION_V_PREFIX_REGEX; #[derive(Debug)] pub struct GoForge { @@ -32,7 +33,13 @@ impl Forge for GoForge { let res = cmd!("go", "list", "-m", "-versions", "-json", cur_mod_path).read(); if let Ok(raw) = res { let res = serde_json::from_str::(&raw); - if let Ok(mod_info) = res { + if let Ok(mut mod_info) = res { + // remove the leading v from the versions + mod_info.versions = mod_info + .versions + .into_iter() + .map(|v| v.trim_start_matches('v').to_string()) + .collect(); return Ok(mod_info.versions); } }; @@ -50,9 +57,15 @@ impl Forge for GoForge { let settings = Settings::get(); settings.ensure_experimental("go backend")?; + let version = if VERSION_V_PREFIX_REGEX.is_match(ctx.tv.version.as_str()) { + ctx.tv.version.clone() + } else { + format!("v{}", ctx.tv.version) + }; + CmdLineRunner::new("go") .arg("install") - .arg(&format!("{}@{}", self.name(), ctx.tv.version)) + .arg(&format!("{}@{}", self.name(), version)) .with_pr(ctx.pr.as_ref()) .envs(config.env()?) .env("GOBIN", ctx.tv.install_path().join("bin")) diff --git a/src/plugins/mod.rs b/src/plugins/mod.rs index 7e5e6f30c2..1ada975d27 100644 --- a/src/plugins/mod.rs +++ b/src/plugins/mod.rs @@ -30,6 +30,9 @@ pub static VERSION_REGEX: Lazy = Lazy::new(|| { .unwrap() }); +pub static VERSION_V_PREFIX_REGEX: Lazy = + Lazy::new(|| Regex::new(r"^v(\d+(\.\d+)*([+-.].+)?)$").unwrap()); + pub fn get(name: &str) -> Arc { let fa = ForgeArg::new(ForgeType::Asdf, name); forge::get(&fa) diff --git a/src/toolset/tool_version.rs b/src/toolset/tool_version.rs index b2c63ddca9..6d50b48254 100644 --- a/src/toolset/tool_version.rs +++ b/src/toolset/tool_version.rs @@ -6,6 +6,7 @@ use std::path::PathBuf; use console::style; use eyre::Result; +use regex::Captures; use versions::{Chunk, Version}; use crate::cli::args::ForgeArg; @@ -13,6 +14,7 @@ use crate::config::Config; use crate::forge; use crate::forge::{AForge, Forge}; use crate::hash::hash_to_str; +use crate::plugins::VERSION_V_PREFIX_REGEX; use crate::toolset::{ToolVersionOptions, ToolVersionRequest}; /// represents a single version of a tool for a particular plugin @@ -33,7 +35,9 @@ impl ToolVersion { ) -> Self { ToolVersion { forge: tool.fa().clone(), - version, + version: VERSION_V_PREFIX_REGEX + .replace(&version, |caps: &Captures| format!("{}", &caps[1])) + .to_string(), request, opts, }