Skip to content

Commit

Permalink
fix(go): go backend supports versions prefixed with 'v'
Browse files Browse the repository at this point in the history
  • Loading branch information
roele committed Mar 6, 2024
1 parent 0d95fde commit febe769
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
17 changes: 15 additions & 2 deletions src/forge/go.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,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::<GoModInfo>(&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);
}
};
Expand All @@ -50,9 +56,16 @@ impl Forge for GoForge {
let settings = Settings::get();
settings.ensure_experimental("go backend")?;

// if the version has no v prefix, add it
let version = if ctx.tv.version.starts_with('v') {
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"))
Expand Down
6 changes: 5 additions & 1 deletion src/toolset/tool_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -31,9 +32,12 @@ impl ToolVersion {
opts: ToolVersionOptions,
version: String,
) -> Self {
let v_prefix = regex!(r"^v(\d+(\.\d+)*)$");
ToolVersion {
forge: tool.fa().clone(),
version,
version: v_prefix
.replace(&version, |caps: &Captures| format!("{}", &caps[1]))
.to_string(),
request,
opts,
}
Expand Down

0 comments on commit febe769

Please sign in to comment.