Skip to content

Commit

Permalink
fix: reuse tool options on mise use from config file (#3076)
Browse files Browse the repository at this point in the history
* fix: reuse tool options on `mise use` from config file

* [autofix.ci] apply automated fixes

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
  • Loading branch information
jdx and autofix-ci[bot] authored Nov 18, 2024
1 parent 56f9718 commit 9fe811e
Show file tree
Hide file tree
Showing 25 changed files with 166 additions and 103 deletions.
1 change: 1 addition & 0 deletions .github/workflows/autofix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ env:
MISE_EXPERIMENTAL: 1
RUST_BACKTRACE: 1
NPM_CONFIG_FUND: false
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
autofix:
Expand Down
6 changes: 3 additions & 3 deletions docs/registry.md
Original file line number Diff line number Diff line change
Expand Up @@ -608,10 +608,10 @@ editLink: false
| restic | [asdf:xataz/asdf-restic](https://github.com/xataz/asdf-restic) |
| restish | [ubi:danielgtaylor/restish](https://github.com/danielgtaylor/restish) [go:github.com/danielgtaylor/restish](https://pkg.go.dev/github.com/danielgtaylor/restish) |
| revive | [aqua:mgechev/revive](https://github.com/mgechev/revive) [asdf:bjw-s/asdf-revive](https://github.com/bjw-s/asdf-revive) |
| rg | [ubi:BurntSushi/ripgrep](https://github.com/BurntSushi/ripgrep) [aqua:BurntSushi/ripgrep](https://github.com/BurntSushi/ripgrep) [asdf:https://gitlab.com/wt0f/asdf-ripgrep](https://gitlab.com/wt0f/asdf-ripgrep) |
| rg | [aqua:BurntSushi/ripgrep](https://github.com/BurntSushi/ripgrep) [ubi:BurntSushi/ripgrep](https://github.com/BurntSushi/ripgrep) [asdf:https://gitlab.com/wt0f/asdf-ripgrep](https://gitlab.com/wt0f/asdf-ripgrep) |
| richgo | [aqua:kyoh86/richgo](https://github.com/kyoh86/richgo) [asdf:paxosglobal/asdf-richgo](https://github.com/paxosglobal/asdf-richgo) |
| riff | [asdf:abinet/asdf-riff](https://github.com/abinet/asdf-riff) |
| ripgrep | [ubi:BurntSushi/ripgrep](https://github.com/BurntSushi/ripgrep) [aqua:BurntSushi/ripgrep](https://github.com/BurntSushi/ripgrep) [asdf:https://gitlab.com/wt0f/asdf-ripgrep](https://gitlab.com/wt0f/asdf-ripgrep) |
| ripgrep | [aqua:BurntSushi/ripgrep](https://github.com/BurntSushi/ripgrep) [ubi:BurntSushi/ripgrep](https://github.com/BurntSushi/ripgrep) [asdf:https://gitlab.com/wt0f/asdf-ripgrep](https://gitlab.com/wt0f/asdf-ripgrep) |
| rke | [aqua:rancher/rke](https://github.com/rancher/rke) [asdf:particledecay/asdf-rke](https://github.com/particledecay/asdf-rke) |
| rlwrap | [asdf:asdf-community/asdf-rlwrap](https://github.com/asdf-community/asdf-rlwrap) |
| rome | [asdf:kichiemon/asdf-rome](https://github.com/kichiemon/asdf-rome) |
Expand Down Expand Up @@ -682,7 +682,7 @@ editLink: false
| step | [asdf:log2/asdf-step](https://github.com/log2/asdf-step) |
| stern | [aqua:stern/stern](https://github.com/stern/stern) [asdf:looztra/asdf-stern](https://github.com/looztra/asdf-stern) |
| stripe-cli | [aqua:stripe/stripe-cli](https://github.com/stripe/stripe-cli) [asdf:offbyone/asdf-stripe](https://github.com/offbyone/asdf-stripe) |
| stylua | [asdf:jc00ke/asdf-stylua](https://github.com/jc00ke/asdf-stylua) |
| stylua | [aqua:JohnnyMorganz/StyLua](https://github.com/JohnnyMorganz/StyLua) [asdf:jc00ke/asdf-stylua](https://github.com/jc00ke/asdf-stylua) |
| sui | [asdf:placeholder-soft/asdf-sui](https://github.com/placeholder-soft/asdf-sui) |
| sver | [aqua:mitoma/sver](https://github.com/mitoma/sver) [asdf:robzr/asdf-sver](https://github.com/robzr/asdf-sver) |
| svu | [aqua:caarlos0/svu](https://github.com/caarlos0/svu) [asdf:asdf-community/asdf-svu](https://github.com/asdf-community/asdf-svu) |
Expand Down
9 changes: 9 additions & 0 deletions e2e/backend/test_ubi
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,12 @@ assert "mise x ubi:goreleaser/[email protected] -- goreleaser -v | grep -o 1.25

mise use ubi:kellyjonbrazil/[email protected]
assert_contains "$MISE_DATA_DIR/shims/jc --version" "jc version: 1.25.3"

cat <<EOF >mise.toml
[tools]
"ubi:cilium/cilium-cli" = { version = "latest", exe = "cilium" }
EOF
# re-uses tool options
mise use ubi:cilium/cilium-cli
assert "cat mise.toml" '[tools]
"ubi:cilium/cilium-cli" = { version = "latest", exe = "cilium" }'
File renamed without changes.
5 changes: 3 additions & 2 deletions registry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ revive.backends = ["aqua:mgechev/revive", "asdf:bjw-s/asdf-revive"]
richgo.backends = ["aqua:kyoh86/richgo", "asdf:paxosglobal/asdf-richgo"]
riff.backends = ["asdf:abinet/asdf-riff"]
ripgrep.aliases = ["rg"]
ripgrep.backends = ["ubi:BurntSushi/ripgrep[exe=rg]", "aqua:BurntSushi/ripgrep", "asdf:https://gitlab.com/wt0f/asdf-ripgrep"]
ripgrep.backends = ["aqua:BurntSushi/ripgrep", "ubi:BurntSushi/ripgrep[exe=rg]", "asdf:https://gitlab.com/wt0f/asdf-ripgrep"]
ripgrep.test = ["rg --version", "ripgrep {{version}}"]
rke.backends = ["aqua:rancher/rke", "asdf:particledecay/asdf-rke"]
rlwrap.backends = ["asdf:asdf-community/asdf-rlwrap"]
Expand Down Expand Up @@ -699,7 +699,8 @@ steampipe.backends = ["aqua:turbot/steampipe", "asdf:carnei-ro/asdf-steampipe"]
step.backends = ["asdf:log2/asdf-step"]
stern.backends = ["aqua:stern/stern", "asdf:looztra/asdf-stern"]
stripe-cli.backends = ["aqua:stripe/stripe-cli", "asdf:offbyone/asdf-stripe"]
stylua.backends = ["asdf:jc00ke/asdf-stylua"]
stylua.backends = ["aqua:JohnnyMorganz/StyLua", "asdf:jc00ke/asdf-stylua"]
stylua.test = ["stylua --version", "stylua {{version}}"]
sui.backends = ["asdf:placeholder-soft/asdf-sui"]
sver.backends = ["aqua:mitoma/sver", "asdf:robzr/asdf-sver"]
svu.backends = ["aqua:caarlos0/svu", "asdf:asdf-community/asdf-svu"]
Expand Down
8 changes: 4 additions & 4 deletions src/backend/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl Backend for CargoBackend {
}
self.remote_version_cache
.get_or_try_init(|| {
let raw = HTTP_FETCH.get_text(get_crate_url(self.name())?)?;
let raw = HTTP_FETCH.get_text(get_crate_url(&self.tool_name())?)?;
let stream = Deserializer::from_str(&raw).into_iter::<CrateVersion>();
let mut versions = vec![];
for v in stream {
Expand All @@ -63,7 +63,7 @@ impl Backend for CargoBackend {

fn install_version_impl(&self, ctx: &InstallContext) -> eyre::Result<()> {
let config = Config::try_get()?;
let install_arg = format!("{}@{}", self.name(), ctx.tv.version);
let install_arg = format!("{}@{}", self.tool_name(), ctx.tv.version);

let cmd = CmdLineRunner::new("cargo").arg("install");
let mut cmd = if let Some(url) = self.git_url() {
Expand Down Expand Up @@ -150,9 +150,9 @@ impl CargoBackend {

/// if the name is a git repo, return the git url
fn git_url(&self) -> Option<Url> {
if let Ok(url) = Url::parse(self.name()) {
if let Ok(url) = Url::parse(&self.tool_name()) {
Some(url)
} else if let Some((user, repo)) = self.name().split_once('/') {
} else if let Some((user, repo)) = self.tool_name().split_once('/') {
format!("https://github.com/{user}/{repo}.git").parse().ok()
} else {
None
Expand Down
13 changes: 5 additions & 8 deletions src/backend/go.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ impl Backend for GoBackend {
fn _list_remote_versions(&self) -> eyre::Result<Vec<String>> {
self.remote_version_cache
.get_or_try_init(|| {
let mut mod_path = Some(self.name());
let mut mod_path = Some(self.tool_name());

while let Some(cur_mod_path) = mod_path {
let res = cmd!("go", "list", "-m", "-versions", "-json", cur_mod_path)
let res = cmd!("go", "list", "-m", "-versions", "-json", &cur_mod_path)
.full_env(self.dependency_env()?)
.read();
if let Ok(raw) = res {
Expand Down Expand Up @@ -72,7 +72,7 @@ impl Backend for GoBackend {
let install = |v| {
CmdLineRunner::new("go")
.arg("install")
.arg(format!("{}@{v}", self.name()))
.arg(format!("{}@{v}", self.tool_name()))
.with_pr(ctx.pr.as_ref())
.envs(self.dependency_env()?)
.env("GOBIN", ctx.tv.install_path().join("bin"))
Expand Down Expand Up @@ -101,11 +101,8 @@ impl GoBackend {
}
}

fn trim_after_last_slash(s: &str) -> Option<&str> {
match s.rsplit_once('/') {
Some((new_path, _)) => Some(new_path),
None => None,
}
fn trim_after_last_slash(s: String) -> Option<String> {
s.rsplit_once('/').map(|(new_path, _)| new_path.to_string())
}

#[derive(Debug, serde::Deserialize)]
Expand Down
9 changes: 6 additions & 3 deletions src/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ pub trait Backend: Debug + Send + Sync {
fn id(&self) -> &str {
&self.ba().short
}
fn name(&self) -> &str {
&self.ba().tool_name
fn tool_name(&self) -> String {
self.ba().tool_name()
}
fn get_type(&self) -> BackendType {
BackendType::Core
Expand All @@ -159,6 +159,7 @@ pub trait Backend: Debug + Send + Sync {
let tvr = ToolRequest::System {
backend: ba.clone(),
source: ToolSource::Unknown,
options: Default::default(),
os: None,
};
if let Ok(backend) = ba.backend() {
Expand Down Expand Up @@ -310,6 +311,7 @@ pub trait Backend: Debug + Send + Sync {
.get_all_dependencies(&ToolRequest::System {
backend: self.id().into(),
source: ToolSource::Unknown,
options: Default::default(),
os: None,
})?
.into_iter()
Expand Down Expand Up @@ -515,8 +517,9 @@ pub trait Backend: Debug + Send + Sync {
let config = Config::get();
let dependencies = self
.get_all_dependencies(&ToolRequest::System {
backend: self.name().into(),
backend: self.tool_name().into(),
source: ToolSource::Unknown,
options: Default::default(),
os: None,
})?
.into_iter()
Expand Down
8 changes: 4 additions & 4 deletions src/backend/npm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl Backend for NPMBackend {
fn _list_remote_versions(&self) -> eyre::Result<Vec<String>> {
self.remote_version_cache
.get_or_try_init(|| {
let raw = cmd!(NPM_PROGRAM, "view", self.name(), "versions", "--json")
let raw = cmd!(NPM_PROGRAM, "view", self.tool_name(), "versions", "--json")
.full_env(self.dependency_env()?)
.read()?;
let versions: Vec<String> = serde_json::from_str(&raw)?;
Expand All @@ -47,7 +47,7 @@ impl Backend for NPMBackend {
fn latest_stable_version(&self) -> eyre::Result<Option<String>> {
self.latest_version_cache
.get_or_try_init(|| {
let raw = cmd!(NPM_PROGRAM, "view", self.name(), "dist-tags", "--json")
let raw = cmd!(NPM_PROGRAM, "view", self.tool_name(), "dist-tags", "--json")
.full_env(self.dependency_env()?)
.read()?;
let dist_tags: Value = serde_json::from_str(&raw)?;
Expand All @@ -66,7 +66,7 @@ impl Backend for NPMBackend {
if SETTINGS.npm.bun {
CmdLineRunner::new("bun")
.arg("install")
.arg(format!("{}@{}", self.name(), ctx.tv.version))
.arg(format!("{}@{}", self.tool_name(), ctx.tv.version))
.arg("--cwd")
.arg(ctx.tv.install_path())
.arg("--global")
Expand All @@ -82,7 +82,7 @@ impl Backend for NPMBackend {
CmdLineRunner::new(NPM_PROGRAM)
.arg("install")
.arg("-g")
.arg(format!("{}@{}", self.name(), ctx.tv.version))
.arg(format!("{}@{}", self.tool_name(), ctx.tv.version))
.arg("--prefix")
.arg(ctx.tv.install_path())
.with_pr(ctx.pr.as_ref())
Expand Down
6 changes: 3 additions & 3 deletions src/backend/pipx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl Backend for PIPXBackend {
*/
fn _list_remote_versions(&self) -> eyre::Result<Vec<String>> {
self.remote_version_cache
.get_or_try_init(|| match self.name().parse()? {
.get_or_try_init(|| match self.tool_name().parse()? {
PipxRequest::Pypi(package) => {
let url = format!("https://pypi.org/pypi/{}/json", package);
let data: PypiPackage = HTTP_FETCH.json(url)?;
Expand All @@ -65,7 +65,7 @@ impl Backend for PIPXBackend {

fn latest_stable_version(&self) -> eyre::Result<Option<String>> {
self.latest_version_cache
.get_or_try_init(|| match self.name().parse()? {
.get_or_try_init(|| match self.tool_name().parse()? {
PipxRequest::Pypi(package) => {
let url = format!("https://pypi.org/pypi/{}/json", package);
let pkg: PypiPackage = HTTP_FETCH.json(url)?;
Expand All @@ -80,7 +80,7 @@ impl Backend for PIPXBackend {
let config = Config::try_get()?;
SETTINGS.ensure_experimental("pipx backend")?;
let pipx_request = self
.name()
.tool_name()
.parse::<PipxRequest>()?
.pipx_request(&ctx.tv.version, &ctx.tv.request.options());

Expand Down
4 changes: 2 additions & 2 deletions src/backend/spm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl Backend for SPMBackend {
}

fn _list_remote_versions(&self) -> eyre::Result<Vec<String>> {
let repo = SwiftPackageRepo::new(self.name())?;
let repo = SwiftPackageRepo::new(&self.tool_name())?;
self.remote_version_cache
.get_or_try_init(|| {
Ok(github::list_releases(repo.shorthand.as_str())?
Expand All @@ -56,7 +56,7 @@ impl Backend for SPMBackend {
let settings = Settings::get();
settings.ensure_experimental("spm backend")?;

let repo = SwiftPackageRepo::new(self.name())?;
let repo = SwiftPackageRepo::new(&self.tool_name())?;
let revision = if ctx.tv.version == "latest" {
self.latest_stable_version()?
.ok_or_else(|| eyre::eyre!("No stable versions found"))?
Expand Down
19 changes: 7 additions & 12 deletions src/backend/ubi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::env::GITHUB_TOKEN;
use crate::github;
use crate::install_context::InstallContext;
use crate::plugins::VERSION_REGEX;
use crate::tokio::RUNTIME;
use eyre::bail;
use regex::Regex;
use std::fmt::Debug;
Expand All @@ -31,14 +32,14 @@ impl Backend for UbiBackend {
}

fn _list_remote_versions(&self) -> eyre::Result<Vec<String>> {
if name_is_url(self.name()) {
if name_is_url(&self.tool_name()) {
Ok(vec!["latest".to_string()])
} else {
self.remote_version_cache
.get_or_try_init(|| {
let opts = self.ba.opts.clone().unwrap_or_default();
let tag_regex = OnceLock::new();
Ok(github::list_releases(self.name())?
Ok(github::list_releases(&self.tool_name())?
.into_iter()
.map(|r| r.tag_name)
// trim 'v' prefixes if they exist
Expand All @@ -64,7 +65,7 @@ impl Backend for UbiBackend {
fn install_version_impl(&self, ctx: &InstallContext) -> eyre::Result<()> {
let mut v = ctx.tv.version.to_string();

if let Err(err) = github::get_release(self.name(), &ctx.tv.version) {
if let Err(err) = github::get_release(&self.tool_name(), &ctx.tv.version) {
// this can fail with a rate limit error or 404, either way, try prefixing and if it fails, try without the prefix
// if http::error_code(&err) == Some(404) {
debug!(
Expand All @@ -79,10 +80,9 @@ impl Backend for UbiBackend {
let opts = ctx.tv.request.options();
// Workaround because of not knowing how to pull out the value correctly without quoting
let path_with_bin = ctx.tv.install_path().join("bin");
let name = self.tool_name();

let mut builder = UbiBuilder::new()
.project(self.name())
.install_dir(path_with_bin);
let mut builder = UbiBuilder::new().project(&name).install_dir(path_with_bin);

if let Some(token) = &*GITHUB_TOKEN {
builder = builder.github_token(token);
Expand All @@ -101,12 +101,7 @@ impl Backend for UbiBackend {

let mut ubi = builder.build()?;

let rt = tokio::runtime::Builder::new_current_thread()
.enable_io()
.enable_time()
.build()?;

rt.block_on(ubi.install_binary())
RUNTIME.block_on(ubi.install_binary())
};

if let Err(err) = install(&v) {
Expand Down
16 changes: 4 additions & 12 deletions src/backend/vfox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use crate::dirs;
use crate::install_context::InstallContext;
use crate::plugins::vfox_plugin::VfoxPlugin;
use crate::plugins::{Plugin, PluginType};
use crate::tokio::RUNTIME;
use crate::toolset::{ToolRequest, ToolVersion, Toolset};
use crate::ui::multi_progress_report::MultiProgressReport;

Expand Down Expand Up @@ -45,10 +46,7 @@ impl Backend for VfoxBackend {
.get_or_try_init(|| {
let (vfox, _log_rx) = self.plugin.vfox();
self.ensure_plugin_installed()?;
let versions = self
.plugin
.runtime()?
.block_on(vfox.list_available_versions(&self.pathname))?;
let versions = RUNTIME.block_on(vfox.list_available_versions(&self.pathname))?;
Ok(versions
.into_iter()
.rev()
Expand All @@ -67,11 +65,7 @@ impl Backend for VfoxBackend {
info!("{}", line);
}
});
self.plugin.runtime()?.block_on(vfox.install(
&self.pathname,
&ctx.tv.version,
ctx.tv.install_path(),
))?;
RUNTIME.block_on(vfox.install(&self.pathname, &ctx.tv.version, ctx.tv.install_path()))?;
Ok(())
}

Expand Down Expand Up @@ -149,9 +143,7 @@ impl VfoxBackend {
.get_or_try_init(|| {
self.ensure_plugin_installed()?;
let (vfox, _log_rx) = self.plugin.vfox();
Ok(self
.plugin
.runtime()?
Ok(RUNTIME
.block_on(vfox.env_keys(&self.pathname, &tv.version))?
.into_iter()
.fold(BTreeMap::new(), |mut acc, env_key| {
Expand Down
7 changes: 7 additions & 0 deletions src/cli/args/backend_arg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,13 @@ impl BackendArg {
unalias_backend(&self.short).to_string()
}

pub fn tool_name(&self) -> String {
let full = self.full();
let (_backend, tool_name) = full.split_once(':').unwrap_or(("", &full));
let tool_name = regex!(r#"\[.+\]$"#).replace_all(tool_name, "").to_string();
tool_name.to_string()
}

/// maps something like cargo:cargo-binstall to cargo-binstall and ubi:cargo-binstall, etc
pub fn all_fulls(&self) -> HashSet<String> {
let full = self.full();
Expand Down
2 changes: 1 addition & 1 deletion src/cli/test_tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl TestTool {
}
let (cmd, expected) = if let Some(test) = &rt.test {
(test.0.to_string(), test.1)
} else if self.include_non_defined {
} else if self.include_non_defined || self.tool.is_some() {
(format!("{} --version", tool.short), "__TODO__")
} else {
continue;
Expand Down
Loading

0 comments on commit 9fe811e

Please sign in to comment.