From 8f876cc80a82953a9732c135db926853493f2a71 Mon Sep 17 00:00:00 2001 From: Jeff Dickey <216188+jdx@users.noreply.github.com> Date: Thu, 30 May 2024 21:26:10 -0500 Subject: [PATCH] refactor: forge -> backend --- e2e/{forge => backend}/test_cargo_binstall | 0 .../test_cargo_binstall_token | 0 .../test_cargo_compile_slow | 0 e2e/{forge => backend}/test_go_install_slow | 0 e2e/{forge => backend}/test_npm | 0 .../test_pipx_deep_dependencies | 0 .../test_pipx_direct_dependencies | 0 e2e/{forge => backend}/test_pipx_slow | 0 e2e/{forge => backend}/test_ubi | 0 e2e/{forge => backend}/test_ubi_token | 0 src/{forge => backend}/asdf.rs | 20 +-- .../forge_meta.rs => backend/backend_meta.rs} | 44 +++--- src/{forge => backend}/cargo.rs | 22 +-- src/{forge => backend}/go.rs | 22 +-- src/{forge => backend}/mod.rs | 142 +++++++++--------- src/{forge => backend}/npm.rs | 22 +-- src/{forge => backend}/pipx.rs | 22 +-- src/{forge => backend}/ubi.rs | 22 +-- src/cli/alias/get.rs | 4 +- src/cli/alias/ls.rs | 4 +- src/cli/alias/mod.rs | 4 +- src/cli/alias/set.rs | 4 +- src/cli/alias/unset.rs | 4 +- src/cli/args/{forge_arg.rs => backend_arg.rs} | 72 ++++----- src/cli/args/mod.rs | 4 +- src/cli/args/tool_arg.rs | 48 +++--- src/cli/asdf.rs | 4 +- src/cli/backends/ls.rs | 10 +- src/cli/current.rs | 16 +- src/cli/doctor.rs | 16 +- src/cli/external.rs | 10 +- src/cli/global.rs | 4 +- src/cli/install.rs | 8 +- src/cli/latest.rs | 4 +- src/cli/link.rs | 2 +- src/cli/local.rs | 10 +- src/cli/ls.rs | 32 ++-- src/cli/ls_remote.rs | 12 +- src/cli/outdated.rs | 8 +- src/cli/plugins/install.rs | 8 +- src/cli/plugins/link.rs | 6 +- src/cli/plugins/uninstall.rs | 4 +- src/cli/prune.rs | 14 +- src/cli/uninstall.rs | 13 +- src/cli/upgrade.rs | 8 +- src/cli/use.rs | 12 +- src/cli/watch.rs | 4 +- src/cli/where.rs | 8 +- src/config/config_file/legacy_version.rs | 10 +- src/config/config_file/mise_toml.rs | 26 ++-- src/config/config_file/mod.rs | 14 +- ...fig_file__mise_toml__tests__fixture-3.snap | 38 ++--- ...fig_file__mise_toml__tests__fixture-4.snap | 2 +- ...fig_file__mise_toml__tests__fixture-5.snap | 2 +- ...ile__mise_toml__tests__remove_alias-4.snap | 2 +- ..._file__mise_toml__tests__remove_alias.snap | 2 +- ...e__mise_toml__tests__replace_versions.snap | 8 +- ...fig_file__mise_toml__tests__set_alias.snap | 4 +- src/config/config_file/tool_versions.rs | 16 +- src/config/env_directive.rs | 2 +- src/config/mod.rs | 26 ++-- .../snapshots/mise__config__tests__load.snap | 2 +- src/main.rs | 2 +- src/plugins/core/bun.rs | 8 +- src/plugins/core/deno.rs | 8 +- src/plugins/core/erlang.rs | 8 +- src/plugins/core/go.rs | 8 +- src/plugins/core/java.rs | 8 +- src/plugins/core/mod.rs | 12 +- src/plugins/core/node.rs | 8 +- src/plugins/core/python.rs | 8 +- src/plugins/core/ruby.rs | 8 +- src/plugins/core/zig.rs | 8 +- src/plugins/mod.rs | 22 +-- src/runtime_symlinks.rs | 30 ++-- src/shims.rs | 16 +- src/test.rs | 6 +- src/toolset/builder.rs | 14 +- src/toolset/mod.rs | 53 ++++--- src/toolset/tool_request_set.rs | 50 +++--- src/toolset/tool_version.rs | 54 ++++--- src/toolset/tool_version_list.rs | 18 +-- src/toolset/tool_version_request.rs | 82 +++++----- src/ui/progress_report.rs | 4 +- tests/cli/{forge.rs => backend.rs} | 0 tests/cli/mod.rs | 4 +- 86 files changed, 646 insertions(+), 620 deletions(-) rename e2e/{forge => backend}/test_cargo_binstall (100%) rename e2e/{forge => backend}/test_cargo_binstall_token (100%) rename e2e/{forge => backend}/test_cargo_compile_slow (100%) rename e2e/{forge => backend}/test_go_install_slow (100%) rename e2e/{forge => backend}/test_npm (100%) rename e2e/{forge => backend}/test_pipx_deep_dependencies (100%) rename e2e/{forge => backend}/test_pipx_direct_dependencies (100%) rename e2e/{forge => backend}/test_pipx_slow (100%) rename e2e/{forge => backend}/test_ubi (100%) rename e2e/{forge => backend}/test_ubi_token (100%) rename src/{forge => backend}/asdf.rs (98%) rename src/{forge/forge_meta.rs => backend/backend_meta.rs} (58%) rename src/{forge => backend}/cargo.rs (89%) rename src/{forge => backend}/go.rs (89%) rename src/{forge => backend}/mod.rs (82%) rename src/{forge => backend}/npm.rs (87%) rename src/{forge => backend}/pipx.rs (93%) rename src/{forge => backend}/ubi.rs (87%) rename src/cli/args/{forge_arg.rs => backend_arg.rs} (60%) rename tests/cli/{forge.rs => backend.rs} (100%) diff --git a/e2e/forge/test_cargo_binstall b/e2e/backend/test_cargo_binstall similarity index 100% rename from e2e/forge/test_cargo_binstall rename to e2e/backend/test_cargo_binstall diff --git a/e2e/forge/test_cargo_binstall_token b/e2e/backend/test_cargo_binstall_token similarity index 100% rename from e2e/forge/test_cargo_binstall_token rename to e2e/backend/test_cargo_binstall_token diff --git a/e2e/forge/test_cargo_compile_slow b/e2e/backend/test_cargo_compile_slow similarity index 100% rename from e2e/forge/test_cargo_compile_slow rename to e2e/backend/test_cargo_compile_slow diff --git a/e2e/forge/test_go_install_slow b/e2e/backend/test_go_install_slow similarity index 100% rename from e2e/forge/test_go_install_slow rename to e2e/backend/test_go_install_slow diff --git a/e2e/forge/test_npm b/e2e/backend/test_npm similarity index 100% rename from e2e/forge/test_npm rename to e2e/backend/test_npm diff --git a/e2e/forge/test_pipx_deep_dependencies b/e2e/backend/test_pipx_deep_dependencies similarity index 100% rename from e2e/forge/test_pipx_deep_dependencies rename to e2e/backend/test_pipx_deep_dependencies diff --git a/e2e/forge/test_pipx_direct_dependencies b/e2e/backend/test_pipx_direct_dependencies similarity index 100% rename from e2e/forge/test_pipx_direct_dependencies rename to e2e/backend/test_pipx_direct_dependencies diff --git a/e2e/forge/test_pipx_slow b/e2e/backend/test_pipx_slow similarity index 100% rename from e2e/forge/test_pipx_slow rename to e2e/backend/test_pipx_slow diff --git a/e2e/forge/test_ubi b/e2e/backend/test_ubi similarity index 100% rename from e2e/forge/test_ubi rename to e2e/backend/test_ubi diff --git a/e2e/forge/test_ubi_token b/e2e/backend/test_ubi_token similarity index 100% rename from e2e/forge/test_ubi_token rename to e2e/backend/test_ubi_token diff --git a/src/forge/asdf.rs b/src/backend/asdf.rs similarity index 98% rename from src/forge/asdf.rs rename to src/backend/asdf.rs index e6a09a24d..bb2c1ce8e 100644 --- a/src/forge/asdf.rs +++ b/src/backend/asdf.rs @@ -14,15 +14,15 @@ use itertools::Itertools; use rayon::prelude::*; use url::Url; +use crate::backend::{ABackend, Backend, BackendList, BackendType}; use crate::cache::CacheManager; -use crate::cli::args::ForgeArg; +use crate::cli::args::BackendArg; use crate::config::{Config, Settings}; use crate::default_shorthands::{DEFAULT_SHORTHANDS, TRUSTED_SHORTHANDS}; use crate::env::MISE_FETCH_REMOTE_VERSIONS_TIMEOUT; use crate::env_diff::{EnvDiff, EnvDiffOperation}; use crate::errors::Error::PluginNotInstalled; use crate::file::{display_path, remove_all}; -use crate::forge::{AForge, Forge, ForgeList, ForgeType}; use crate::git::Git; use crate::hash::hash_to_str; use crate::http::HTTP_FETCH; @@ -40,7 +40,7 @@ use crate::{dirs, env, file, http}; /// This represents a plugin installed to ~/.local/share/mise/plugins pub struct Asdf { - pub fa: ForgeArg, + pub fa: BackendArg, pub name: String, pub plugin_path: PathBuf, pub repo_url: Option, @@ -61,7 +61,7 @@ impl Asdf { toml_path = plugin_path.join("rtx.plugin.toml"); } let toml = MisePluginToml::from_file(&toml_path).unwrap(); - let fa = ForgeArg::new(ForgeType::Asdf, &name); + let fa = BackendArg::new(BackendType::Asdf, &name); Self { script_man: build_script_man(&name, &plugin_path), cache: ExternalPluginCache::default(), @@ -93,10 +93,10 @@ impl Asdf { } } - pub fn list() -> Result { + pub fn list() -> Result { Ok(file::dir_subdirs(&dirs::PLUGINS)? .into_par_iter() - .map(|name| Arc::new(Self::new(name)) as AForge) + .map(|name| Arc::new(Self::new(name)) as ABackend) .collect()) } @@ -451,8 +451,8 @@ impl Hash for Asdf { } } -impl Forge for Asdf { - fn fa(&self) -> &ForgeArg { +impl Backend for Asdf { + fn fa(&self) -> &BackendArg { &self.fa } @@ -460,8 +460,8 @@ impl Forge for Asdf { PluginType::Asdf } - fn get_dependencies(&self, tvr: &ToolRequest) -> Result> { - let out = match tvr.forge().name.as_str() { + fn get_dependencies(&self, tvr: &ToolRequest) -> Result> { + let out = match tvr.backend().name.as_str() { "poetry" | "pipenv" | "pipx" => vec!["python"], "elixir" => vec!["erlang"], _ => vec![], diff --git a/src/forge/forge_meta.rs b/src/backend/backend_meta.rs similarity index 58% rename from src/forge/forge_meta.rs rename to src/backend/backend_meta.rs index f046b06b6..d551cfafd 100644 --- a/src/forge/forge_meta.rs +++ b/src/backend/backend_meta.rs @@ -1,34 +1,34 @@ use serde::{Deserialize, Serialize}; -use crate::cli::args::ForgeArg; +use crate::cli::args::BackendArg; use crate::{dirs, file}; -use super::ForgeType; +use super::BackendType; #[derive(Debug, Default, Serialize, Deserialize)] -pub struct ForgeMeta { +pub struct BackendMeta { pub id: String, pub name: String, - pub forge_type: String, + pub backend_type: String, } -pub const FORGE_META_FILENAME: &str = ".mise.forge.json"; +pub const FORGE_META_FILENAME: &str = ".mise.backend.json"; -impl ForgeMeta { - pub fn read(dirname: &str) -> ForgeMeta { +impl BackendMeta { + pub fn read(dirname: &str) -> BackendMeta { let meta_path = &dirs::INSTALLS.join(dirname).join(FORGE_META_FILENAME); let json = file::read_to_string(meta_path).unwrap_or_default(); serde_json::from_str(&json).unwrap_or(Self::default_meta(dirname)) } - pub fn write(fa: &ForgeArg) -> eyre::Result<()> { - if fa.forge_type == ForgeType::Asdf { + pub fn write(fa: &BackendArg) -> eyre::Result<()> { + if fa.backend_type == BackendType::Asdf { return Ok(()); } - let meta = ForgeMeta { + let meta = BackendMeta { id: fa.id.clone(), name: fa.name.clone(), - forge_type: fa.forge_type.as_ref().to_string(), + backend_type: fa.backend_type.as_ref().to_string(), }; let json = serde_json::to_string(&meta).expect("Could not encode JSON value"); @@ -37,30 +37,30 @@ impl ForgeMeta { Ok(()) } - // Returns a ForgeMeta derived from the dirname for forges without a meta file - fn default_meta(dirname: &str) -> ForgeMeta { + // Returns a BackendMeta derived from the dirname for backends without a meta file + fn default_meta(dirname: &str) -> BackendMeta { let id = dirname.replacen('-', ":", 1); match id.split_once(':') { - Some((forge_type, name)) => { - let name = Self::name_for_type(name.to_string(), forge_type); - let id = format!("{}:{}", forge_type, name); - ForgeMeta { + Some((backend_type, name)) => { + let name = Self::name_for_type(name.to_string(), backend_type); + let id = format!("{}:{}", backend_type, name); + BackendMeta { id, name, - forge_type: forge_type.to_string(), + backend_type: backend_type.to_string(), } } - None => ForgeMeta { + None => BackendMeta { id: id.to_string(), name: id.to_string(), - forge_type: ForgeType::Asdf.as_ref().to_string(), + backend_type: BackendType::Asdf.as_ref().to_string(), }, } } // TODO: remove this when backends come out of experimental - fn name_for_type(name: String, forge_type: &str) -> String { - match forge_type { + fn name_for_type(name: String, backend_type: &str) -> String { + match backend_type { "go" => name.replace('-', "/"), "npm" => { if name.contains('@') { diff --git a/src/forge/cargo.rs b/src/backend/cargo.rs similarity index 89% rename from src/forge/cargo.rs rename to src/backend/cargo.rs index cafc3556f..a07d17fa8 100644 --- a/src/forge/cargo.rs +++ b/src/backend/cargo.rs @@ -3,33 +3,33 @@ use std::fmt::Debug; use serde_json::Deserializer; use url::Url; +use crate::backend::{Backend, BackendType}; use crate::cache::CacheManager; -use crate::cli::args::ForgeArg; +use crate::cli::args::BackendArg; use crate::cmd::CmdLineRunner; use crate::config::{Config, Settings}; use crate::env::GITHUB_TOKEN; use crate::file; -use crate::forge::{Forge, ForgeType}; use crate::http::HTTP_FETCH; use crate::install_context::InstallContext; use crate::toolset::ToolRequest; #[derive(Debug)] -pub struct CargoForge { - fa: ForgeArg, +pub struct CargoBackend { + fa: BackendArg, remote_version_cache: CacheManager>, } -impl Forge for CargoForge { - fn get_type(&self) -> ForgeType { - ForgeType::Cargo +impl Backend for CargoBackend { + fn get_type(&self) -> BackendType { + BackendType::Cargo } - fn fa(&self) -> &ForgeArg { + fn fa(&self) -> &BackendArg { &self.fa } - fn get_dependencies(&self, _tvr: &ToolRequest) -> eyre::Result> { + fn get_dependencies(&self, _tvr: &ToolRequest) -> eyre::Result> { Ok(vec!["cargo".into(), "rust".into()]) } @@ -76,9 +76,9 @@ impl Forge for CargoForge { } } -impl CargoForge { +impl CargoBackend { pub fn new(name: String) -> Self { - let fa = ForgeArg::new(ForgeType::Cargo, &name); + let fa = BackendArg::new(BackendType::Cargo, &name); Self { remote_version_cache: CacheManager::new( fa.cache_path.join("remote_versions-$KEY.msgpack.z"), diff --git a/src/forge/go.rs b/src/backend/go.rs similarity index 89% rename from src/forge/go.rs rename to src/backend/go.rs index 70d9927cb..35e0eb8c8 100644 --- a/src/forge/go.rs +++ b/src/backend/go.rs @@ -1,29 +1,29 @@ use std::fmt::Debug; +use crate::backend::{Backend, BackendType}; use crate::cache::CacheManager; -use crate::cli::args::ForgeArg; +use crate::cli::args::BackendArg; use crate::cmd::CmdLineRunner; use crate::config::Settings; -use crate::forge::{Forge, ForgeType}; use crate::install_context::InstallContext; use crate::toolset::ToolRequest; #[derive(Debug)] -pub struct GoForge { - fa: ForgeArg, +pub struct GoBackend { + fa: BackendArg, remote_version_cache: CacheManager>, } -impl Forge for GoForge { - fn get_type(&self) -> ForgeType { - ForgeType::Go +impl Backend for GoBackend { + fn get_type(&self) -> BackendType { + BackendType::Go } - fn fa(&self) -> &ForgeArg { + fn fa(&self) -> &BackendArg { &self.fa } - fn get_dependencies(&self, _tvr: &ToolRequest) -> eyre::Result> { + fn get_dependencies(&self, _tvr: &ToolRequest) -> eyre::Result> { Ok(vec!["go".into()]) } @@ -82,9 +82,9 @@ impl Forge for GoForge { } } -impl GoForge { +impl GoBackend { pub fn new(name: String) -> Self { - let fa = ForgeArg::new(ForgeType::Go, &name); + let fa = BackendArg::new(BackendType::Go, &name); Self { remote_version_cache: CacheManager::new( fa.cache_path.join("remote_versions-$KEY.msgpack.z"), diff --git a/src/forge/mod.rs b/src/backend/mod.rs similarity index 82% rename from src/forge/mod.rs rename to src/backend/mod.rs index 7c2f28634..9272ae928 100644 --- a/src/forge/mod.rs +++ b/src/backend/mod.rs @@ -15,11 +15,11 @@ use regex::Regex; use strum::IntoEnumIterator; use versions::Versioning; -use crate::cli::args::ForgeArg; +use crate::backend::asdf::Asdf; +use crate::backend::cargo::CargoBackend; +use crate::cli::args::BackendArg; use crate::config::{Config, Settings}; use crate::file::{display_path, remove_all, remove_all_with_warning}; -use crate::forge::asdf::Asdf; -use crate::forge::cargo::CargoForge; use crate::install_context::InstallContext; use crate::lock_file::LockFile; use crate::plugins::core::CORE_PLUGINS; @@ -30,19 +30,19 @@ use crate::ui::multi_progress_report::MultiProgressReport; use crate::ui::progress_report::SingleReport; use crate::{dirs, file}; -use self::forge_meta::ForgeMeta; +use self::backend_meta::BackendMeta; pub mod asdf; +pub mod backend_meta; pub mod cargo; -pub mod forge_meta; pub mod go; pub mod npm; pub mod pipx; pub mod ubi; -pub type AForge = Arc; -pub type ForgeMap = BTreeMap; -pub type ForgeList = Vec; +pub type ABackend = Arc; +pub type BackendMap = BTreeMap; +pub type BackendList = Vec; #[derive( Debug, @@ -58,7 +58,7 @@ pub type ForgeList = Vec; PartialOrd, )] #[strum(serialize_all = "snake_case")] -pub enum ForgeType { +pub enum BackendType { Asdf, Cargo, Core, @@ -68,117 +68,117 @@ pub enum ForgeType { Ubi, } -impl Display for ForgeType { +impl Display for BackendType { fn fmt(&self, formatter: &mut Formatter) -> std::fmt::Result { write!(formatter, "{}", format!("{:?}", self).to_lowercase()) } } -static FORGES: Mutex> = Mutex::new(None); +static FORGES: Mutex> = Mutex::new(None); -fn load_forges() -> ForgeMap { - let mut forges = FORGES.lock().unwrap(); - if let Some(forges) = &*forges { - return forges.clone(); +fn load_backends() -> BackendMap { + let mut backends = FORGES.lock().unwrap(); + if let Some(backends) = &*backends { + return backends.clone(); } let mut plugins = CORE_PLUGINS.clone(); plugins.extend(Asdf::list().expect("failed to list plugins")); - plugins.extend(list_installed_forges().expect("failed to list forges")); + plugins.extend(list_installed_backends().expect("failed to list backends")); let settings = Settings::get(); plugins.retain(|plugin| !settings.disable_tools.contains(plugin.id())); - let plugins: ForgeMap = plugins + let plugins: BackendMap = plugins .into_iter() .map(|plugin| (plugin.fa().clone(), plugin)) .collect(); - *forges = Some(plugins.clone()); + *backends = Some(plugins.clone()); plugins } -fn list_installed_forges() -> eyre::Result { +fn list_installed_backends() -> eyre::Result { Ok(file::dir_subdirs(&dirs::INSTALLS)? .into_par_iter() .map(|dir| { - let id = ForgeMeta::read(&dir).id; - let fa: ForgeArg = id.as_str().into(); - match fa.forge_type { - ForgeType::Asdf => Arc::new(Asdf::new(fa.name)) as AForge, - ForgeType::Cargo => Arc::new(CargoForge::new(fa.name)) as AForge, - ForgeType::Core => Arc::new(Asdf::new(fa.name)) as AForge, - ForgeType::Npm => Arc::new(npm::NPMForge::new(fa.name)) as AForge, - ForgeType::Go => Arc::new(go::GoForge::new(fa.name)) as AForge, - ForgeType::Pipx => Arc::new(pipx::PIPXForge::new(fa.name)) as AForge, - ForgeType::Ubi => Arc::new(ubi::UbiForge::new(fa.name)) as AForge, + let id = BackendMeta::read(&dir).id; + let fa: BackendArg = id.as_str().into(); + match fa.backend_type { + BackendType::Asdf => Arc::new(Asdf::new(fa.name)) as ABackend, + BackendType::Cargo => Arc::new(CargoBackend::new(fa.name)) as ABackend, + BackendType::Core => Arc::new(Asdf::new(fa.name)) as ABackend, + BackendType::Npm => Arc::new(npm::NPMBackend::new(fa.name)) as ABackend, + BackendType::Go => Arc::new(go::GoBackend::new(fa.name)) as ABackend, + BackendType::Pipx => Arc::new(pipx::PIPXBackend::new(fa.name)) as ABackend, + BackendType::Ubi => Arc::new(ubi::UbiBackend::new(fa.name)) as ABackend, } }) - .filter(|f| f.fa().forge_type != ForgeType::Asdf) + .filter(|f| f.fa().backend_type != BackendType::Asdf) .collect()) } -pub fn list() -> ForgeList { - load_forges().values().cloned().collect() +pub fn list() -> BackendList { + load_backends().values().cloned().collect() } -pub fn list_forge_types() -> Vec { - ForgeType::iter().collect() +pub fn list_backend_types() -> Vec { + BackendType::iter().collect() } -pub fn get(fa: &ForgeArg) -> AForge { - if let Some(forge) = load_forges().get(fa) { - forge.clone() +pub fn get(fa: &BackendArg) -> ABackend { + if let Some(backend) = load_backends().get(fa) { + backend.clone() } else { let mut m = FORGES.lock().unwrap(); - let forges = m.as_mut().unwrap(); + let backends = m.as_mut().unwrap(); let name = fa.name.to_string(); - forges + backends .entry(fa.clone()) - .or_insert_with(|| match fa.forge_type { - ForgeType::Asdf => Arc::new(Asdf::new(name)), - ForgeType::Cargo => Arc::new(CargoForge::new(name)), - ForgeType::Core => Arc::new(Asdf::new(name)), - ForgeType::Npm => Arc::new(npm::NPMForge::new(name)), - ForgeType::Go => Arc::new(go::GoForge::new(name)), - ForgeType::Pipx => Arc::new(pipx::PIPXForge::new(name)), - ForgeType::Ubi => Arc::new(ubi::UbiForge::new(name)), + .or_insert_with(|| match fa.backend_type { + BackendType::Asdf => Arc::new(Asdf::new(name)), + BackendType::Cargo => Arc::new(CargoBackend::new(name)), + BackendType::Core => Arc::new(Asdf::new(name)), + BackendType::Npm => Arc::new(npm::NPMBackend::new(name)), + BackendType::Go => Arc::new(go::GoBackend::new(name)), + BackendType::Pipx => Arc::new(pipx::PIPXBackend::new(name)), + BackendType::Ubi => Arc::new(ubi::UbiBackend::new(name)), }) .clone() } } -impl From for AForge { - fn from(fa: ForgeArg) -> Self { +impl From for ABackend { + fn from(fa: BackendArg) -> Self { get(&fa) } } -impl From<&ForgeArg> for AForge { - fn from(fa: &ForgeArg) -> Self { +impl From<&BackendArg> for ABackend { + fn from(fa: &BackendArg) -> Self { get(fa) } } -pub trait Forge: Debug + Send + Sync { +pub trait Backend: Debug + Send + Sync { fn id(&self) -> &str { &self.fa().id } fn name(&self) -> &str { &self.fa().name } - fn get_type(&self) -> ForgeType { - ForgeType::Asdf + fn get_type(&self) -> BackendType { + BackendType::Asdf } - fn fa(&self) -> &ForgeArg; + fn fa(&self) -> &BackendArg; fn get_plugin_type(&self) -> PluginType { PluginType::Core } /// If any of these tools are installing in parallel, we should wait for them to finish /// before installing this tool. - fn get_dependencies(&self, _tvr: &ToolRequest) -> eyre::Result> { + fn get_dependencies(&self, _tvr: &ToolRequest) -> eyre::Result> { Ok(vec![]) } - fn get_all_dependencies(&self, tvr: &ToolRequest) -> eyre::Result> { + fn get_all_dependencies(&self, tvr: &ToolRequest) -> eyre::Result> { let mut deps = self.get_dependencies(tvr)?; - let dep_forges = deps.iter().map(|fa| fa.into()).collect::>(); - for dep in dep_forges { + let dep_backends = deps.iter().map(|fa| fa.into()).collect::>(); + for dep in dep_backends { // TODO: pass the right tvr let tvr = ToolRequest::System(dep.id().into()); deps.extend(dep.get_all_dependencies(&tvr)?); @@ -216,7 +216,7 @@ pub trait Forge: Debug + Send + Sync { } } } - fn is_version_outdated(&self, tv: &ToolVersion, p: &dyn Forge) -> bool { + fn is_version_outdated(&self, tv: &ToolVersion, p: &dyn Backend) -> bool { let latest = match tv.latest_version(p) { Ok(latest) => latest, Err(e) => { @@ -339,7 +339,7 @@ pub trait Forge: Debug + Send + Sync { unimplemented!() } - #[requires(ctx.tv.forge.forge_type == self.get_type())] + #[requires(ctx.tv.backend.backend_type == self.get_type())] fn install_version(&self, ctx: InstallContext) -> eyre::Result<()> { ensure!(self.is_installed(), "{} is not installed", self.id()); let config = Config::get(); @@ -360,7 +360,7 @@ pub trait Forge: Debug + Send + Sync { return Err(e); } - ForgeMeta::write(&ctx.tv.forge)?; + BackendMeta::write(&ctx.tv.backend)?; self.cleanup_install_dirs(&settings, &ctx.tv); // attempt to touch all the .tool-version files to trigger updates in hook-env @@ -535,41 +535,41 @@ fn rmdir(dir: &Path, pr: &dyn SingleReport) -> eyre::Result<()> { }) } -pub fn unalias_forge(forge: &str) -> &str { - match forge { +pub fn unalias_backend(backend: &str) -> &str { + match backend { "nodejs" => "node", "golang" => "go", - _ => forge, + _ => backend, } } -impl Display for dyn Forge { +impl Display for dyn Backend { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.id()) } } -impl Eq for dyn Forge {} +impl Eq for dyn Backend {} -impl PartialEq for dyn Forge { +impl PartialEq for dyn Backend { fn eq(&self, other: &Self) -> bool { self.get_plugin_type() == other.get_plugin_type() && self.id() == other.id() } } -impl Hash for dyn Forge { +impl Hash for dyn Backend { fn hash(&self, state: &mut H) { self.id().hash(state) } } -impl PartialOrd for dyn Forge { +impl PartialOrd for dyn Backend { fn partial_cmp(&self, other: &Self) -> Option { Some(self.cmp(other)) } } -impl Ord for dyn Forge { +impl Ord for dyn Backend { fn cmp(&self, other: &Self) -> std::cmp::Ordering { self.id().cmp(other.id()) } diff --git a/src/forge/npm.rs b/src/backend/npm.rs similarity index 87% rename from src/forge/npm.rs rename to src/backend/npm.rs index aae849c7e..3dacfc999 100644 --- a/src/forge/npm.rs +++ b/src/backend/npm.rs @@ -2,31 +2,31 @@ use std::fmt::Debug; use serde_json::Value; +use crate::backend::{Backend, BackendType}; use crate::cache::CacheManager; -use crate::cli::args::ForgeArg; +use crate::cli::args::BackendArg; use crate::cmd::CmdLineRunner; use crate::config::{Config, Settings}; -use crate::forge::{Forge, ForgeType}; use crate::install_context::InstallContext; use crate::toolset::ToolRequest; #[derive(Debug)] -pub struct NPMForge { - fa: ForgeArg, +pub struct NPMBackend { + fa: BackendArg, remote_version_cache: CacheManager>, latest_version_cache: CacheManager>, } -impl Forge for NPMForge { - fn get_type(&self) -> ForgeType { - ForgeType::Npm +impl Backend for NPMBackend { + fn get_type(&self) -> BackendType { + BackendType::Npm } - fn fa(&self) -> &ForgeArg { + fn fa(&self) -> &BackendArg { &self.fa } - fn get_dependencies(&self, _tvr: &ToolRequest) -> eyre::Result> { + fn get_dependencies(&self, _tvr: &ToolRequest) -> eyre::Result> { Ok(vec!["node".into()]) } @@ -76,9 +76,9 @@ impl Forge for NPMForge { } } -impl NPMForge { +impl NPMBackend { pub fn new(name: String) -> Self { - let fa = ForgeArg::new(ForgeType::Npm, &name); + let fa = BackendArg::new(BackendType::Npm, &name); Self { remote_version_cache: CacheManager::new( fa.cache_path.join("remote_versions-$KEY.msgpack.z"), diff --git a/src/forge/pipx.rs b/src/backend/pipx.rs similarity index 93% rename from src/forge/pipx.rs rename to src/backend/pipx.rs index 964c5b386..024fd783f 100644 --- a/src/forge/pipx.rs +++ b/src/backend/pipx.rs @@ -4,33 +4,33 @@ use std::fmt::Debug; use std::str::FromStr; use versions::Versioning; +use crate::backend::{Backend, BackendType}; use crate::cache::CacheManager; -use crate::cli::args::ForgeArg; +use crate::cli::args::BackendArg; use crate::cmd::CmdLineRunner; use crate::config::{Config, Settings}; -use crate::forge::{Forge, ForgeType}; use crate::github; use crate::http::HTTP_FETCH; use crate::install_context::InstallContext; use crate::toolset::ToolRequest; #[derive(Debug)] -pub struct PIPXForge { - fa: ForgeArg, +pub struct PIPXBackend { + fa: BackendArg, remote_version_cache: CacheManager>, latest_version_cache: CacheManager>, } -impl Forge for PIPXForge { - fn get_type(&self) -> ForgeType { - ForgeType::Pipx +impl Backend for PIPXBackend { + fn get_type(&self) -> BackendType { + BackendType::Pipx } - fn fa(&self) -> &ForgeArg { + fn fa(&self) -> &BackendArg { &self.fa } - fn get_dependencies(&self, _tvr: &ToolRequest) -> eyre::Result> { + fn get_dependencies(&self, _tvr: &ToolRequest) -> eyre::Result> { Ok(vec!["pipx".into()]) } @@ -100,9 +100,9 @@ impl Forge for PIPXForge { } } -impl PIPXForge { +impl PIPXBackend { pub fn new(name: String) -> Self { - let fa = ForgeArg::new(ForgeType::Pipx, &name); + let fa = BackendArg::new(BackendType::Pipx, &name); Self { remote_version_cache: CacheManager::new( fa.cache_path.join("remote_versions-$KEY.msgpack.z"), diff --git a/src/forge/ubi.rs b/src/backend/ubi.rs similarity index 87% rename from src/forge/ubi.rs rename to src/backend/ubi.rs index f44dc658e..7a3430ab1 100644 --- a/src/forge/ubi.rs +++ b/src/backend/ubi.rs @@ -1,33 +1,33 @@ use std::fmt::Debug; +use crate::backend::{Backend, BackendType}; use crate::cache::CacheManager; -use crate::cli::args::ForgeArg; +use crate::cli::args::BackendArg; use crate::cmd::CmdLineRunner; use crate::config::{Config, Settings}; use crate::env::GITHUB_TOKEN; -use crate::forge::{Forge, ForgeType}; use crate::github; use crate::install_context::InstallContext; use crate::toolset::ToolRequest; #[derive(Debug)] -pub struct UbiForge { - fa: ForgeArg, +pub struct UbiBackend { + fa: BackendArg, remote_version_cache: CacheManager>, } // Uses ubi for installations https://github.com/houseabsolute/ubi // it can be installed via mise install cargo:ubi -impl Forge for UbiForge { - fn get_type(&self) -> ForgeType { - ForgeType::Ubi +impl Backend for UbiBackend { + fn get_type(&self) -> BackendType { + BackendType::Ubi } - fn fa(&self) -> &ForgeArg { + fn fa(&self) -> &BackendArg { &self.fa } - fn get_dependencies(&self, _tvr: &ToolRequest) -> eyre::Result> { + fn get_dependencies(&self, _tvr: &ToolRequest) -> eyre::Result> { Ok(vec!["cargo:ubi".into()]) } @@ -77,9 +77,9 @@ impl Forge for UbiForge { } } -impl UbiForge { +impl UbiBackend { pub fn new(name: String) -> Self { - let fa = ForgeArg::new(ForgeType::Ubi, &name); + let fa = BackendArg::new(BackendType::Ubi, &name); Self { remote_version_cache: CacheManager::new( fa.cache_path.join("remote_versions-$KEY.msgpack.z"), diff --git a/src/cli/alias/get.rs b/src/cli/alias/get.rs index 831d574ec..efbebf34a 100644 --- a/src/cli/alias/get.rs +++ b/src/cli/alias/get.rs @@ -1,6 +1,6 @@ use color_eyre::eyre::{eyre, Result}; -use crate::cli::args::ForgeArg; +use crate::cli::args::BackendArg; use crate::config::Config; /// Show an alias for a plugin @@ -11,7 +11,7 @@ use crate::config::Config; #[clap(after_long_help = AFTER_LONG_HELP, verbatim_doc_comment)] pub struct AliasGet { /// The plugin to show the alias for - pub plugin: ForgeArg, + pub plugin: BackendArg, /// The alias to show pub alias: String, } diff --git a/src/cli/alias/ls.rs b/src/cli/alias/ls.rs index cc230c017..b2a30e830 100644 --- a/src/cli/alias/ls.rs +++ b/src/cli/alias/ls.rs @@ -1,7 +1,7 @@ use eyre::Result; use tabled::Tabled; -use crate::cli::args::ForgeArg; +use crate::cli::args::BackendArg; use crate::config::Config; use crate::ui::table; @@ -18,7 +18,7 @@ use crate::ui::table; pub struct AliasLs { /// Show aliases for #[clap()] - pub plugin: Option, + pub plugin: Option, /// Don't show table header #[clap(long)] diff --git a/src/cli/alias/mod.rs b/src/cli/alias/mod.rs index 5b942f185..a68901726 100644 --- a/src/cli/alias/mod.rs +++ b/src/cli/alias/mod.rs @@ -1,7 +1,7 @@ use clap::Subcommand; use eyre::Result; -use crate::cli::args::ForgeArg; +use crate::cli::args::BackendArg; mod get; mod ls; @@ -16,7 +16,7 @@ pub struct Alias { /// filter aliases by plugin #[clap(short, long)] - pub plugin: Option, + pub plugin: Option, /// Don't show table header #[clap(long)] diff --git a/src/cli/alias/set.rs b/src/cli/alias/set.rs index a60a538b4..13b2fe0fe 100644 --- a/src/cli/alias/set.rs +++ b/src/cli/alias/set.rs @@ -1,6 +1,6 @@ use eyre::Result; -use crate::cli::args::ForgeArg; +use crate::cli::args::BackendArg; use crate::config::config_file::ConfigFile; use crate::config::Config; @@ -11,7 +11,7 @@ use crate::config::Config; #[clap(visible_aliases = ["add", "create"], after_long_help = AFTER_LONG_HELP, verbatim_doc_comment)] pub struct AliasSet { /// The plugin to set the alias for - pub plugin: ForgeArg, + pub plugin: BackendArg, /// The alias to set pub alias: String, /// The value to set the alias to diff --git a/src/cli/alias/unset.rs b/src/cli/alias/unset.rs index 3763ccd01..efafe03e2 100644 --- a/src/cli/alias/unset.rs +++ b/src/cli/alias/unset.rs @@ -1,6 +1,6 @@ use eyre::Result; -use crate::cli::args::ForgeArg; +use crate::cli::args::BackendArg; use crate::config::config_file::ConfigFile; use crate::config::Config; @@ -11,7 +11,7 @@ use crate::config::Config; #[clap(visible_aliases = ["rm", "remove", "delete", "del"], after_long_help = AFTER_LONG_HELP, verbatim_doc_comment)] pub struct AliasUnset { /// The plugin to remove the alias from - pub plugin: ForgeArg, + pub plugin: BackendArg, /// The alias to remove pub alias: String, } diff --git a/src/cli/args/forge_arg.rs b/src/cli/args/backend_arg.rs similarity index 60% rename from src/cli/args/forge_arg.rs rename to src/cli/args/backend_arg.rs index e8e276eb7..835a06e7b 100644 --- a/src/cli/args/forge_arg.rs +++ b/src/cli/args/backend_arg.rs @@ -6,20 +6,20 @@ use std::path::PathBuf; use once_cell::sync::Lazy; +use crate::backend::{unalias_backend, BackendType}; use crate::dirs; -use crate::forge::{unalias_forge, ForgeType}; use crate::registry::REGISTRY; #[derive(Clone, PartialOrd, Ord)] -pub struct ForgeArg { +pub struct BackendArg { /// user-specified identifier, "node", "npm:prettier", "cargo:eza", "vfox:version-fox/vfox-nodejs" /// multiple ids may point to a single tool, e.g.: "node", "core:node" or "vfox:version-fox/vfox-nodejs" /// and "vfox:https://github.com/version-fox/vfox-nodejs" pub id: String, - /// the name of the tool within the forge, e.g.: "node", "prettier", "eza", "vfox-nodejs" + /// the name of the tool within the backend, e.g.: "node", "prettier", "eza", "vfox-nodejs" pub name: String, - /// type of forge, "asdf", "cargo", "core", "npm", "vfox" - pub forge_type: ForgeType, + /// type of backend, "asdf", "cargo", "core", "npm", "vfox" + pub backend_type: BackendType, /// ~/.local/share/mise/cache/ pub cache_path: PathBuf, /// ~/.local/share/mise/installs/ @@ -28,32 +28,32 @@ pub struct ForgeArg { pub downloads_path: PathBuf, } -impl> From for ForgeArg { +impl> From for BackendArg { fn from(s: A) -> Self { let s = s.as_ref(); if let Some(fa) = FORGE_MAP.get(s) { return fa.clone(); } - if let Some((forge_type, name)) = s.split_once(':') { - if let Ok(forge_type) = forge_type.parse() { - return Self::new(forge_type, name); + if let Some((backend_type, name)) = s.split_once(':') { + if let Ok(backend_type) = backend_type.parse() { + return Self::new(backend_type, name); } } - Self::new(ForgeType::Asdf, s) + Self::new(BackendType::Asdf, s) } } -impl ForgeArg { - pub fn new(forge_type: ForgeType, name: &str) -> Self { - let name = unalias_forge(name).to_string(); - let id = match forge_type { - ForgeType::Asdf | ForgeType::Core => name.clone(), - forge_type => format!("{forge_type}:{name}"), +impl BackendArg { + pub fn new(backend_type: BackendType, name: &str) -> Self { + let name = unalias_backend(name).to_string(); + let id = match backend_type { + BackendType::Asdf | BackendType::Core => name.clone(), + backend_type => format!("{backend_type}:{name}"), }; let pathname = id.to_kebab_case(); Self { name, - forge_type, + backend_type, id, cache_path: dirs::CACHE.join(&pathname), installs_path: dirs::INSTALLS.join(&pathname), @@ -62,39 +62,39 @@ impl ForgeArg { } } -impl Display for ForgeArg { +impl Display for BackendArg { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.id) } } -impl Debug for ForgeArg { +impl Debug for BackendArg { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, r#"ForgeArg("{}")"#, self.id) + write!(f, r#"BackendArg("{}")"#, self.id) } } -impl PartialEq for ForgeArg { +impl PartialEq for BackendArg { fn eq(&self, other: &Self) -> bool { self.id == other.id } } -impl Eq for ForgeArg {} +impl Eq for BackendArg {} -impl Hash for ForgeArg { +impl Hash for BackendArg { fn hash(&self, state: &mut H) { self.id.hash(state); } } -static FORGE_MAP: Lazy> = Lazy::new(|| { +static FORGE_MAP: Lazy> = Lazy::new(|| { REGISTRY .iter() .map(|(short, full)| { - let (forge_type, name) = full.split_once(':').unwrap(); - let forge_type = forge_type.parse().unwrap(); - let fa = ForgeArg::new(forge_type, name); + let (backend_type, name) = full.split_once(':').unwrap(); + let backend_type = backend_type.parse().unwrap(); + let fa = BackendArg::new(backend_type, name); (*short, fa) }) .collect() @@ -107,17 +107,17 @@ mod tests { use super::*; #[test] - fn test_forge_arg() { + fn test_backend_arg() { let t = |s: &str, id, name, t| { - let fa: ForgeArg = s.into(); + let fa: BackendArg = s.into(); assert_str_eq!(fa.id, id); assert_str_eq!(fa.name, name); - assert_eq!(fa.forge_type, t); + assert_eq!(fa.backend_type, t); }; - let asdf = |s, id, name| t(s, id, name, ForgeType::Asdf); - let cargo = |s, id, name| t(s, id, name, ForgeType::Cargo); - // let core = |s, id, name| t(s, id, name, ForgeType::Core); - let npm = |s, id, name| t(s, id, name, ForgeType::Npm); + let asdf = |s, id, name| t(s, id, name, BackendType::Asdf); + let cargo = |s, id, name| t(s, id, name, BackendType::Cargo); + // let core = |s, id, name| t(s, id, name, BackendType::Core); + let npm = |s, id, name| t(s, id, name, BackendType::Npm); asdf("asdf:poetry", "poetry", "poetry"); asdf("poetry", "poetry", "poetry"); @@ -129,9 +129,9 @@ mod tests { } #[test] - fn test_forge_arg_pathname() { + fn test_backend_arg_pathname() { let t = |s: &str, expected| { - let fa: ForgeArg = s.into(); + let fa: BackendArg = s.into(); let actual = fa.installs_path.to_string_lossy(); let expected = dirs::INSTALLS.join(expected); assert_str_eq!(actual, expected.to_string_lossy()); diff --git a/src/cli/args/mod.rs b/src/cli/args/mod.rs index d3c4a016c..8bbc97857 100644 --- a/src/cli/args/mod.rs +++ b/src/cli/args/mod.rs @@ -1,15 +1,15 @@ +pub use backend_arg::BackendArg; pub use cd_arg::CdArg; pub use env_var_arg::EnvVarArg; -pub use forge_arg::ForgeArg; pub use log_level_arg::{DebugArg, LogLevelArg, TraceArg}; pub use quiet_arg::QuietArg; pub use tool_arg::{ToolArg, ToolVersionType}; pub use verbose_arg::VerboseArg; pub use yes_arg::YesArg; +mod backend_arg; mod cd_arg; mod env_var_arg; -mod forge_arg; mod log_level_arg; mod quiet_arg; mod tool_arg; diff --git a/src/cli/args/tool_arg.rs b/src/cli/args/tool_arg.rs index d92ab2c91..9822dd416 100644 --- a/src/cli/args/tool_arg.rs +++ b/src/cli/args/tool_arg.rs @@ -6,13 +6,13 @@ use console::style; use eyre::bail; use regex::Regex; -use crate::cli::args::ForgeArg; +use crate::cli::args::BackendArg; use crate::toolset::ToolRequest; use crate::ui::style; #[derive(Debug, Clone, Eq, PartialEq)] pub struct ToolArg { - pub forge: ForgeArg, + pub backend: BackendArg, pub version: Option, pub version_type: ToolVersionType, pub tvr: Option, @@ -32,22 +32,22 @@ impl FromStr for ToolArg { type Err = eyre::Error; fn from_str(input: &str) -> eyre::Result { - let (forge_input, version) = parse_input(input); + let (backend_input, version) = parse_input(input); - let forge: ForgeArg = forge_input.into(); + let backend: BackendArg = backend_input.into(); let version_type = match version.as_ref() { Some(version) => version.parse()?, None => ToolVersionType::Version(String::from("latest")), }; let tvr = version .as_ref() - .map(|v| ToolRequest::new(forge.clone(), v)) + .map(|v| ToolRequest::new(backend.clone(), v)) .transpose()?; Ok(Self { tvr, version: version.map(|v| v.to_string()), version_type, - forge, + backend, }) } } @@ -98,11 +98,11 @@ impl ToolArg { let re: &Regex = regex!(r"^\d+(\.\d+)*$"); let a = tools[0].clone(); let b = tools[1].clone(); - if a.tvr.is_none() && b.tvr.is_none() && re.is_match(&b.forge.name) { - tools[1].tvr = Some(ToolRequest::new(a.forge.clone(), &b.forge.name)?); - tools[1].forge = a.forge; - tools[1].version_type = b.forge.name.parse()?; - tools[1].version = Some(b.forge.name); + if a.tvr.is_none() && b.tvr.is_none() && re.is_match(&b.backend.name) { + tools[1].tvr = Some(ToolRequest::new(a.backend.clone(), &b.backend.name)?); + tools[1].backend = a.backend; + tools[1].version_type = b.backend.name.parse()?; + tools[1].version = Some(b.backend.name); tools.remove(0); } } @@ -111,7 +111,7 @@ impl ToolArg { pub fn with_version(self, version: &str) -> Self { Self { - tvr: Some(ToolRequest::new(self.forge.clone(), version).unwrap()), + tvr: Some(ToolRequest::new(self.backend.clone(), version).unwrap()), version: Some(version.into()), version_type: version.parse().unwrap(), ..self @@ -126,7 +126,7 @@ impl ToolArg { .unwrap_or(String::from("latest")); format!( "{}{}", - style(&self.forge.name).blue().for_stderr(), + style(&self.backend.name).blue().for_stderr(), style(&format!("@{version}")).for_stderr() ) } @@ -136,29 +136,29 @@ impl Display for ToolArg { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match &self.tvr { Some(tvr) => write!(f, "{}", tvr), - _ => write!(f, "{}", self.forge.name), + _ => write!(f, "{}", self.backend.name), } } } fn parse_input(s: &str) -> (&str, Option<&str>) { - let (forge, version) = s + let (backend, version) = s .split_once('@') .map(|(f, v)| (f, Some(v))) .unwrap_or((s, None)); // special case for packages with npm scopes like "npm:@antfu/ni" - if forge == "npm:" { + if backend == "npm:" { if let Some(v) = version { return if let Some(i) = v.find('@') { - (&s[..forge.len() + i + 1], Some(&v[i + 1..])) + (&s[..backend.len() + i + 1], Some(&v[i + 1..])) } else { - (&s[..forge.len() + v.len() + 1], None) + (&s[..backend.len() + v.len() + 1], None) }; } } - (forge, version) + (backend, version) } #[cfg(test)] @@ -173,7 +173,7 @@ mod tests { assert_eq!( tool, ToolArg { - forge: "node".into(), + backend: "node".into(), version: None, version_type: ToolVersionType::Version("latest".into()), tvr: None, @@ -187,7 +187,7 @@ mod tests { assert_eq!( tool, ToolArg { - forge: "node".into(), + backend: "node".into(), version: Some("20".into()), version_type: ToolVersionType::Version("20".into()), tvr: Some(ToolRequest::new("node".into(), "20").unwrap()), @@ -201,7 +201,7 @@ mod tests { assert_eq!( tool, ToolArg { - forge: "node".into(), + backend: "node".into(), version: Some("lts".into()), version_type: ToolVersionType::Version("lts".into()), tvr: Some(ToolRequest::new("node".into(), "lts").unwrap()), @@ -212,8 +212,8 @@ mod tests { #[test] fn test_tool_arg_parse_input() { let t = |input, f, v| { - let (forge, version) = parse_input(input); - assert_eq!(forge, f); + let (backend, version) = parse_input(input); + assert_eq!(backend, f); assert_eq!(version, v); }; t("npm:@antfu/ni", "npm:@antfu/ni", None); diff --git a/src/cli/asdf.rs b/src/cli/asdf.rs index f4384ff64..5db824142 100644 --- a/src/cli/asdf.rs +++ b/src/cli/asdf.rs @@ -53,12 +53,12 @@ fn list_versions(config: &Config, args: &[String]) -> Result<()> { _ => None, }; if let Some(plugin) = plugin { - versions.retain(|(_, v)| &v.forge.to_string() == plugin); + versions.retain(|(_, v)| &v.backend.to_string() == plugin); for (_, version) in versions { miseprintln!("{}", version.version); } } else { - for (plugin, versions) in &versions.into_iter().group_by(|(_, v)| v.forge.clone()) { + for (plugin, versions) in &versions.into_iter().group_by(|(_, v)| v.backend.clone()) { miseprintln!("{}", plugin); for (_, tv) in versions { miseprintln!(" {}", tv.version); diff --git a/src/cli/backends/ls.rs b/src/cli/backends/ls.rs index 201a8228a..454003832 100644 --- a/src/cli/backends/ls.rs +++ b/src/cli/backends/ls.rs @@ -1,6 +1,6 @@ use eyre::Result; -use crate::forge::{self, ForgeType}; +use crate::backend::{self, BackendType}; /// List built-in backends #[derive(Debug, clap::Args)] @@ -9,11 +9,11 @@ pub struct BackendsLs {} impl BackendsLs { pub fn run(self) -> Result<()> { - let mut forges = forge::list_forge_types(); - forges.retain(|f| *f != ForgeType::Asdf); + let mut backends = backend::list_backend_types(); + backends.retain(|f| *f != BackendType::Asdf); - for forge in forges { - miseprintln!("{}", forge); + for backend in backends { + miseprintln!("{}", backend); } Ok(()) } diff --git a/src/cli/current.rs b/src/cli/current.rs index 42b1f664c..a557b403f 100644 --- a/src/cli/current.rs +++ b/src/cli/current.rs @@ -1,10 +1,10 @@ use console::style; use eyre::{bail, Result}; -use crate::cli::args::ForgeArg; +use crate::backend; +use crate::backend::Backend; +use crate::cli::args::BackendArg; use crate::config::Config; -use crate::forge; -use crate::forge::Forge; use crate::toolset::{Toolset, ToolsetBuilder}; /// Shows current active and installed runtime versions @@ -17,7 +17,7 @@ pub struct Current { /// Plugin to show versions of /// e.g.: ruby, node, cargo:eza, npm:prettier, etc. #[clap()] - plugin: Option, + plugin: Option, } impl Current { @@ -26,7 +26,7 @@ impl Current { let ts = ToolsetBuilder::new().build(&config)?; match &self.plugin { Some(fa) => { - let plugin = forge::get(fa); + let plugin = backend::get(fa); if !plugin.is_installed() { bail!("Plugin {fa} is not installed"); } @@ -36,7 +36,7 @@ impl Current { } } - fn one(&self, ts: Toolset, tool: &dyn Forge) -> Result<()> { + fn one(&self, ts: Toolset, tool: &dyn Backend) -> Result<()> { if !tool.is_installed() { warn!("Plugin {} is not installed", tool.id()); return Ok(()); @@ -73,10 +73,10 @@ impl Current { } for tv in versions { if !plugin.is_version_installed(tv) { - let source = ts.versions.get(&tv.forge).unwrap().source.clone(); + let source = ts.versions.get(&tv.backend).unwrap().source.clone(); warn!( "{}@{} is specified in {}, but not installed", - &tv.forge, &tv.version, &source + &tv.backend, &tv.version, &source ); } } diff --git a/src/cli/doctor.rs b/src/cli/doctor.rs index a6edbbc3a..9b066c63a 100644 --- a/src/cli/doctor.rs +++ b/src/cli/doctor.rs @@ -7,19 +7,19 @@ use indoc::formatdoc; use itertools::Itertools; use rayon::prelude::*; +use crate::backend::BackendType; use crate::build_time::built_info; use crate::cli::version; use crate::cli::version::VERSION; use crate::config::{Config, Settings}; use crate::file::display_path; -use crate::forge::ForgeType; use crate::git::Git; use crate::plugins::core::CORE_PLUGINS; use crate::plugins::PluginType; use crate::shell::ShellType; use crate::toolset::{Toolset, ToolsetBuilder}; use crate::ui::style; -use crate::{cmd, dirs, duration, env, file, forge, shims}; +use crate::{backend, cmd, dirs, duration, env, file, shims}; /// Check mise installation for possible problems #[derive(Debug, clap::Args)] @@ -103,7 +103,7 @@ impl Doctor { section("backends", render_backends())?; section("plugins", render_plugins())?; - for plugin in forge::list() { + for plugin in backend::list() { if !plugin.is_installed() { self.errors .push(format!("plugin {} is not installed", &plugin.id())); @@ -186,7 +186,7 @@ impl Doctor { } fn analyze_plugins(&mut self) { - for plugin in forge::list() { + for plugin in backend::list() { let is_core = CORE_PLUGINS.iter().any(|fg| fg.id() == plugin.id()); let plugin_type = plugin.get_plugin_type(); @@ -244,9 +244,9 @@ fn render_config_files(config: &Config) -> String { fn render_backends() -> String { let mut s = vec![]; - let backends = forge::list_forge_types() + let backends = backend::list_backend_types() .into_iter() - .filter(|f| *f != ForgeType::Asdf); + .filter(|f| *f != BackendType::Asdf); for b in backends { s.push(format!("{}", b)); } @@ -254,9 +254,9 @@ fn render_backends() -> String { } fn render_plugins() -> String { - let plugins = forge::list() + let plugins = backend::list() .into_iter() - .filter(|p| p.is_installed() && p.get_type() == ForgeType::Asdf) + .filter(|p| p.is_installed() && p.get_type() == BackendType::Asdf) .collect::>(); let max_plugin_name_len = plugins .iter() diff --git a/src/cli/external.rs b/src/cli/external.rs index edf4036de..f78e9ba00 100644 --- a/src/cli/external.rs +++ b/src/cli/external.rs @@ -2,11 +2,11 @@ use clap::{ArgMatches, Command}; use eyre::Result; use rayon::prelude::*; -use crate::cli::args::ForgeArg; -use crate::forge; +use crate::backend; +use crate::cli::args::BackendArg; pub fn commands() -> Vec { - forge::list() + backend::list() .into_par_iter() .flat_map(|p| { p.external_commands().unwrap_or_else(|e| { @@ -18,13 +18,13 @@ pub fn commands() -> Vec { .collect() } -pub fn execute(fa: &ForgeArg, args: &ArgMatches) -> Result<()> { +pub fn execute(fa: &BackendArg, args: &ArgMatches) -> Result<()> { if let Some(mut cmd) = commands() .into_iter() .find(|c| c.get_name() == fa.to_string()) { if let Some((subcommand, matches)) = args.subcommand() { - let plugin = forge::get(fa); + let plugin = backend::get(fa); let args: Vec = matches .get_raw("args") .unwrap_or_default() diff --git a/src/cli/global.rs b/src/cli/global.rs index ba9558244..b749253c3 100644 --- a/src/cli/global.rs +++ b/src/cli/global.rs @@ -1,6 +1,6 @@ use eyre::Result; -use crate::cli::args::{ForgeArg, ToolArg}; +use crate::cli::args::{BackendArg, ToolArg}; use crate::cli::local::local; use crate::config::Settings; @@ -37,7 +37,7 @@ pub struct Global { /// Remove the plugin(s) from ~/.tool-versions #[clap(long, value_name = "PLUGIN", aliases = ["rm", "unset"])] - remove: Option>, + remove: Option>, /// Get the path of the global config file #[clap(long)] diff --git a/src/cli/install.rs b/src/cli/install.rs index 5502f0645..6609f9841 100644 --- a/src/cli/install.rs +++ b/src/cli/install.rs @@ -2,7 +2,7 @@ use eyre::Result; use itertools::Itertools; use std::collections::HashSet; -use crate::cli::args::{ForgeArg, ToolArg}; +use crate::cli::args::{BackendArg, ToolArg}; use crate::config::Config; use crate::toolset::{InstallOptions, ToolRequest, ToolVersion, ToolVersionOptions, Toolset}; use crate::ui::multi_progress_report::MultiProgressReport; @@ -57,7 +57,7 @@ impl Install { } fn install_runtimes(&self, config: &Config, runtimes: &[ToolArg]) -> Result> { let mpr = MultiProgressReport::get(); - let tools: HashSet = runtimes.iter().map(|ta| ta.forge.clone()).collect(); + let tools: HashSet = runtimes.iter().map(|ta| ta.backend.clone()).collect(); let mut ts = config.get_tool_request_set()?.filter_by_tool(&tools).into(); let tool_versions = self.get_requested_tool_versions(&ts, runtimes)?; if tool_versions.is_empty() { @@ -91,7 +91,7 @@ impl Install { Some(tv) => requests.push(tv), None => { if ta.tvr.is_none() { - match ts.versions.get(&ta.forge) { + match ts.versions.get(&ta.backend) { // the tool is in config so fetch the params from config // this may match multiple versions of one tool (e.g.: python) Some(tvl) => { @@ -103,7 +103,7 @@ impl Install { // so we default to @latest with no options None => { let tvr = ToolRequest::Version { - forge: ta.forge.clone(), + backend: ta.backend.clone(), version: "latest".into(), options: default_opts.clone(), }; diff --git a/src/cli/latest.rs b/src/cli/latest.rs index 6064a6560..345ca25de 100644 --- a/src/cli/latest.rs +++ b/src/cli/latest.rs @@ -1,8 +1,8 @@ use color_eyre::eyre::{bail, Result}; +use crate::backend::ABackend; use crate::cli::args::ToolArg; use crate::config::Config; -use crate::forge::AForge; use crate::toolset::ToolRequest; use crate::ui::multi_progress_report::MultiProgressReport; @@ -34,7 +34,7 @@ impl Latest { _ => bail!("invalid version: {}", self.tool.style()), }; - let plugin: AForge = self.tool.forge.into(); + let plugin: ABackend = self.tool.backend.into(); let mpr = MultiProgressReport::get(); plugin.ensure_installed(&mpr, false)?; if let Some(v) = prefix { diff --git a/src/cli/link.rs b/src/cli/link.rs index f7c1dc5b8..921c0bd68 100644 --- a/src/cli/link.rs +++ b/src/cli/link.rs @@ -46,7 +46,7 @@ impl Link { style(path.to_string_lossy()).cyan().for_stderr() ); } - let target = self.tool.forge.installs_path.join(version); + let target = self.tool.backend.installs_path.join(version); if target.exists() { if self.force { remove_all(&target)?; diff --git a/src/cli/local.rs b/src/cli/local.rs index a151c9f53..4e9fec433 100644 --- a/src/cli/local.rs +++ b/src/cli/local.rs @@ -4,7 +4,7 @@ use color_eyre::eyre::{eyre, ContextCompat, Result}; use console::style; use itertools::Itertools; -use crate::cli::args::{ForgeArg, ToolArg}; +use crate::cli::args::{BackendArg, ToolArg}; use crate::config::{config_file, Settings}; use crate::env::{MISE_DEFAULT_CONFIG_FILENAME, MISE_DEFAULT_TOOL_VERSIONS_FILENAME}; use crate::file::display_path; @@ -44,7 +44,7 @@ pub struct Local { /// Remove the plugin(s) from .tool-versions #[clap(long, value_name = "PLUGIN", aliases = ["rm", "unset"])] - remove: Option>, + remove: Option>, /// Get the path of the config file #[clap(long)] @@ -91,7 +91,7 @@ pub fn get_parent_path() -> Result { pub fn local( path: &Path, runtime: Vec, - remove: Option>, + remove: Option>, pin: bool, fuzzy: bool, show_path: bool, @@ -165,7 +165,7 @@ mod tests { use crate::cli::tests::grep; use crate::test::{cleanup, reset}; - use crate::{dirs, forge}; + use crate::{backend, dirs}; #[test] fn test_local_remove() { @@ -227,7 +227,7 @@ mod tests { assert_cli_snapshot!("local", "--path"); assert_cli_snapshot!("local", "tiny@2", "tiny@1", "tiny@3"); assert_cli!("install"); - forge::reset(); + backend::reset(); assert_cli_snapshot!("bin-paths"); }); } diff --git a/src/cli/ls.rs b/src/cli/ls.rs index 5014827f1..3603fd691 100644 --- a/src/cli/ls.rs +++ b/src/cli/ls.rs @@ -11,12 +11,12 @@ use serde_derive::Serialize; use tabled::{Table, Tabled}; use versions::Versioning; -use crate::cli::args::ForgeArg; +use crate::backend::Backend; +use crate::cli::args::BackendArg; use crate::config::Config; -use crate::forge::Forge; use crate::toolset::{ToolSource, ToolVersion, Toolset}; use crate::ui::table; -use crate::{config, forge}; +use crate::{backend, config}; /// List installed and active tool versions /// @@ -30,10 +30,10 @@ use crate::{config, forge}; pub struct Ls { /// Only show tool versions from [PLUGIN] #[clap(conflicts_with = "plugin_flag")] - plugin: Option>, + plugin: Option>, #[clap(long = "plugin", short, hide = true)] - plugin_flag: Option, + plugin_flag: Option, /// Only show tool versions currently specified in a .tool-versions/.mise.toml #[clap(long, short)] @@ -105,7 +105,7 @@ impl Ls { match &self.plugin { Some(plugins) => { for fa in plugins { - let plugin = forge::get(fa); + let plugin = backend::get(fa); ensure!(plugin.is_installed(), "{fa} is not installed"); } } @@ -151,7 +151,7 @@ impl Ls { // only displaying 1 plugin so only show the version miseprintln!("{}", tv.version); } else { - miseprintln!("{} {}", &tv.forge, tv.version); + miseprintln!("{} {}", &tv.backend, tv.version); } } Ok(()) @@ -192,7 +192,7 @@ impl Ls { let mut ts = Toolset::from(trs); ts.resolve()?; - let mut versions: HashMap<(String, String), (Arc, ToolVersion)> = ts + let mut versions: HashMap<(String, String), (Arc, ToolVersion)> = ts .list_installed_versions()? .into_iter() .map(|(p, tv)| ((p.id().into(), tv.version.clone()), (p, tv))) @@ -202,7 +202,7 @@ impl Ls { .list_current_versions() .into_iter() .map(|(p, tv)| ((p.id().into(), tv.version.clone()), (p, tv))) - .collect::, ToolVersion)>>(); + .collect::, ToolVersion)>>(); versions.extend(active.clone()); @@ -221,7 +221,7 @@ impl Ls { }) .map(|(k, (p, tv))| { let source = match &active.get(&k) { - Some((_, tv)) => ts.versions.get(&tv.forge).map(|tv| tv.source.clone()), + Some((_, tv)) => ts.versions.get(&tv.backend).map(|tv| tv.source.clone()), None => None, }; (p, tv, source) @@ -229,7 +229,7 @@ impl Ls { // if it isn't installed and it's not specified, don't show it .filter(|(p, tv, source)| source.is_some() || p.is_version_installed(tv)) .filter(|(p, _, _)| match &self.plugin { - Some(forge) => forge.contains(p.fa()), + Some(backend) => backend.contains(p.fa()), None => true, }) .collect(); @@ -254,13 +254,13 @@ struct JSONToolVersion { active: bool, } -type RuntimeRow = (Arc, ToolVersion, Option); +type RuntimeRow = (Arc, ToolVersion, Option); #[derive(Tabled)] #[tabled(rename_all = "PascalCase")] struct Row { #[tabled(display_with = "Self::display_plugin")] - plugin: Arc, + plugin: Arc, version: VersionStatus, #[tabled(rename = "Config Source", display_with = "Self::display_source")] source: Option, @@ -275,7 +275,7 @@ impl Row { None => String::new(), } } - fn display_plugin(plugin: &Arc) -> String { + fn display_plugin(plugin: &Arc) -> String { style(plugin).blue().to_string() } fn display_source(source: &Option) -> String { @@ -309,8 +309,8 @@ enum VersionStatus { Symlink(String, bool), } -impl From<(&dyn Forge, &ToolVersion, &Option)> for VersionStatus { - fn from((p, tv, source): (&dyn Forge, &ToolVersion, &Option)) -> Self { +impl From<(&dyn Backend, &ToolVersion, &Option)> for VersionStatus { + fn from((p, tv, source): (&dyn Backend, &ToolVersion, &Option)) -> Self { if p.symlink_path(tv).is_some() { VersionStatus::Symlink(tv.version.clone(), source.is_some()) } else if !p.is_version_installed(tv) { diff --git a/src/cli/ls_remote.rs b/src/cli/ls_remote.rs index 497a6a17e..92fee9c04 100644 --- a/src/cli/ls_remote.rs +++ b/src/cli/ls_remote.rs @@ -4,9 +4,9 @@ use eyre::Result; use itertools::Itertools; use rayon::prelude::*; +use crate::backend; +use crate::backend::Backend; use crate::cli::args::ToolArg; -use crate::forge; -use crate::forge::Forge; use crate::toolset::ToolRequest; use crate::ui::multi_progress_report::MultiProgressReport; @@ -40,7 +40,7 @@ impl LsRemote { } } - fn run_single(self, plugin: Arc) -> Result<()> { + fn run_single(self, plugin: Arc) -> Result<()> { let prefix = match &self.plugin { Some(tool_arg) => match &tool_arg.tvr { Some(ToolRequest::Version { version: v, .. }) => Some(v.clone()), @@ -66,7 +66,7 @@ impl LsRemote { } fn run_all(self) -> Result<()> { - let versions = forge::list() + let versions = backend::list() .into_par_iter() .map(|p| { let versions = p.list_remote_versions()?; @@ -84,10 +84,10 @@ impl LsRemote { Ok(()) } - fn get_plugin(&self) -> Result>> { + fn get_plugin(&self) -> Result>> { match &self.plugin { Some(tool_arg) => { - let plugin = forge::get(&tool_arg.forge); + let plugin = backend::get(&tool_arg.backend); let mpr = MultiProgressReport::get(); plugin.ensure_installed(&mpr, false)?; Ok(Some(plugin)) diff --git a/src/cli/outdated.rs b/src/cli/outdated.rs index 0c724714b..886c5916c 100644 --- a/src/cli/outdated.rs +++ b/src/cli/outdated.rs @@ -4,9 +4,9 @@ use std::sync::Arc; use console::{pad_str, style, Alignment}; use eyre::Result; +use crate::backend::Backend; use crate::cli::args::ToolArg; use crate::config::Config; -use crate::forge::Forge; use crate::toolset::{ToolVersion, ToolsetBuilder}; /// Shows outdated tool versions @@ -31,10 +31,10 @@ impl Outdated { let tool_set = self .tool .iter() - .map(|t| t.forge.clone()) + .map(|t| t.backend.clone()) .collect::>(); ts.versions - .retain(|_, tvl| tool_set.is_empty() || tool_set.contains(&tvl.forge)); + .retain(|_, tvl| tool_set.is_empty() || tool_set.contains(&tvl.backend)); let outdated = ts.list_outdated_versions(); if outdated.is_empty() { info!("All tools are up to date"); @@ -126,7 +126,7 @@ impl Outdated { } } -type OutputVec = Vec<(Arc, ToolVersion, String)>; +type OutputVec = Vec<(Arc, ToolVersion, String)>; static AFTER_LONG_HELP: &str = color_print::cstr!( r#"Examples: diff --git a/src/cli/plugins/install.rs b/src/cli/plugins/install.rs index 096947826..82cd9d8f5 100644 --- a/src/cli/plugins/install.rs +++ b/src/cli/plugins/install.rs @@ -3,9 +3,9 @@ use rayon::prelude::*; use rayon::ThreadPoolBuilder; use url::Url; +use crate::backend::asdf::Asdf; +use crate::backend::{unalias_backend, Backend}; use crate::config::{Config, Settings}; -use crate::forge::asdf::Asdf; -use crate::forge::{unalias_forge, Forge}; use crate::plugins::core::CORE_PLUGINS; use crate::toolset::ToolsetBuilder; use crate::ui::multi_progress_report::MultiProgressReport; @@ -121,7 +121,7 @@ impl PluginsInstall { } fn get_name_and_url(name: &str, git_url: &Option) -> Result<(String, Option)> { - let name = unalias_forge(name); + let name = unalias_backend(name); Ok(match git_url { Some(url) => match url.contains(':') { true => (name.to_string(), Some(url.clone())), @@ -142,7 +142,7 @@ fn get_name_from_url(url: &str) -> Result { let name = name.strip_prefix("rtx-").unwrap_or(name); let name = name.strip_prefix("mise-").unwrap_or(name); let name = name.strip_suffix(".git").unwrap_or(name); - return Ok(unalias_forge(name).to_string()); + return Ok(unalias_backend(name).to_string()); } } Err(eyre!("could not infer plugin name from url: {}", url)) diff --git a/src/cli/plugins/link.rs b/src/cli/plugins/link.rs index 9d1701997..16c8c94ef 100644 --- a/src/cli/plugins/link.rs +++ b/src/cli/plugins/link.rs @@ -5,8 +5,8 @@ use color_eyre::eyre::{eyre, Result}; use console::style; use path_absolutize::Absolutize; +use crate::backend::unalias_backend; use crate::file::{make_symlink, remove_all}; -use crate::forge::unalias_forge; use crate::{dirs, file}; /// Symlinks a plugin into mise @@ -40,7 +40,7 @@ impl PluginsLink { (name, path) } }; - let name = unalias_forge(&name); + let name = unalias_backend(&name); let path = path.absolutize()?; let symlink = dirs::PLUGINS.join(name); if symlink.exists() { @@ -64,7 +64,7 @@ fn get_name_from_path(path: &Path) -> String { let name = name.strip_prefix("asdf-").unwrap_or(name); let name = name.strip_prefix("rtx-").unwrap_or(name); let name = name.strip_prefix("mise-").unwrap_or(name); - unalias_forge(name).to_string() + unalias_backend(name).to_string() } static AFTER_LONG_HELP: &str = color_print::cstr!( diff --git a/src/cli/plugins/uninstall.rs b/src/cli/plugins/uninstall.rs index 1989c4fce..beda6e098 100644 --- a/src/cli/plugins/uninstall.rs +++ b/src/cli/plugins/uninstall.rs @@ -1,6 +1,6 @@ use eyre::Result; -use crate::forge::unalias_forge; +use crate::backend::unalias_backend; use crate::plugins; use crate::ui::multi_progress_report::MultiProgressReport; use crate::ui::style; @@ -35,7 +35,7 @@ impl PluginsUninstall { }; for plugin_name in plugins { - let plugin_name = unalias_forge(&plugin_name); + let plugin_name = unalias_backend(&plugin_name); self.uninstall_one(plugin_name, &mpr)?; } Ok(()) diff --git a/src/cli/prune.rs b/src/cli/prune.rs index 065f5b3cd..97701849c 100644 --- a/src/cli/prune.rs +++ b/src/cli/prune.rs @@ -4,10 +4,10 @@ use std::sync::Arc; use console::style; use eyre::Result; -use crate::cli::args::ForgeArg; +use crate::backend::Backend; +use crate::cli::args::BackendArg; use crate::config::tracking::Tracker; use crate::config::{Config, Settings}; -use crate::forge::Forge; use crate::toolset::{ToolVersion, Toolset, ToolsetBuilder}; use crate::ui::multi_progress_report::MultiProgressReport; use crate::ui::prompt; @@ -25,7 +25,7 @@ use super::trust::Trust; pub struct Prune { /// Prune only versions from this plugin(s) #[clap()] - pub plugin: Option>, + pub plugin: Option>, /// Do not actually delete anything #[clap(long, short = 'n')] @@ -69,10 +69,10 @@ impl Prune { .list_installed_versions()? .into_iter() .map(|(p, tv)| (tv.to_string(), (p, tv))) - .collect::, ToolVersion)>>(); + .collect::, ToolVersion)>>(); - if let Some(forges) = &self.plugin { - to_delete.retain(|_, (_, tv)| forges.contains(&tv.forge)); + if let Some(backends) = &self.plugin { + to_delete.retain(|_, (_, tv)| backends.contains(&tv.backend)); } for cf in config.get_tracked_config_files()?.values() { @@ -86,7 +86,7 @@ impl Prune { self.delete(to_delete.into_values().collect()) } - fn delete(&self, to_delete: Vec<(Arc, ToolVersion)>) -> Result<()> { + fn delete(&self, to_delete: Vec<(Arc, ToolVersion)>) -> Result<()> { let settings = Settings::try_get()?; let mpr = MultiProgressReport::get(); for (p, tv) in to_delete { diff --git a/src/cli/uninstall.rs b/src/cli/uninstall.rs index 9e29e2841..5a3e70e19 100644 --- a/src/cli/uninstall.rs +++ b/src/cli/uninstall.rs @@ -5,12 +5,12 @@ use eyre::{bail, eyre, Result, WrapErr}; use itertools::Itertools; use rayon::prelude::*; +use crate::backend::Backend; use crate::cli::args::ToolArg; use crate::config::Config; -use crate::forge::Forge; use crate::toolset::{ToolRequest, ToolVersion, ToolsetBuilder}; use crate::ui::multi_progress_report::MultiProgressReport; -use crate::{forge, runtime_symlinks, shims}; +use crate::{backend, runtime_symlinks, shims}; /// Removes runtime versions #[derive(Debug, clap::Args)] @@ -72,7 +72,10 @@ impl Uninstall { Ok(()) } - fn get_all_tool_versions(&self, config: &Config) -> Result, ToolVersion)>> { + fn get_all_tool_versions( + &self, + config: &Config, + ) -> Result, ToolVersion)>> { let ts = ToolsetBuilder::new().build(config)?; let tool_versions = ts .list_installed_versions()? @@ -80,12 +83,12 @@ impl Uninstall { .collect::>(); Ok(tool_versions) } - fn get_requested_tool_versions(&self) -> Result, ToolVersion)>> { + fn get_requested_tool_versions(&self) -> Result, ToolVersion)>> { let runtimes = ToolArg::double_tool_condition(&self.installed_tool)?; let tool_versions = runtimes .into_par_iter() .map(|a| { - let tool = forge::get(&a.forge); + let tool = backend::get(&a.backend); let query = a.tvr.as_ref().map(|tvr| tvr.version()).unwrap_or_default(); let installed_versions = tool.list_installed_versions()?; let exact_match = installed_versions.iter().find(|v| v == &&query); diff --git a/src/cli/upgrade.rs b/src/cli/upgrade.rs index 5739b0a37..f3b2b1e72 100644 --- a/src/cli/upgrade.rs +++ b/src/cli/upgrade.rs @@ -4,9 +4,9 @@ use std::sync::Arc; use demand::DemandOption; use eyre::{Context, Result}; +use crate::backend::Backend; use crate::cli::args::ToolArg; use crate::config::Config; -use crate::forge::Forge; use crate::toolset::{InstallOptions, ToolVersion, ToolsetBuilder}; use crate::ui::multi_progress_report::MultiProgressReport; use crate::ui::progress_report::SingleReport; @@ -53,7 +53,7 @@ impl Upgrade { let tool_set = self .tool .iter() - .map(|t| t.forge.clone()) + .map(|t| t.backend.clone()) .collect::>(); outdated.retain(|(p, _, _)| tool_set.is_empty() || tool_set.contains(p.fa())); } @@ -115,7 +115,7 @@ impl Upgrade { fn uninstall_old_version( &self, - tool: Arc, + tool: Arc, tv: &ToolVersion, pr: &dyn SingleReport, ) -> Result<()> { @@ -143,7 +143,7 @@ impl Upgrade { } } -type OutputVec = Vec<(Arc, ToolVersion, String)>; +type OutputVec = Vec<(Arc, ToolVersion, String)>; #[cfg(test)] pub mod tests { diff --git a/src/cli/use.rs b/src/cli/use.rs index 1d3a9beec..c681f077a 100644 --- a/src/cli/use.rs +++ b/src/cli/use.rs @@ -4,7 +4,7 @@ use console::style; use eyre::Result; use itertools::Itertools; -use crate::cli::args::{ForgeArg, ToolArg}; +use crate::cli::args::{BackendArg, ToolArg}; use crate::config::config_file::ConfigFile; use crate::config::{config_file, Config, Settings, LOCAL_CONFIG_FILENAMES}; use crate::env::{MISE_DEFAULT_CONFIG_FILENAME, MISE_GLOBAL_CONFIG_FILE}; @@ -62,7 +62,7 @@ pub struct Use { /// Remove the plugin(s) from config file #[clap(long, value_name = "PLUGIN", aliases = ["rm", "unset"])] - remove: Vec, + remove: Vec, /// Specify a path to a config file or directory /// If a directory is specified, it will look for .mise.toml (default) or .tool-versions @@ -87,7 +87,7 @@ impl Use { .cloned() .map(|t| match t.tvr { Some(tvr) => Ok(tvr), - None => ToolRequest::new(t.forge, "latest"), + None => ToolRequest::new(t.backend, "latest"), }) .collect::>()?; let versions = ts.install_versions( @@ -106,7 +106,7 @@ impl Use { let settings = Settings::try_get()?; let pin = self.pin || (settings.asdf_compat && !self.fuzzy); - for (fa, tvl) in &versions.iter().group_by(|tv| &tv.forge) { + for (fa, tvl) in &versions.iter().group_by(|tv| &tv.backend) { let versions: Vec = tvl .into_iter() .map(|tv| { @@ -147,13 +147,13 @@ impl Use { fn warn_if_hidden(&self, config: &Config, global: &Path) { let ts = ToolsetBuilder::new().build(config).unwrap_or_default(); let warn = |targ: &ToolArg, p| { - let plugin = &targ.forge; + let plugin = &targ.backend; let p = display_path(p); let global = display_path(global); warn!("{plugin} is defined in {p} which overrides the global config ({global})"); }; for targ in &self.tool { - if let Some(tv) = ts.versions.get(&targ.forge) { + if let Some(tv) = ts.versions.get(&targ.backend) { if let ToolSource::MiseToml(p) | ToolSource::ToolVersions(p) = &tv.source { if p != global { warn(targ, p); diff --git a/src/cli/watch.rs b/src/cli/watch.rs index 262497d7c..93d9ddd21 100644 --- a/src/cli/watch.rs +++ b/src/cli/watch.rs @@ -3,7 +3,7 @@ use std::process::exit; use console::style; use eyre::{eyre, Result}; -use crate::cli::args::ForgeArg; +use crate::cli::args::BackendArg; use crate::cmd; use crate::config::{Config, Settings}; use crate::toolset::ToolsetBuilder; @@ -72,7 +72,7 @@ impl Watch { let ts = ToolsetBuilder::new().build(&config)?; settings.ensure_experimental("`mise watch`")?; if let Err(err) = which::which("watchexec") { - let watchexec: ForgeArg = "watchexec".into(); + let watchexec: BackendArg = "watchexec".into(); if !ts.versions.contains_key(&watchexec) { eprintln!("{}: {}", style("Error").red().bold(), err); eprintln!("{}: Install watchexec with:", style("Hint").bold()); diff --git a/src/cli/where.rs b/src/cli/where.rs index 7e7273d91..865287c7b 100644 --- a/src/cli/where.rs +++ b/src/cli/where.rs @@ -1,9 +1,9 @@ use eyre::Result; +use crate::backend; use crate::cli::args::ToolArg; use crate::config::Config; use crate::errors::Error::VersionNotInstalled; -use crate::forge; use crate::toolset::ToolsetBuilder; /// Display the installation path for a runtime @@ -39,7 +39,7 @@ impl Where { .build(&config)?; let v = ts .versions - .get(&self.tool.forge) + .get(&self.tool.backend) .and_then(|v| v.requests.first()) .map(|r| r.version()); self.tool.with_version(&v.unwrap_or(String::from("latest"))) @@ -48,7 +48,7 @@ impl Where { _ => self.tool, }; - let plugin = forge::get(&runtime.forge); + let plugin = backend::get(&runtime.backend); match runtime .tvr @@ -60,7 +60,7 @@ impl Where { Ok(()) } _ => Err(VersionNotInstalled( - runtime.forge.to_string(), + runtime.backend.to_string(), runtime.tvr.map(|tvr| tvr.version()).unwrap_or_default(), ))?, } diff --git a/src/config/config_file/legacy_version.rs b/src/config/config_file/legacy_version.rs index b01bdf887..f24c20db4 100644 --- a/src/config/config_file/legacy_version.rs +++ b/src/config/config_file/legacy_version.rs @@ -2,9 +2,9 @@ use std::path::{Path, PathBuf}; use eyre::Result; -use crate::cli::args::ForgeArg; +use crate::backend::BackendList; +use crate::cli::args::BackendArg; use crate::config::config_file::ConfigFile; -use crate::forge::ForgeList; use crate::toolset::{ToolRequest, ToolRequestSet, ToolSource}; #[derive(Debug)] @@ -14,7 +14,7 @@ pub struct LegacyVersionFile { } impl LegacyVersionFile { - pub fn parse(path: PathBuf, plugins: ForgeList) -> Result { + pub fn parse(path: PathBuf, plugins: BackendList) -> Result { let source = ToolSource::LegacyVersionFile(path.clone()); let mut tools = ToolRequestSet::new(); @@ -35,11 +35,11 @@ impl ConfigFile for LegacyVersionFile { self.path.as_path() } - fn remove_plugin(&mut self, _fa: &ForgeArg) -> Result<()> { + fn remove_plugin(&mut self, _fa: &BackendArg) -> Result<()> { unimplemented!() } - fn replace_versions(&mut self, _plugin_name: &ForgeArg, _versions: &[String]) -> Result<()> { + fn replace_versions(&mut self, _plugin_name: &BackendArg, _versions: &[String]) -> Result<()> { unimplemented!() } diff --git a/src/config/config_file/mise_toml.rs b/src/config/config_file/mise_toml.rs index 3786a283e..00df53249 100644 --- a/src/config/config_file/mise_toml.rs +++ b/src/config/config_file/mise_toml.rs @@ -13,7 +13,7 @@ use tera::Context as TeraContext; use toml_edit::{table, value, Array, DocumentMut, Item, Value}; use versions::Versioning; -use crate::cli::args::{ForgeArg, ToolVersionType}; +use crate::cli::args::{BackendArg, ToolVersionType}; use crate::config::config_file::toml::deserialize_arr; use crate::config::config_file::{trust_check, ConfigFile, TaskConfig}; use crate::config::env_directive::EnvDirective; @@ -45,7 +45,7 @@ pub struct MiseToml { #[serde(skip)] doc: OnceCell, #[serde(default)] - tools: IndexMap, + tools: IndexMap, #[serde(default)] plugins: HashMap, #[serde(default)] @@ -109,7 +109,7 @@ impl MiseToml { Ok(self.doc.get_mut().unwrap()) } - pub fn set_alias(&mut self, fa: &ForgeArg, from: &str, to: &str) -> eyre::Result<()> { + pub fn set_alias(&mut self, fa: &BackendArg, from: &str, to: &str) -> eyre::Result<()> { self.alias .entry(fa.clone()) .or_default() @@ -127,7 +127,7 @@ impl MiseToml { Ok(()) } - pub fn remove_alias(&mut self, fa: &ForgeArg, from: &str) -> eyre::Result<()> { + pub fn remove_alias(&mut self, fa: &BackendArg, from: &str) -> eyre::Result<()> { if let Some(aliases) = self .doc_mut()? .get_mut("alias") @@ -250,7 +250,7 @@ impl ConfigFile for MiseToml { self.tasks.0.values().collect() } - fn remove_plugin(&mut self, fa: &ForgeArg) -> eyre::Result<()> { + fn remove_plugin(&mut self, fa: &BackendArg) -> eyre::Result<()> { self.tools.shift_remove(fa); let doc = self.doc_mut()?; if let Some(tools) = doc.get_mut("tools") { @@ -264,7 +264,7 @@ impl ConfigFile for MiseToml { Ok(()) } - fn replace_versions(&mut self, fa: &ForgeArg, versions: &[String]) -> eyre::Result<()> { + fn replace_versions(&mut self, fa: &BackendArg, versions: &[String]) -> eyre::Result<()> { self.tools.entry(fa.clone()).or_default().0 = versions .iter() .map(|v| MiseTomlTool { @@ -805,17 +805,17 @@ impl<'de> de::Deserialize<'de> for Tasks { } } -impl<'de> de::Deserialize<'de> for ForgeArg { +impl<'de> de::Deserialize<'de> for BackendArg { fn deserialize(deserializer: D) -> std::result::Result where D: de::Deserializer<'de>, { - struct ForgeArgVisitor; + struct BackendArgVisitor; - impl<'de> Visitor<'de> for ForgeArgVisitor { - type Value = ForgeArg; + impl<'de> Visitor<'de> for BackendArgVisitor { + type Value = BackendArg; fn expecting(&self, formatter: &mut Formatter) -> std::fmt::Result { - formatter.write_str("forge argument") + formatter.write_str("backend argument") } fn visit_str(self, v: &str) -> Result @@ -826,7 +826,7 @@ impl<'de> de::Deserialize<'de> for ForgeArg { } } - deserializer.deserialize_any(ForgeArgVisitor) + deserializer.deserialize_any(BackendArgVisitor) } } @@ -848,7 +848,7 @@ where { let mut aliases = AliasMap::new(); while let Some(plugin) = map.next_key::()? { - let fa: ForgeArg = plugin.as_str().into(); + let fa: BackendArg = plugin.as_str().into(); let plugin_aliases = aliases.entry(fa).or_default(); for (from, to) in map.next_value::>()? { plugin_aliases.insert(from, to); diff --git a/src/config/config_file/mod.rs b/src/config/config_file/mod.rs index 990384abf..c8e17c910 100644 --- a/src/config/config_file/mod.rs +++ b/src/config/config_file/mod.rs @@ -12,7 +12,7 @@ use versions::Versioning; use tool_versions::ToolVersions; -use crate::cli::args::{ForgeArg, ToolArg}; +use crate::cli::args::{BackendArg, ToolArg}; use crate::config::config_file::mise_toml::MiseToml; use crate::config::env_directive::EnvDirective; use crate::config::{AliasMap, Settings}; @@ -22,7 +22,7 @@ use crate::hash::{file_hash_sha256, hash_to_str}; use crate::task::Task; use crate::toolset::{ToolRequestSet, ToolSource, ToolVersionList, Toolset}; use crate::ui::{prompt, style}; -use crate::{dirs, env, file, forge}; +use crate::{backend, dirs, env, file}; pub mod legacy_version; pub mod mise_toml; @@ -69,8 +69,8 @@ pub trait ConfigFile: Debug + Send + Sync { fn tasks(&self) -> Vec<&Task> { Default::default() } - fn remove_plugin(&mut self, _fa: &ForgeArg) -> eyre::Result<()>; - fn replace_versions(&mut self, fa: &ForgeArg, versions: &[String]) -> eyre::Result<()>; + fn remove_plugin(&mut self, _fa: &BackendArg) -> eyre::Result<()>; + fn replace_versions(&mut self, fa: &BackendArg, versions: &[String]) -> eyre::Result<()>; fn save(&self) -> eyre::Result<()>; fn dump(&self) -> eyre::Result; fn to_toolset(&self) -> eyre::Result { @@ -95,7 +95,7 @@ impl dyn ConfigFile { for ta in tools { if let Some(tv) = &ta.tvr { plugins_to_update - .entry(ta.forge.clone()) + .entry(ta.backend.clone()) .or_insert_with(Vec::new) .push(tv); } @@ -116,7 +116,7 @@ impl dyn ConfigFile { .into_iter() .map(|tvr| { if pin { - let plugin = forge::get(&fa); + let plugin = backend::get(&fa); let tv = tvr.resolve(plugin.as_ref(), false)?; Ok(tv.version) } else { @@ -136,7 +136,7 @@ impl dyn ConfigFile { pub fn display_runtime(&self, runtimes: &[ToolArg]) -> eyre::Result { // in this situation we just print the current version in the config file if runtimes.len() == 1 && runtimes[0].tvr.is_none() { - let fa = &runtimes[0].forge; + let fa = &runtimes[0].backend; let tvl = self .to_toolset()? .versions diff --git a/src/config/config_file/snapshots/mise__config__config_file__mise_toml__tests__fixture-3.snap b/src/config/config_file/snapshots/mise__config__config_file__mise_toml__tests__fixture-3.snap index be6563cff..59fa22dc2 100644 --- a/src/config/config_file/snapshots/mise__config__config_file__mise_toml__tests__fixture-3.snap +++ b/src/config/config_file/snapshots/mise__config__config_file__mise_toml__tests__fixture-3.snap @@ -4,77 +4,77 @@ expression: "replace_path(&format!(\"{:#?}\", cf.to_tool_request_set().unwrap()) --- ToolRequestSet { tools: { - ForgeArg("terraform"): [ + BackendArg("terraform"): [ Version { - forge: ForgeArg("terraform"), + backend: BackendArg("terraform"), version: "1.0.0", options: {}, }, ], - ForgeArg("node"): [ + BackendArg("node"): [ Version { - forge: ForgeArg("node"), + backend: BackendArg("node"), version: "18", options: {}, }, Prefix { - forge: ForgeArg("node"), + backend: BackendArg("node"), prefix: "20", options: {}, }, Ref { - forge: ForgeArg("node"), + backend: BackendArg("node"), ref_: "master", options: {}, }, Path( - ForgeArg("node"), + BackendArg("node"), "~/.nodes/18", ), ], - ForgeArg("jq"): [ + BackendArg("jq"): [ Prefix { - forge: ForgeArg("jq"), + backend: BackendArg("jq"), prefix: "1.6", options: {}, }, ], - ForgeArg("shellcheck"): [ + BackendArg("shellcheck"): [ Version { - forge: ForgeArg("shellcheck"), + backend: BackendArg("shellcheck"), version: "0.9.0", options: {}, }, ], - ForgeArg("python"): [ + BackendArg("python"): [ Version { - forge: ForgeArg("python"), + backend: BackendArg("python"), version: "3.10.0", options: { "venv": ".venv", }, }, Version { - forge: ForgeArg("python"), + backend: BackendArg("python"), version: "3.9.0", options: {}, }, ], }, sources: { - ForgeArg("jq"): MiseToml( + BackendArg("jq"): MiseToml( "~/fixtures/.mise.toml", ), - ForgeArg("node"): MiseToml( + BackendArg("node"): MiseToml( "~/fixtures/.mise.toml", ), - ForgeArg("python"): MiseToml( + BackendArg("python"): MiseToml( "~/fixtures/.mise.toml", ), - ForgeArg("shellcheck"): MiseToml( + BackendArg("shellcheck"): MiseToml( "~/fixtures/.mise.toml", ), - ForgeArg("terraform"): MiseToml( + BackendArg("terraform"): MiseToml( "~/fixtures/.mise.toml", ), }, diff --git a/src/config/config_file/snapshots/mise__config__config_file__mise_toml__tests__fixture-4.snap b/src/config/config_file/snapshots/mise__config__config_file__mise_toml__tests__fixture-4.snap index c6db6307d..c8d84310c 100644 --- a/src/config/config_file/snapshots/mise__config__config_file__mise_toml__tests__fixture-4.snap +++ b/src/config/config_file/snapshots/mise__config__config_file__mise_toml__tests__fixture-4.snap @@ -3,7 +3,7 @@ source: src/config/config_file/mise_toml.rs expression: cf.alias --- { - ForgeArg("node"): { + BackendArg("node"): { "my_custom_node": "18", }, } diff --git a/src/config/config_file/snapshots/mise__config__config_file__mise_toml__tests__fixture-5.snap b/src/config/config_file/snapshots/mise__config__config_file__mise_toml__tests__fixture-5.snap index 1eff8b5b9..bfcb4bac5 100644 --- a/src/config/config_file/snapshots/mise__config__config_file__mise_toml__tests__fixture-5.snap +++ b/src/config/config_file/snapshots/mise__config__config_file__mise_toml__tests__fixture-5.snap @@ -11,7 +11,7 @@ MiseToml(~/fixtures/.mise.toml): ToolRequestSet: terraform@1.0.0 node@18 node@pr ), ], alias: { - ForgeArg("node"): { + BackendArg("node"): { "my_custom_node": "18", }, }, diff --git a/src/config/config_file/snapshots/mise__config__config_file__mise_toml__tests__remove_alias-4.snap b/src/config/config_file/snapshots/mise__config__config_file__mise_toml__tests__remove_alias-4.snap index 2a5f94f31..41f0d25c1 100644 --- a/src/config/config_file/snapshots/mise__config__config_file__mise_toml__tests__remove_alias-4.snap +++ b/src/config/config_file/snapshots/mise__config__config_file__mise_toml__tests__remove_alias-4.snap @@ -5,7 +5,7 @@ expression: cf MiseToml(~/cwd/.test.mise.toml): ToolRequestSet: { alias: { - ForgeArg("node"): { + BackendArg("node"): { "18": "18.0.0", }, }, diff --git a/src/config/config_file/snapshots/mise__config__config_file__mise_toml__tests__remove_alias.snap b/src/config/config_file/snapshots/mise__config__config_file__mise_toml__tests__remove_alias.snap index dbfd0f472..dcc27c900 100644 --- a/src/config/config_file/snapshots/mise__config__config_file__mise_toml__tests__remove_alias.snap +++ b/src/config/config_file/snapshots/mise__config__config_file__mise_toml__tests__remove_alias.snap @@ -3,7 +3,7 @@ source: src/config/config_file/mise_toml.rs expression: cf.alias --- { - ForgeArg("node"): { + BackendArg("node"): { "18": "18.0.0", }, } diff --git a/src/config/config_file/snapshots/mise__config__config_file__mise_toml__tests__replace_versions.snap b/src/config/config_file/snapshots/mise__config__config_file__mise_toml__tests__replace_versions.snap index 3b60b8ec3..6bf106ff1 100644 --- a/src/config/config_file/snapshots/mise__config__config_file__mise_toml__tests__replace_versions.snap +++ b/src/config/config_file/snapshots/mise__config__config_file__mise_toml__tests__replace_versions.snap @@ -4,17 +4,17 @@ expression: cf.to_toolset().unwrap() --- Toolset { versions: { - ForgeArg("node"): ToolVersionList { - forge: ForgeArg("node"), + BackendArg("node"): ToolVersionList { + backend: BackendArg("node"), versions: [], requests: [ Version { - forge: ForgeArg("node"), + backend: BackendArg("node"), version: "16.0.1", options: {}, }, Version { - forge: ForgeArg("node"), + backend: BackendArg("node"), version: "18.0.1", options: {}, }, diff --git a/src/config/config_file/snapshots/mise__config__config_file__mise_toml__tests__set_alias.snap b/src/config/config_file/snapshots/mise__config__config_file__mise_toml__tests__set_alias.snap index b439ce631..df7bdfaa0 100644 --- a/src/config/config_file/snapshots/mise__config__config_file__mise_toml__tests__set_alias.snap +++ b/src/config/config_file/snapshots/mise__config__config_file__mise_toml__tests__set_alias.snap @@ -3,12 +3,12 @@ source: src/config/config_file/mise_toml.rs expression: cf.alias --- { - ForgeArg("node"): { + BackendArg("node"): { "16": "16.0.0", "18": "18.0.1", "20": "20.0.0", }, - ForgeArg("python"): { + BackendArg("python"): { "3.10": "3.10.0", }, } diff --git a/src/config/config_file/tool_versions.rs b/src/config/config_file/tool_versions.rs index 8ab1edf52..32d1fc433 100644 --- a/src/config/config_file/tool_versions.rs +++ b/src/config/config_file/tool_versions.rs @@ -7,7 +7,7 @@ use indexmap::IndexMap; use itertools::Itertools; use tera::Context; -use crate::cli::args::ForgeArg; +use crate::cli::args::BackendArg; use crate::config::config_file; use crate::config::config_file::ConfigFile; use crate::file; @@ -25,7 +25,7 @@ pub struct ToolVersions { context: Context, path: PathBuf, pre: String, - plugins: IndexMap, + plugins: IndexMap, tools: ToolRequestSet, } @@ -75,7 +75,7 @@ impl ToolVersions { Ok(cf) } - fn get_or_create_plugin(&mut self, fa: &ForgeArg) -> &mut ToolVersionPlugin { + fn get_or_create_plugin(&mut self, fa: &BackendArg) -> &mut ToolVersionPlugin { self.plugins .entry(fa.clone()) .or_insert_with(|| ToolVersionPlugin { @@ -85,8 +85,8 @@ impl ToolVersions { }) } - fn parse_plugins(input: &str) -> IndexMap { - let mut plugins: IndexMap = IndexMap::new(); + fn parse_plugins(input: &str) -> IndexMap { + let mut plugins: IndexMap = IndexMap::new(); for line in input.lines() { if line.trim_start().starts_with('#') { if let Some(prev) = &mut plugins.values_mut().last() { @@ -118,7 +118,7 @@ impl ToolVersions { plugins } - fn add_version(&mut self, fa: &ForgeArg, version: &str) { + fn add_version(&mut self, fa: &BackendArg, version: &str) { self.get_or_create_plugin(fa) .versions .push(version.to_string()); @@ -157,12 +157,12 @@ impl ConfigFile for ToolVersions { self.path.as_path() } - fn remove_plugin(&mut self, fa: &ForgeArg) -> Result<()> { + fn remove_plugin(&mut self, fa: &BackendArg) -> Result<()> { self.plugins.shift_remove(fa); Ok(()) } - fn replace_versions(&mut self, fa: &ForgeArg, versions: &[String]) -> eyre::Result<()> { + fn replace_versions(&mut self, fa: &BackendArg, versions: &[String]) -> eyre::Result<()> { self.get_or_create_plugin(fa).versions.clear(); for version in versions { self.add_version(fa, version); diff --git a/src/config/env_directive.rs b/src/config/env_directive.rs index 91e4b6804..b07f80902 100644 --- a/src/config/env_directive.rs +++ b/src/config/env_directive.rs @@ -184,7 +184,7 @@ impl EnvResults { if ts .list_missing_versions() .iter() - .any(|tv| tv.forge.name == "python") + .any(|tv| tv.backend.name == "python") { debug!("python not installed, skipping venv creation"); } else { diff --git a/src/config/mod.rs b/src/config/mod.rs index 9e779ef5d..17cf64afe 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -12,7 +12,8 @@ use rayon::prelude::*; pub use settings::Settings; -use crate::cli::args::ForgeArg; +use crate::backend::Backend; +use crate::cli::args::BackendArg; use crate::cli::version; use crate::config::config_file::legacy_version::LegacyVersionFile; use crate::config::config_file::mise_toml::MiseToml; @@ -20,19 +21,18 @@ use crate::config::config_file::ConfigFile; use crate::config::env_directive::EnvResults; use crate::config::tracking::Tracker; use crate::file::display_path; -use crate::forge::Forge; use crate::shorthands::{get_shorthands, Shorthands}; use crate::task::Task; use crate::toolset::{ToolRequestSet, ToolRequestSetBuilder}; use crate::ui::style; -use crate::{dirs, env, file, forge}; +use crate::{backend, dirs, env, file}; pub mod config_file; mod env_directive; pub mod settings; pub mod tracking; -type AliasMap = BTreeMap>; +type AliasMap = BTreeMap>; type ConfigMap = IndexMap>; type EnvWithSources = IndexMap; @@ -173,13 +173,13 @@ impl Config { .collect()) } - pub fn resolve_alias(&self, forge: &dyn Forge, v: &str) -> Result { - if let Some(plugin_aliases) = self.aliases.get(forge.fa()) { + pub fn resolve_alias(&self, backend: &dyn Backend, v: &str) -> Result { + if let Some(plugin_aliases) = self.aliases.get(backend.fa()) { if let Some(alias) = plugin_aliases.get(v) { return Ok(alias.clone()); } } - if let Some(alias) = forge.get_aliases()?.get(v) { + if let Some(alias) = backend.get_aliases()?.get(v) { return Ok(alias.clone()); } Ok(v.to_string()) @@ -187,14 +187,14 @@ impl Config { fn load_all_aliases(&self) -> AliasMap { let mut aliases: AliasMap = self.aliases.clone(); - let plugin_aliases: Vec<_> = forge::list() + let plugin_aliases: Vec<_> = backend::list() .into_par_iter() - .map(|forge| { - let aliases = forge.get_aliases().unwrap_or_else(|err| { + .map(|backend| { + let aliases = backend.get_aliases().unwrap_or_else(|err| { warn!("get_aliases: {err}"); BTreeMap::new() }); - (forge.fa().clone(), aliases) + (backend.fa().clone(), aliases) }) .collect(); for (fa, plugin_aliases) in plugin_aliases { @@ -423,7 +423,7 @@ fn load_legacy_files(settings: &Settings) -> BTreeMap> { if !settings.legacy_version_file { return BTreeMap::new(); } - let legacy = forge::list() + let legacy = backend::list() .into_par_iter() .filter(|tool| { !settings @@ -593,7 +593,7 @@ fn parse_config_file( ) -> Result> { match legacy_filenames.get(&f.file_name().unwrap().to_string_lossy().to_string()) { Some(plugin) => { - let tools = forge::list() + let tools = backend::list() .into_iter() .filter(|f| plugin.contains(&f.to_string())) .collect::>(); diff --git a/src/config/snapshots/mise__config__tests__load.snap b/src/config/snapshots/mise__config__tests__load.snap index c72528482..f782f7ace 100644 --- a/src/config/snapshots/mise__config__tests__load.snap +++ b/src/config/snapshots/mise__config__tests__load.snap @@ -9,7 +9,7 @@ Config { "~/config/config.toml", ], Aliases: { - ForgeArg("tiny"): { + BackendArg("tiny"): { "my/alias": "3.0", }, }, diff --git a/src/main.rs b/src/main.rs index 47be9bb0f..c58a54e77 100644 --- a/src/main.rs +++ b/src/main.rs @@ -21,6 +21,7 @@ mod regex; #[macro_use] mod cmd; +mod backend; pub mod build_time; mod cache; mod cli; @@ -35,7 +36,6 @@ mod errors; #[cfg_attr(windows, path = "fake_asdf_windows.rs")] mod fake_asdf; mod file; -mod forge; mod git; pub mod github; mod hash; diff --git a/src/plugins/core/bun.rs b/src/plugins/core/bun.rs index eaaf3c916..906d60815 100644 --- a/src/plugins/core/bun.rs +++ b/src/plugins/core/bun.rs @@ -5,11 +5,11 @@ use eyre::Result; use itertools::Itertools; use versions::Versioning; -use crate::cli::args::ForgeArg; +use crate::backend::Backend; +use crate::cli::args::BackendArg; use crate::cli::version::{ARCH, OS}; use crate::cmd::CmdLineRunner; use crate::file; -use crate::forge::Forge; use crate::github::GithubRelease; use crate::http::{HTTP, HTTP_FETCH}; use crate::install_context::InstallContext; @@ -97,8 +97,8 @@ impl BunPlugin { } } -impl Forge for BunPlugin { - fn fa(&self) -> &ForgeArg { +impl Backend for BunPlugin { + fn fa(&self) -> &BackendArg { &self.core.fa } diff --git a/src/plugins/core/deno.rs b/src/plugins/core/deno.rs index 19fe06db9..560b3bcf9 100644 --- a/src/plugins/core/deno.rs +++ b/src/plugins/core/deno.rs @@ -6,12 +6,12 @@ use eyre::Result; use itertools::Itertools; use versions::Versioning; -use crate::cli::args::ForgeArg; +use crate::backend::Backend; +use crate::cli::args::BackendArg; use crate::cli::version::{ARCH, OS}; use crate::cmd::CmdLineRunner; use crate::config::Config; use crate::file; -use crate::forge::Forge; use crate::github::GithubRelease; use crate::http::{HTTP, HTTP_FETCH}; use crate::install_context::InstallContext; @@ -96,8 +96,8 @@ impl DenoPlugin { } } -impl Forge for DenoPlugin { - fn fa(&self) -> &ForgeArg { +impl Backend for DenoPlugin { + fn fa(&self) -> &BackendArg { &self.core.fa } diff --git a/src/plugins/core/erlang.rs b/src/plugins/core/erlang.rs index aad992253..a0d8db0e7 100644 --- a/src/plugins/core/erlang.rs +++ b/src/plugins/core/erlang.rs @@ -2,9 +2,9 @@ use std::path::PathBuf; use eyre::Result; -use crate::cli::args::ForgeArg; +use crate::backend::Backend; +use crate::cli::args::BackendArg; use crate::file::display_path; -use crate::forge::Forge; use crate::http::HTTP_FETCH; use crate::install_context::InstallContext; use crate::lock_file::LockFile; @@ -92,8 +92,8 @@ impl ErlangPlugin { } } -impl Forge for ErlangPlugin { - fn fa(&self) -> &ForgeArg { +impl Backend for ErlangPlugin { + fn fa(&self) -> &BackendArg { &self.core.fa } fn _list_remote_versions(&self) -> Result> { diff --git a/src/plugins/core/go.rs b/src/plugins/core/go.rs index 341b9062c..265eddecf 100644 --- a/src/plugins/core/go.rs +++ b/src/plugins/core/go.rs @@ -6,11 +6,11 @@ use itertools::Itertools; use tempfile::tempdir_in; use versions::Versioning; -use crate::cli::args::ForgeArg; +use crate::backend::Backend; +use crate::cli::args::BackendArg; use crate::cli::version::{ARCH, OS}; use crate::cmd::CmdLineRunner; use crate::config::{Config, Settings}; -use crate::forge::Forge; use crate::http::HTTP; use crate::install_context::InstallContext; use crate::plugins::core::CorePlugin; @@ -185,8 +185,8 @@ impl GoPlugin { } } -impl Forge for GoPlugin { - fn fa(&self) -> &ForgeArg { +impl Backend for GoPlugin { + fn fa(&self) -> &BackendArg { &self.core.fa } fn _list_remote_versions(&self) -> eyre::Result> { diff --git a/src/plugins/core/java.rs b/src/plugins/core/java.rs index 69a529ed1..d2279e677 100644 --- a/src/plugins/core/java.rs +++ b/src/plugins/core/java.rs @@ -12,12 +12,12 @@ use regex::Regex; use serde_derive::{Deserialize, Serialize}; use versions::Versioning; +use crate::backend::Backend; use crate::cache::CacheManager; -use crate::cli::args::ForgeArg; +use crate::cli::args::BackendArg; use crate::cli::version::{ARCH, OS}; use crate::cmd::CmdLineRunner; use crate::config::Config; -use crate::forge::Forge; use crate::http::{HTTP, HTTP_FETCH}; use crate::install_context::InstallContext; use crate::plugins::core::CorePlugin; @@ -301,8 +301,8 @@ impl JavaPlugin { } } -impl Forge for JavaPlugin { - fn fa(&self) -> &ForgeArg { +impl Backend for JavaPlugin { + fn fa(&self) -> &BackendArg { &self.core.fa } diff --git a/src/plugins/core/mod.rs b/src/plugins/core/mod.rs index 8d2f29733..6895dd1d6 100644 --- a/src/plugins/core/mod.rs +++ b/src/plugins/core/mod.rs @@ -7,11 +7,11 @@ use once_cell::sync::Lazy; pub use python::PythonPlugin; +use crate::backend::{Backend, BackendList}; use crate::cache::CacheManager; -use crate::cli::args::ForgeArg; +use crate::cli::args::BackendArg; use crate::config::Settings; use crate::env; -use crate::forge::{Forge, ForgeList}; use crate::http::HTTP_FETCH; use crate::plugins::core::bun::BunPlugin; use crate::plugins::core::deno::DenoPlugin; @@ -35,8 +35,8 @@ mod python; mod ruby; mod zig; -pub static CORE_PLUGINS: Lazy = Lazy::new(|| { - let mut plugins: Vec> = vec![ +pub static CORE_PLUGINS: Lazy = Lazy::new(|| { + let mut plugins: Vec> = vec![ Arc::new(BunPlugin::new()), Arc::new(DenoPlugin::new()), Arc::new(ErlangPlugin::new()), @@ -55,7 +55,7 @@ pub static CORE_PLUGINS: Lazy = Lazy::new(|| { #[derive(Debug)] pub struct CorePlugin { - pub fa: ForgeArg, + pub fa: BackendArg, pub remote_version_cache: CacheManager>, } @@ -69,7 +69,7 @@ impl CorePlugin { .collect() } - pub fn new(fa: ForgeArg) -> Self { + pub fn new(fa: BackendArg) -> Self { Self { remote_version_cache: CacheManager::new( fa.cache_path.join("remote_versions-$KEY.msgpack.z"), diff --git a/src/plugins/core/node.rs b/src/plugins/core/node.rs index 353c12e35..f16b2ea41 100644 --- a/src/plugins/core/node.rs +++ b/src/plugins/core/node.rs @@ -6,12 +6,12 @@ use serde_derive::Deserialize; use tempfile::tempdir_in; use url::Url; +use crate::backend::Backend; use crate::build_time::built_info; -use crate::cli::args::ForgeArg; +use crate::cli::args::BackendArg; use crate::cmd::CmdLineRunner; use crate::config::{Config, Settings}; use crate::env::MISE_NODE_MIRROR_URL; -use crate::forge::Forge; use crate::http::{HTTP, HTTP_FETCH}; use crate::install_context::InstallContext; use crate::plugins::core::CorePlugin; @@ -234,8 +234,8 @@ impl NodePlugin { } } -impl Forge for NodePlugin { - fn fa(&self) -> &ForgeArg { +impl Backend for NodePlugin { + fn fa(&self) -> &BackendArg { &self.core.fa } diff --git a/src/plugins/core/python.rs b/src/plugins/core/python.rs index 05124098a..0e0ce77fd 100644 --- a/src/plugins/core/python.rs +++ b/src/plugins/core/python.rs @@ -4,13 +4,13 @@ use std::path::{Path, PathBuf}; use eyre::{bail, eyre}; use itertools::Itertools; +use crate::backend::Backend; use crate::build_time::built_info; use crate::cache::CacheManager; -use crate::cli::args::ForgeArg; +use crate::cli::args::BackendArg; use crate::cmd::CmdLineRunner; use crate::config::{Config, Settings}; use crate::file::display_path; -use crate::forge::Forge; use crate::git::Git; use crate::http::{HTTP, HTTP_FETCH}; use crate::install_context::InstallContext; @@ -309,8 +309,8 @@ impl PythonPlugin { } } -impl Forge for PythonPlugin { - fn fa(&self) -> &ForgeArg { +impl Backend for PythonPlugin { + fn fa(&self) -> &BackendArg { &self.core.fa } diff --git a/src/plugins/core/ruby.rs b/src/plugins/core/ruby.rs index e636ba843..1435039da 100644 --- a/src/plugins/core/ruby.rs +++ b/src/plugins/core/ruby.rs @@ -5,11 +5,11 @@ use std::path::{Path, PathBuf}; use contracts::requires; use eyre::{Result, WrapErr}; -use crate::cli::args::ForgeArg; +use crate::backend::Backend; +use crate::cli::args::BackendArg; use crate::cmd::CmdLineRunner; use crate::config::{Config, Settings}; use crate::duration::DAILY; -use crate::forge::Forge; use crate::git::Git; use crate::github::GithubRelease; use crate::http::{HTTP, HTTP_FETCH}; @@ -327,8 +327,8 @@ impl RubyPlugin { } } -impl Forge for RubyPlugin { - fn fa(&self) -> &ForgeArg { +impl Backend for RubyPlugin { + fn fa(&self) -> &BackendArg { &self.core.fa } fn _list_remote_versions(&self) -> Result> { diff --git a/src/plugins/core/zig.rs b/src/plugins/core/zig.rs index b6c1bde9b..6976698ac 100644 --- a/src/plugins/core/zig.rs +++ b/src/plugins/core/zig.rs @@ -5,11 +5,11 @@ use eyre::Result; use itertools::Itertools; use versions::Versioning; -use crate::cli::args::ForgeArg; +use crate::backend::Backend; +use crate::cli::args::BackendArg; use crate::cli::version::{ARCH, OS}; use crate::cmd::CmdLineRunner; use crate::file; -use crate::forge::Forge; use crate::github::GithubRelease; use crate::http::{HTTP, HTTP_FETCH}; use crate::install_context::InstallContext; @@ -127,8 +127,8 @@ impl ZigPlugin { } } -impl Forge for ZigPlugin { - fn fa(&self) -> &ForgeArg { +impl Backend for ZigPlugin { + fn fa(&self) -> &BackendArg { &self.core.fa } diff --git a/src/plugins/mod.rs b/src/plugins/mod.rs index 5ae227b2f..3e18d71a5 100644 --- a/src/plugins/mod.rs +++ b/src/plugins/mod.rs @@ -6,9 +6,9 @@ use regex::Regex; pub use script_manager::{Script, ScriptManager}; -use crate::cli::args::ForgeArg; -use crate::forge; -use crate::forge::{AForge, ForgeList, ForgeType}; +use crate::backend; +use crate::backend::{ABackend, BackendList, BackendType}; +use crate::cli::args::BackendArg; use crate::plugins::asdf_plugin::AsdfPlugin; use crate::plugins::core::CorePlugin; @@ -30,14 +30,14 @@ pub static VERSION_REGEX: Lazy = Lazy::new(|| { .unwrap() }); -pub fn get(name: &str) -> AForge { - ForgeArg::new(ForgeType::Asdf, name).into() +pub fn get(name: &str) -> ABackend { + BackendArg::new(BackendType::Asdf, name).into() } -pub fn list() -> ForgeList { - forge::list() +pub fn list() -> BackendList { + backend::list() .into_iter() - .filter(|f| f.get_type() == ForgeType::Asdf) + .filter(|f| f.get_type() == BackendType::Asdf) .collect() } @@ -51,7 +51,7 @@ pub fn list2() -> eyre::Result { Ok(core.chain(asdf).collect()) } -pub fn list_external() -> ForgeList { +pub fn list_external() -> BackendList { list() .into_iter() .filter(|tool| tool.get_plugin_type() == PluginType::Asdf) @@ -102,8 +102,8 @@ mod tests { use pretty_assertions::assert_str_eq; use test_log::test; - use crate::forge::asdf::Asdf; - use crate::forge::Forge; + use crate::backend::asdf::Asdf; + use crate::backend::Backend; use crate::test::reset; #[test] diff --git a/src/runtime_symlinks.rs b/src/runtime_symlinks.rs index ea71fe259..fc2e21bb4 100644 --- a/src/runtime_symlinks.rs +++ b/src/runtime_symlinks.rs @@ -7,16 +7,16 @@ use indexmap::IndexMap; use itertools::Itertools; use versions::Versioning; +use crate::backend::{backend_meta, Backend}; use crate::config::Config; use crate::file::make_symlink; -use crate::forge::{forge_meta, Forge}; use crate::plugins::VERSION_REGEX; -use crate::{file, forge}; +use crate::{backend, file}; pub fn rebuild(config: &Config) -> Result<()> { - for forge in forge::list() { - let symlinks = list_symlinks(config, forge.clone())?; - let installs_dir = &forge.fa().installs_path; + for backend in backend::list() { + let symlinks = list_symlinks(config, backend.clone())?; + let installs_dir = &backend.fa().installs_path; for (from, to) in symlinks { let from = installs_dir.join(from); if from.exists() { @@ -29,21 +29,21 @@ pub fn rebuild(config: &Config) -> Result<()> { } make_symlink(&to, &from)?; } - remove_missing_symlinks(forge.clone())?; + remove_missing_symlinks(backend.clone())?; // remove install dir if empty (ignore metadata) file::remove_dir_ignore( installs_dir, - vec![forge_meta::FORGE_META_FILENAME.to_string()], + vec![backend_meta::FORGE_META_FILENAME.to_string()], )?; } Ok(()) } -fn list_symlinks(config: &Config, forge: Arc) -> Result> { +fn list_symlinks(config: &Config, backend: Arc) -> Result> { // TODO: make this a pure function and add test cases let mut symlinks = IndexMap::new(); let rel_path = |x: &String| PathBuf::from(".").join(x.clone()); - for v in installed_versions(&forge)? { + for v in installed_versions(&backend)? { let prefix = regex!(r"^[a-zA-Z0-9]+-") .find(&v) .map(|s| s.as_str().to_string()) @@ -60,7 +60,7 @@ fn list_symlinks(config: &Config, forge: Arc) -> Result) -> Result) -> Result> { - let versions = forge +fn installed_versions(backend: &Arc) -> Result> { + let versions = backend .list_installed_versions()? .into_iter() .filter(|v| !VERSION_REGEX.is_match(v)) @@ -88,8 +88,8 @@ fn installed_versions(forge: &Arc) -> Result> { Ok(versions) } -fn remove_missing_symlinks(forge: Arc) -> Result<()> { - let installs_dir = &forge.fa().installs_path; +fn remove_missing_symlinks(backend: Arc) -> Result<()> { + let installs_dir = &backend.fa().installs_path; if !installs_dir.exists() { return Ok(()); } @@ -113,7 +113,7 @@ pub fn is_runtime_symlink(path: &Path) -> bool { #[cfg(test)] mod tests { - use crate::forge::asdf::Asdf; + use crate::backend::asdf::Asdf; use insta::assert_debug_snapshot; use crate::test::reset; diff --git a/src/shims.rs b/src/shims.rs index 4d1674b73..6b3935e5d 100644 --- a/src/shims.rs +++ b/src/shims.rs @@ -11,13 +11,13 @@ use indoc::formatdoc; use itertools::Itertools; use rayon::prelude::*; +use crate::backend::Backend; use crate::cli::exec::Exec; use crate::config::{Config, Settings}; use crate::file::{create_dir_all, display_path, remove_all}; -use crate::forge::Forge; use crate::lock_file::LockFile; use crate::toolset::{ToolVersion, Toolset, ToolsetBuilder}; -use crate::{dirs, env, fake_asdf, file, forge, logger}; +use crate::{backend, dirs, env, fake_asdf, file, logger}; // executes as if it was a shim if the command is not "mise", e.g.: "node" pub fn handle_shim() -> Result<()> { @@ -58,7 +58,7 @@ fn which_shim(bin_name: &str) -> Result { let settings = Settings::try_get()?; if settings.not_found_auto_install { for tv in ts.install_missing_bin(bin_name)?.unwrap_or_default() { - let p = tv.get_forge(); + let p = tv.get_backend(); if let Some(bin) = p.which(&tv, bin_name)? { trace!( "shim[{bin_name}] NOT_FOUND ToolVersion: {tv} bin: {bin}", @@ -112,7 +112,7 @@ pub fn reshim(ts: &Toolset) -> Result<()> { let symlink_path = dirs::SHIMS.join(shim); remove_all(&symlink_path)?; } - for plugin in forge::list() { + for plugin in backend::list() { match dirs::PLUGINS.join(plugin.id()).join("shims").read_dir() { Ok(files) => { for bin in files { @@ -204,7 +204,7 @@ fn get_desired_shims(toolset: &Toolset) -> Result> { } // lists all the paths to bins in a tv that shims will be needed for -fn list_tool_bins(t: Arc, tv: &ToolVersion) -> Result> { +fn list_tool_bins(t: Arc, tv: &ToolVersion) -> Result> { Ok(t.list_bin_paths(tv)? .into_iter() .par_bridge() @@ -245,17 +245,17 @@ fn err_no_version_set(ts: Toolset, bin_name: &str, tvs: Vec) -> Res if tvs.is_empty() { bail!("{} is not a valid shim", bin_name); } - let missing_plugins = tvs.iter().map(|tv| &tv.forge).collect::>(); + let missing_plugins = tvs.iter().map(|tv| &tv.backend).collect::>(); let mut missing_tools = ts .list_missing_versions() .into_iter() - .filter(|t| missing_plugins.contains(&t.forge)) + .filter(|t| missing_plugins.contains(&t.backend)) .collect_vec(); if missing_tools.is_empty() { let mut msg = format!("No version is set for shim: {}\n", bin_name); msg.push_str("Set a global default version with one of the following:\n"); for tv in tvs { - msg.push_str(&format!("mise use -g {}@{}\n", tv.forge, tv.version)); + msg.push_str(&format!("mise use -g {}@{}\n", tv.backend, tv.version)); } Err(eyre!(msg.trim().to_string())) } else { diff --git a/src/test.rs b/src/test.rs index 7a04a8e6c..6ccf80217 100644 --- a/src/test.rs +++ b/src/test.rs @@ -7,7 +7,7 @@ use indoc::indoc; use crate::cli::Cli; use crate::config::{config_file, Config}; use crate::output::tests::{STDERR, STDOUT}; -use crate::{cmd, dirs, env, file, forge}; +use crate::{backend, cmd, dirs, env, file}; #[macro_export] macro_rules! assert_cli_snapshot { @@ -74,7 +74,7 @@ fn init() { pub fn reset() { Config::reset(); - forge::reset(); + backend::reset(); config_file::reset(); file::remove_all(&*env::HOME.join("cwd")).unwrap(); file::create_dir_all(&*env::HOME.join("cwd")).unwrap(); @@ -191,7 +191,7 @@ pub fn replace_path(input: &str) -> String { pub fn cli_run(args: &Vec) -> eyre::Result<(String, String)> { Config::reset(); - forge::reset(); + backend::reset(); config_file::reset(); env::ARGS.write().unwrap().clone_from(args); STDOUT.lock().unwrap().clear(); diff --git a/src/toolset/builder.rs b/src/toolset/builder.rs index 42ac5af01..41715056c 100644 --- a/src/toolset/builder.rs +++ b/src/toolset/builder.rs @@ -3,7 +3,7 @@ use std::collections::BTreeMap; use eyre::Result; use itertools::Itertools; -use crate::cli::args::{ForgeArg, ToolArg}; +use crate::cli::args::{BackendArg, ToolArg}; use crate::config::Config; use crate::env; use crate::errors::Error; @@ -71,7 +71,7 @@ impl ToolsetBuilder { // ignore MISE_INSTALL_VERSION continue; } - let fa: ForgeArg = plugin_name.as_str().into(); + let fa: BackendArg = plugin_name.as_str().into(); let source = ToolSource::Environment(k, v.clone()); let mut env_ts = Toolset::new(source); for v in v.split_whitespace() { @@ -85,7 +85,11 @@ impl ToolsetBuilder { } fn load_runtime_args(&self, ts: &mut Toolset) -> eyre::Result<()> { - for (_, args) in self.args.iter().into_group_map_by(|arg| arg.forge.clone()) { + for (_, args) in self + .args + .iter() + .into_group_map_by(|arg| arg.backend.clone()) + { let mut arg_ts = Toolset::new(ToolSource::Argument); for arg in args { if let Some(tvr) = &arg.tvr { @@ -99,11 +103,11 @@ impl ToolsetBuilder { let set_as_latest = !ts .list_current_requests() .iter() - .any(|tvr| tvr.forge() == &arg.forge); + .any(|tvr| tvr.backend() == &arg.backend); if set_as_latest { // no active version, so use "latest" - arg_ts.add_version(ToolRequest::new(arg.forge.clone(), "latest")?); + arg_ts.add_version(ToolRequest::new(arg.backend.clone(), "latest")?); } } } diff --git a/src/toolset/mod.rs b/src/toolset/mod.rs index eaacba0d5..c4699508b 100644 --- a/src/toolset/mod.rs +++ b/src/toolset/mod.rs @@ -19,16 +19,16 @@ pub use tool_version::ToolVersion; pub use tool_version_list::ToolVersionList; pub use tool_version_request::ToolRequest; -use crate::cli::args::ForgeArg; +use crate::backend::Backend; +use crate::cli::args::BackendArg; use crate::config::settings::SettingsStatusMissingTools; use crate::config::{Config, Settings}; use crate::env::TERM_WIDTH; use crate::errors::Error; -use crate::forge::Forge; use crate::install_context::InstallContext; use crate::path_env::PathEnv; use crate::ui::multi_progress_report::MultiProgressReport; -use crate::{env, forge, runtime_symlinks, shims}; +use crate::{backend, env, runtime_symlinks, shims}; mod builder; mod tool_request_set; @@ -65,7 +65,7 @@ impl InstallOptions { /// merge in other toolsets from various sources #[derive(Debug, Default, Clone)] pub struct Toolset { - pub versions: IndexMap, + pub versions: IndexMap, pub source: Option, } @@ -77,13 +77,13 @@ impl Toolset { } } pub fn add_version(&mut self, tvr: ToolRequest) { - let fa = tvr.forge(); + let fa = tvr.backend(); if self.is_disabled(fa) { return; } let tvl = self .versions - .entry(tvr.forge().clone()) + .entry(tvr.backend().clone()) .or_insert_with(|| ToolVersionList::new(fa.clone(), self.source.clone().unwrap())); tvl.requests.push(tvr); } @@ -94,7 +94,7 @@ impl Toolset { versions.insert(plugin, tvl); } } - versions.retain(|_, tvl| !self.is_disabled(&tvl.forge)); + versions.retain(|_, tvl| !self.is_disabled(&tvl.backend)); self.versions = versions; self.source = other.source; } @@ -128,7 +128,7 @@ impl Toolset { .into_iter() .filter(|(p, tv)| opts.force || !p.is_version_installed(tv)) .map(|(_, tv)| tv) - .filter(|tv| matches!(self.versions[&tv.forge].source, ToolSource::Argument)) + .filter(|tv| matches!(self.versions[&tv.backend].source, ToolSource::Argument)) .map(|tv| tv.request) .collect_vec(); self.install_versions(config, versions, &mpr, opts) @@ -137,7 +137,7 @@ impl Toolset { pub fn list_missing_plugins(&self) -> Vec { self.versions .keys() - .map(forge::get) + .map(backend::get) .filter(|p| !p.is_installed()) .map(|p| p.id().into()) .collect() @@ -163,9 +163,9 @@ impl Toolset { let queue: Vec<_> = versions .into_iter() .rev() - .group_by(|v| v.forge().clone()) + .group_by(|v| v.backend().clone()) .into_iter() - .map(|(fa, v)| (forge::get(&fa), v.collect_vec())) + .map(|(fa, v)| (backend::get(&fa), v.collect_vec())) .collect(); for (t, _) in &queue { if !t.is_installed() { @@ -250,13 +250,13 @@ impl Toolset { .map(|(_, tv)| tv) .collect() } - pub fn list_installed_versions(&self) -> Result, ToolVersion)>> { - let current_versions: HashMap<(String, String), (Arc, ToolVersion)> = self + pub fn list_installed_versions(&self) -> Result, ToolVersion)>> { + let current_versions: HashMap<(String, String), (Arc, ToolVersion)> = self .list_current_versions() .into_iter() .map(|(p, tv)| ((p.id().into(), tv.version.clone()), (p.clone(), tv))) .collect(); - let versions = forge::list() + let versions = backend::list() .into_par_iter() .map(|p| { let versions = p.list_installed_versions()?; @@ -282,7 +282,7 @@ impl Toolset { Ok(versions) } - pub fn list_plugins(&self) -> Vec> { + pub fn list_plugins(&self) -> Vec> { self.list_versions_by_plugin() .into_iter() .map(|(p, _)| p) @@ -294,25 +294,25 @@ impl Toolset { .flat_map(|tvl| &tvl.requests) .collect() } - pub fn list_versions_by_plugin(&self) -> Vec<(Arc, &Vec)> { + pub fn list_versions_by_plugin(&self) -> Vec<(Arc, &Vec)> { self.versions .iter() - .map(|(p, v)| (forge::get(p), &v.versions)) + .map(|(p, v)| (backend::get(p), &v.versions)) .collect() } - pub fn list_current_versions(&self) -> Vec<(Arc, ToolVersion)> { + pub fn list_current_versions(&self) -> Vec<(Arc, ToolVersion)> { self.list_versions_by_plugin() .iter() .flat_map(|(p, v)| v.iter().map(|v| (p.clone(), v.clone()))) .collect() } - pub fn list_current_installed_versions(&self) -> Vec<(Arc, ToolVersion)> { + pub fn list_current_installed_versions(&self) -> Vec<(Arc, ToolVersion)> { self.list_current_versions() .into_iter() .filter(|(p, v)| p.is_version_installed(v)) .collect() } - pub fn list_outdated_versions(&self) -> Vec<(Arc, ToolVersion, String)> { + pub fn list_outdated_versions(&self) -> Vec<(Arc, ToolVersion, String)> { self.list_current_versions() .into_iter() .filter_map(|(t, tv)| { @@ -402,7 +402,7 @@ impl Toolset { }) .collect() } - pub fn which(&self, bin_name: &str) -> Option<(Arc, ToolVersion)> { + pub fn which(&self, bin_name: &str) -> Option<(Arc, ToolVersion)> { self.list_current_installed_versions() .into_par_iter() .find_first(|(p, tv)| { @@ -430,7 +430,7 @@ impl Toolset { let versions = self .list_missing_versions() .into_iter() - .filter(|tv| &tv.forge == plugin.fa()) + .filter(|tv| &tv.backend == plugin.fa()) .map(|tv| tv.request) .collect_vec(); if !versions.is_empty() { @@ -469,7 +469,7 @@ impl Toolset { SettingsStatusMissingTools::Never => false, SettingsStatusMissingTools::Always => true, SettingsStatusMissingTools::IfOtherVersionsInstalled => tv - .get_forge() + .get_backend() .list_installed_versions() .is_ok_and(|f| !f.is_empty()), }) @@ -488,7 +488,7 @@ impl Toolset { ); } - fn is_disabled(&self, fa: &ForgeArg) -> bool { + fn is_disabled(&self, fa: &BackendArg) -> bool { let settings = Settings::get(); let fa = fa.to_string(); settings.disable_tools.iter().any(|s| s == &fa) @@ -522,7 +522,10 @@ impl From for Toolset { } fn get_leaf_dependencies(requests: &[ToolRequest]) -> eyre::Result> { - let versions_hash = requests.iter().map(|tr| tr.forge()).collect::>(); + let versions_hash = requests + .iter() + .map(|tr| tr.backend()) + .collect::>(); let leaves = requests .iter() .map(|tr| { diff --git a/src/toolset/tool_request_set.rs b/src/toolset/tool_request_set.rs index a92fbef3a..12957fb44 100644 --- a/src/toolset/tool_request_set.rs +++ b/src/toolset/tool_request_set.rs @@ -4,15 +4,15 @@ use std::fmt::{Debug, Display}; use indexmap::IndexMap; use itertools::Itertools; -use crate::cli::args::{ForgeArg, ToolArg}; +use crate::cli::args::{BackendArg, ToolArg}; use crate::config::{Config, Settings}; use crate::env; use crate::toolset::{ToolRequest, ToolSource}; #[derive(Debug, Default, Clone)] pub struct ToolRequestSet { - pub tools: IndexMap>, - pub sources: BTreeMap, + pub tools: IndexMap>, + pub sources: BTreeMap, } impl ToolRequestSet { @@ -20,10 +20,10 @@ impl ToolRequestSet { Self::default() } - // pub fn tools_with_sources(&self) -> Vec<(&ForgeArg, &Vec, &ToolSource)> { + // pub fn tools_with_sources(&self) -> Vec<(&BackendArg, &Vec, &ToolSource)> { // self.tools // .iter() - // .map(|(forge, tvr)| (forge, tvr, self.sources.get(forge).unwrap())) + // .map(|(backend, tvr)| (backend, tvr, self.sources.get(backend).unwrap())) // .collect() // } @@ -47,11 +47,11 @@ impl ToolRequestSet { .collect() } - pub fn list_plugins(&self) -> Vec<&ForgeArg> { + pub fn list_plugins(&self) -> Vec<&BackendArg> { self.tools.keys().collect() } - pub fn list_current_versions(&self) -> Vec<(&ForgeArg, &ToolRequest)> { + pub fn list_current_versions(&self) -> Vec<(&BackendArg, &ToolRequest)> { self.tools .iter() .map(|(fa, tvr)| (fa, tvr.last().unwrap())) @@ -59,28 +59,28 @@ impl ToolRequestSet { } pub fn add_version(&mut self, tr: ToolRequest, source: &ToolSource) { - let fa = tr.forge(); + let fa = tr.backend(); if !self.tools.contains_key(fa) { self.sources.insert(fa.clone(), source.clone()); } - let list = self.tools.entry(tr.forge().clone()).or_default(); + let list = self.tools.entry(tr.backend().clone()).or_default(); list.push(tr); } - pub fn iter(&self) -> impl Iterator, &ToolSource)> { + pub fn iter(&self) -> impl Iterator, &ToolSource)> { self.tools .iter() - .map(|(forge, tvr)| (forge, tvr, self.sources.get(forge).unwrap())) + .map(|(backend, tvr)| (backend, tvr, self.sources.get(backend).unwrap())) } - pub fn into_iter(self) -> impl Iterator, ToolSource)> { + pub fn into_iter(self) -> impl Iterator, ToolSource)> { self.tools.into_iter().map(move |(fa, tvr)| { let source = self.sources.get(&fa).unwrap().clone(); (fa, tvr, source) }) } - pub fn filter_by_tool(&self, tools: &HashSet) -> Self { + pub fn filter_by_tool(&self, tools: &HashSet) -> Self { self.iter() .filter(|(fa, ..)| tools.contains(fa)) .map(|(fa, trl, ts)| (fa.clone(), trl.clone(), ts.clone())) @@ -96,10 +96,10 @@ impl Display for ToolRequestSet { } } -impl FromIterator<(ForgeArg, Vec, ToolSource)> for ToolRequestSet { +impl FromIterator<(BackendArg, Vec, ToolSource)> for ToolRequestSet { fn from_iter(iter: T) -> Self where - T: IntoIterator, ToolSource)>, + T: IntoIterator, ToolSource)>, { let mut trs = ToolRequestSet::new(); for (_fa, tvr, source) in iter { @@ -118,7 +118,7 @@ pub struct ToolRequestSetBuilder { /// default to latest version if no version is specified (for `mise x`) default_to_latest: bool, /// tools which will be disabled - disable_tools: Vec, + disable_tools: Vec, } impl ToolRequestSetBuilder { @@ -148,8 +148,8 @@ impl ToolRequestSetBuilder { self.load_runtime_env(&mut trs)?; self.load_runtime_args(&mut trs)?; - let forges = trs.tools.keys().cloned().collect::>(); - for fa in &forges { + let backends = trs.tools.keys().cloned().collect::>(); + for fa in &backends { if self.is_disabled(fa) { trs.tools.swap_remove(fa); trs.sources.remove(fa); @@ -160,7 +160,7 @@ impl ToolRequestSetBuilder { Ok(trs) } - fn is_disabled(&self, fa: &ForgeArg) -> bool { + fn is_disabled(&self, fa: &BackendArg) -> bool { self.disable_tools.contains(fa) } @@ -183,7 +183,7 @@ impl ToolRequestSetBuilder { // ignore MISE_INSTALL_VERSION continue; } - let fa: ForgeArg = plugin_name.as_str().into(); + let fa: BackendArg = plugin_name.as_str().into(); let source = ToolSource::Environment(k, v.clone()); let mut env_ts = ToolRequestSet::new(); for v in v.split_whitespace() { @@ -197,7 +197,11 @@ impl ToolRequestSetBuilder { } fn load_runtime_args(&self, trs: &mut ToolRequestSet) -> eyre::Result<()> { - for (_, args) in self.args.iter().into_group_map_by(|arg| arg.forge.clone()) { + for (_, args) in self + .args + .iter() + .into_group_map_by(|arg| arg.backend.clone()) + { let mut arg_ts = ToolRequestSet::new(); for arg in args { if let Some(tvr) = &arg.tvr { @@ -207,9 +211,9 @@ impl ToolRequestSetBuilder { // should default to installing the "latest" version if no version is specified // in .mise.toml - if !trs.tools.contains_key(&arg.forge) { + if !trs.tools.contains_key(&arg.backend) { // no active version, so use "latest" - let tr = ToolRequest::new(arg.forge.clone(), "latest")?; + let tr = ToolRequest::new(arg.backend.clone(), "latest")?; arg_ts.add_version(tr, &ToolSource::Argument); } } diff --git a/src/toolset/tool_version.rs b/src/toolset/tool_version.rs index 2507efcb3..4979e20b1 100644 --- a/src/toolset/tool_version.rs +++ b/src/toolset/tool_version.rs @@ -7,10 +7,10 @@ use std::path::PathBuf; use console::style; use eyre::Result; -use crate::cli::args::ForgeArg; +use crate::backend; +use crate::backend::{ABackend, Backend}; +use crate::cli::args::BackendArg; use crate::config::Config; -use crate::forge; -use crate::forge::{AForge, Forge}; use crate::hash::hash_to_str; use crate::toolset::{tool_version_request, ToolRequest, ToolVersionOptions}; @@ -18,20 +18,24 @@ use crate::toolset::{tool_version_request, ToolRequest, ToolVersionOptions}; #[derive(Debug, Clone)] pub struct ToolVersion { pub request: ToolRequest, - pub forge: ForgeArg, + pub backend: BackendArg, pub version: String, } impl ToolVersion { - pub fn new(tool: &dyn Forge, request: ToolRequest, version: String) -> Self { + pub fn new(tool: &dyn Backend, request: ToolRequest, version: String) -> Self { ToolVersion { - forge: tool.fa().clone(), + backend: tool.fa().clone(), version, request, } } - pub fn resolve(tool: &dyn Forge, request: ToolRequest, latest_versions: bool) -> Result { + pub fn resolve( + tool: &dyn Backend, + request: ToolRequest, + latest_versions: bool, + ) -> Result { if !tool.is_installed() { let tv = Self::new(tool, request.clone(), request.version()); return Ok(tv); @@ -52,8 +56,8 @@ impl ToolVersion { Ok(tv) } - pub fn get_forge(&self) -> AForge { - forge::get(&self.forge) + pub fn get_backend(&self) -> ABackend { + backend::get(&self.backend) } pub fn install_path(&self) -> PathBuf { @@ -61,14 +65,14 @@ impl ToolVersion { ToolRequest::Path(_, p) => p.to_string_lossy().to_string(), _ => self.tv_pathname(), }; - self.forge.installs_path.join(pathname) + self.backend.installs_path.join(pathname) } pub fn install_short_path(&self) -> PathBuf { let pathname = match &self.request { ToolRequest::Path(_, p) => p.to_string_lossy().to_string(), _ => self.tv_short_pathname(), }; - let sp = self.forge.installs_path.join(pathname); + let sp = self.backend.installs_path.join(pathname); if sp.exists() { sp } else { @@ -76,19 +80,19 @@ impl ToolVersion { } } pub fn cache_path(&self) -> PathBuf { - self.forge.cache_path.join(self.tv_pathname()) + self.backend.cache_path.join(self.tv_pathname()) } pub fn download_path(&self) -> PathBuf { - self.forge.downloads_path.join(self.tv_pathname()) + self.backend.downloads_path.join(self.tv_pathname()) } - pub fn latest_version(&self, tool: &dyn Forge) -> Result { + pub fn latest_version(&self, tool: &dyn Backend) -> Result { let tv = self.request.resolve(tool, true)?; Ok(tv.version) } pub fn style(&self) -> String { format!( "{}{}", - style(&self.forge.id).blue().for_stderr(), + style(&self.backend.id).blue().for_stderr(), style(&format!("@{}", &self.version)).for_stderr() ) } @@ -112,7 +116,7 @@ impl ToolVersion { } fn resolve_version( - tool: &dyn Forge, + tool: &dyn Backend, request: ToolRequest, latest_versions: bool, v: &str, @@ -175,7 +179,7 @@ impl ToolVersion { /// resolve a version like `sub-1:12.0.0` which becomes `11.0.0`, `sub-0.1:12.1.0` becomes `12.0.0` fn resolve_sub( - tool: &dyn Forge, + tool: &dyn Backend, request: ToolRequest, latest_versions: bool, sub: &str, @@ -189,7 +193,7 @@ impl ToolVersion { Self::resolve_version(tool, request, latest_versions, &v) } - fn resolve_prefix(tool: &dyn Forge, request: ToolRequest, prefix: &str) -> Result { + fn resolve_prefix(tool: &dyn Backend, request: ToolRequest, prefix: &str) -> Result { let matches = tool.list_versions_matching(prefix)?; let v = match matches.last() { Some(v) => v, @@ -199,9 +203,9 @@ impl ToolVersion { Ok(Self::new(tool, request, v.to_string())) } - fn resolve_ref(tool: &dyn Forge, ref_: String, opts: ToolVersionOptions) -> Self { + fn resolve_ref(tool: &dyn Backend, ref_: String, opts: ToolVersionOptions) -> Self { let request = ToolRequest::Ref { - forge: tool.fa().clone(), + backend: tool.fa().clone(), ref_, options: opts.clone(), }; @@ -209,7 +213,7 @@ impl ToolVersion { Self::new(tool, request, version) } - fn resolve_path(tool: &dyn Forge, path: PathBuf) -> Result { + fn resolve_path(tool: &dyn Backend, path: PathBuf) -> Result { let path = fs::canonicalize(path)?; let request = ToolRequest::Path(tool.fa().clone(), path); let version = request.version(); @@ -219,13 +223,13 @@ impl ToolVersion { impl Display for ToolVersion { fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result { - write!(f, "{}@{}", &self.forge.id, &self.version) + write!(f, "{}@{}", &self.backend.id, &self.version) } } impl PartialEq for ToolVersion { fn eq(&self, other: &Self) -> bool { - self.forge.id == other.forge.id && self.version == other.version + self.backend.id == other.backend.id && self.version == other.version } } @@ -239,7 +243,7 @@ impl PartialOrd for ToolVersion { impl Ord for ToolVersion { fn cmp(&self, other: &Self) -> Ordering { - match self.forge.id.cmp(&other.forge.id) { + match self.backend.id.cmp(&other.backend.id) { Ordering::Equal => self.version.cmp(&other.version), o => o, } @@ -248,7 +252,7 @@ impl Ord for ToolVersion { impl Hash for ToolVersion { fn hash(&self, state: &mut H) { - self.forge.id.hash(state); + self.backend.id.hash(state); self.version.hash(state); } } diff --git a/src/toolset/tool_version_list.rs b/src/toolset/tool_version_list.rs index 4dac642b9..78b44c230 100644 --- a/src/toolset/tool_version_list.rs +++ b/src/toolset/tool_version_list.rs @@ -1,22 +1,22 @@ -use crate::cli::args::ForgeArg; +use crate::backend; +use crate::cli::args::BackendArg; use crate::errors::Error; -use crate::forge; use crate::toolset::tool_version_request::ToolRequest; use crate::toolset::{ToolSource, ToolVersion}; /// represents several versions of a tool for a particular plugin #[derive(Debug, Clone)] pub struct ToolVersionList { - pub forge: ForgeArg, + pub backend: BackendArg, pub versions: Vec, pub requests: Vec, pub source: ToolSource, } impl ToolVersionList { - pub fn new(forge: ForgeArg, source: ToolSource) -> Self { + pub fn new(backend: BackendArg, source: ToolSource) -> Self { Self { - forge, + backend, versions: Vec::new(), requests: vec![], source, @@ -24,7 +24,7 @@ impl ToolVersionList { } pub fn resolve(&mut self, latest_versions: bool) -> eyre::Result<()> { self.versions.clear(); - let plugin = forge::get(&self.forge); + let plugin = backend::get(&self.backend); for tvr in &mut self.requests { match tvr.resolve(plugin.as_ref(), latest_versions) { Ok(v) => self.versions.push(v), @@ -54,7 +54,7 @@ mod tests { #[test] fn test_tool_version_list() { reset(); - let fa: ForgeArg = "tiny".into(); + let fa: BackendArg = "tiny".into(); let mut tvl = ToolVersionList::new(fa.clone(), ToolSource::Argument); tvl.requests.push(ToolRequest::new(fa, "latest").unwrap()); tvl.resolve(true).unwrap(); @@ -64,10 +64,10 @@ mod tests { #[test] fn test_tool_version_list_failure() { reset(); - forge::reset(); + backend::reset(); env::set_var("MISE_FAILURE", "1"); file::remove_all(dirs::CACHE.join("dummy")).unwrap(); - let fa: ForgeArg = "dummy".into(); + let fa: BackendArg = "dummy".into(); let mut tvl = ToolVersionList::new(fa.clone(), ToolSource::Argument); tvl.requests.push(ToolRequest::new(fa, "latest").unwrap()); let _ = tvl.resolve(true); diff --git a/src/toolset/tool_version_request.rs b/src/toolset/tool_version_request.rs index 43ef7e8d8..d7584629f 100644 --- a/src/toolset/tool_version_request.rs +++ b/src/toolset/tool_version_request.rs @@ -5,66 +5,66 @@ use eyre::{bail, Result}; use versions::{Chunk, Version}; use xx::file; -use crate::cli::args::ForgeArg; -use crate::forge; -use crate::forge::Forge; +use crate::backend; +use crate::backend::Backend; +use crate::cli::args::BackendArg; use crate::toolset::{ToolVersion, ToolVersionOptions}; #[derive(Debug, Clone, Hash, PartialEq, Eq)] pub enum ToolRequest { Version { - forge: ForgeArg, + backend: BackendArg, version: String, options: ToolVersionOptions, }, Prefix { - forge: ForgeArg, + backend: BackendArg, prefix: String, options: ToolVersionOptions, }, Ref { - forge: ForgeArg, + backend: BackendArg, ref_: String, options: ToolVersionOptions, }, Sub { - forge: ForgeArg, + backend: BackendArg, sub: String, orig_version: String, }, - Path(ForgeArg, PathBuf), - System(ForgeArg), + Path(BackendArg, PathBuf), + System(BackendArg), } impl ToolRequest { - pub fn new(forge: ForgeArg, s: &str) -> eyre::Result { + pub fn new(backend: BackendArg, s: &str) -> eyre::Result { let s = match s.split_once('-') { Some(("ref", r)) => format!("ref:{}", r), _ => s.to_string(), }; Ok(match s.split_once(':') { Some(("ref", r)) => Self::Ref { - forge, + backend, ref_: r.to_string(), options: Default::default(), }, Some(("prefix", p)) => Self::Prefix { - forge, + backend, prefix: p.to_string(), options: Default::default(), }, - Some(("path", p)) => Self::Path(forge, PathBuf::from(p)), + Some(("path", p)) => Self::Path(backend, PathBuf::from(p)), Some((p, v)) if p.starts_with("sub-") => Self::Sub { - forge, + backend, sub: p.split_once('-').unwrap().1.to_string(), orig_version: v.to_string(), }, None => { if s == "system" { - Self::System(forge) + Self::System(backend) } else { Self::Version { - forge, + backend, version: s, options: Default::default(), } @@ -73,8 +73,12 @@ impl ToolRequest { _ => bail!("invalid tool version request: {s}"), }) } - pub fn new_opts(forge: ForgeArg, s: &str, options: ToolVersionOptions) -> eyre::Result { - let mut tvr = Self::new(forge, s)?; + pub fn new_opts( + backend: BackendArg, + s: &str, + options: ToolVersionOptions, + ) -> eyre::Result { + let mut tvr = Self::new(backend, s)?; match &mut tvr { Self::Version { options: o, .. } | Self::Prefix { options: o, .. } @@ -83,19 +87,19 @@ impl ToolRequest { } Ok(tvr) } - pub fn forge(&self) -> &ForgeArg { + pub fn backend(&self) -> &BackendArg { match self { - Self::Version { forge: f, .. } - | Self::Prefix { forge: f, .. } - | Self::Ref { forge: f, .. } + Self::Version { backend: f, .. } + | Self::Prefix { backend: f, .. } + | Self::Ref { backend: f, .. } | Self::Path(f, _) - | Self::Sub { forge: f, .. } + | Self::Sub { backend: f, .. } | Self::System(f) => f, } } - pub fn dependencies(&self) -> eyre::Result> { - let forge = forge::get(self.forge()); - forge.get_all_dependencies(self) + pub fn dependencies(&self) -> eyre::Result> { + let backend = backend::get(self.backend()); + backend.get_all_dependencies(self) } pub fn version(&self) -> String { match self { @@ -120,7 +124,7 @@ impl ToolRequest { } pub fn is_installed(&self) -> bool { - // TODO: dispatch to forge + // TODO: dispatch to backend match self { Self::System(_) => true, _ => self.install_path().is_some_and(|p| p.exists()), @@ -129,20 +133,24 @@ impl ToolRequest { pub fn install_path(&self) -> Option { match self { - Self::Version { forge, version, .. } => Some(forge.installs_path.join(version)), - Self::Ref { forge, ref_, .. } => { - Some(forge.installs_path.join(format!("ref-{}", ref_))) + Self::Version { + backend, version, .. + } => Some(backend.installs_path.join(version)), + Self::Ref { backend, ref_, .. } => { + Some(backend.installs_path.join(format!("ref-{}", ref_))) } Self::Sub { - forge, + backend, sub, orig_version, } => self .local_resolve(orig_version) .inspect_err(|e| warn!("ToolRequest.local_resolve: {e:#}")) .unwrap_or_default() - .map(|v| forge.installs_path.join(version_sub(&v, sub.as_str()))), - Self::Prefix { forge, prefix, .. } => match file::ls(&forge.installs_path) { + .map(|v| backend.installs_path.join(version_sub(&v, sub.as_str()))), + Self::Prefix { + backend, prefix, .. + } => match file::ls(&backend.installs_path) { Ok(installs) => installs .iter() .find(|p| p.file_name().unwrap().to_string_lossy().starts_with(prefix)) @@ -155,8 +163,8 @@ impl ToolRequest { } pub fn local_resolve(&self, v: &str) -> eyre::Result> { - let forge = forge::get(self.forge()); - let matches = forge.list_installed_versions_matching(v)?; + let backend = backend::get(self.backend()); + let matches = backend.list_installed_versions_matching(v)?; if matches.iter().any(|m| m == v) { return Ok(Some(v.to_string())); } @@ -166,7 +174,7 @@ impl ToolRequest { Ok(None) } - pub fn resolve(&self, plugin: &dyn Forge, latest_versions: bool) -> Result { + pub fn resolve(&self, plugin: &dyn Backend, latest_versions: bool) -> Result { ToolVersion::resolve(plugin, self.clone(), latest_versions) } } @@ -189,7 +197,7 @@ pub fn version_sub(orig: &str, sub: &str) -> String { impl Display for ToolRequest { fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result { - write!(f, "{}@{}", &self.forge(), self.version()) + write!(f, "{}@{}", &self.backend(), self.version()) } } diff --git a/src/ui/progress_report.rs b/src/ui/progress_report.rs index d5722049c..975891047 100644 --- a/src/ui/progress_report.rs +++ b/src/ui/progress_report.rs @@ -4,7 +4,7 @@ use indicatif::{ProgressBar, ProgressStyle}; use once_cell::sync::Lazy; use crate::ui::style; -use crate::{env, forge, ui}; +use crate::{backend, env, ui}; pub trait SingleReport: Send + Sync { fn println(&self, _message: String) {} @@ -46,7 +46,7 @@ pub struct ProgressReport { } static LONGEST_PLUGIN_NAME: Lazy = Lazy::new(|| { - forge::list() + backend::list() .into_iter() .map(|p| p.id().len()) .max() diff --git a/tests/cli/forge.rs b/tests/cli/backend.rs similarity index 100% rename from tests/cli/forge.rs rename to tests/cli/backend.rs diff --git a/tests/cli/mod.rs b/tests/cli/mod.rs index 4076b1600..d99f4f74d 100644 --- a/tests/cli/mod.rs +++ b/tests/cli/mod.rs @@ -29,9 +29,9 @@ mod env; #[cfg(test)] mod exec; -// Tests forges +// Tests backends #[cfg(test)] -mod forge; +mod backend; // Tests `mise global` #[cfg(test)]