Skip to content

Commit

Permalink
refactor: started the work to merge tool and plugin struct/traits
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed Dec 6, 2023
1 parent 98e504a commit 901c4be
Show file tree
Hide file tree
Showing 12 changed files with 314 additions and 313 deletions.
9 changes: 7 additions & 2 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,14 @@ fn load_tools(settings: &Settings) -> Result<ToolMap> {
if settings.experimental {
tools.extend(EXPERIMENTAL_CORE_PLUGINS.clone());
}
let plugins = Tool::list()?
let plugins = ExternalPlugin::list()?
.into_par_iter()
.map(|p| (p.name.clone(), Arc::new(p)))
.map(|p| {
(
p.name.clone(),
Arc::new(Tool::new(p.name.clone(), Box::new(p))),
)
})
.collect::<Vec<_>>();
tools.extend(plugins);
for tool in &settings.disable_tools {
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/core/bun.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ impl Plugin for BunPlugin {
Ok(vec![".bun-version".into()])
}

fn install_version(&self, ctx: &InstallContext) -> Result<()> {
fn install_version_impl(&self, ctx: &InstallContext) -> Result<()> {

Check warning on line 110 in src/plugins/core/bun.rs

View check run for this annotation

Codecov / codecov/patch

src/plugins/core/bun.rs#L110

Added line #L110 was not covered by tests
assert!(matches!(
&ctx.tv.request,
ToolVersionRequest::Version { .. }
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/core/deno.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl Plugin for DenoPlugin {
Ok(vec![".deno-version".into()])
}

fn install_version(&self, ctx: &InstallContext) -> Result<()> {
fn install_version_impl(&self, ctx: &InstallContext) -> Result<()> {
assert!(matches!(
&ctx.tv.request,
ToolVersionRequest::Version { .. }
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/core/go.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,15 @@ impl Plugin for GoPlugin {
Ok(vec![".go-version".into()])
}

fn install_version(&self, ctx: &InstallContext) -> Result<()> {
fn install_version_impl(&self, ctx: &InstallContext) -> Result<()> {

Check warning on line 152 in src/plugins/core/go.rs

View check run for this annotation

Codecov / codecov/patch

src/plugins/core/go.rs#L152

Added line #L152 was not covered by tests
let tarball_path = self.download(&ctx.tv, &ctx.pr)?;
self.install(&ctx.tv, &ctx.pr, &tarball_path)?;
self.verify(ctx.config, &ctx.tv, &ctx.pr)?;

Ok(())
}

fn uninstall_version(&self, _config: &Config, tv: &ToolVersion) -> Result<()> {
fn uninstall_version_impl(&self, _config: &Config, tv: &ToolVersion) -> Result<()> {

Check warning on line 160 in src/plugins/core/go.rs

View check run for this annotation

Codecov / codecov/patch

src/plugins/core/go.rs#L160

Added line #L160 was not covered by tests
let gopath = self.gopath(tv);
if gopath.exists() {
cmd!("chmod", "-R", "u+wx", gopath).run()?;
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/core/java.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ impl Plugin for JavaPlugin {
Ok(aliases)
}

fn install_version(&self, ctx: &InstallContext) -> Result<()> {
fn install_version_impl(&self, ctx: &InstallContext) -> Result<()> {
assert!(matches!(
&ctx.tv.request,
ToolVersionRequest::Version { .. }
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/core/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ impl Plugin for NodePlugin {
Ok(body.to_string())
}

fn install_version(&self, ctx: &InstallContext) -> Result<()> {
fn install_version_impl(&self, ctx: &InstallContext) -> Result<()> {
let opts = BuildOpts::new(ctx)?;
debug!("node build opts: {:#?}", opts);
if *env::RTX_NODE_COMPILE {
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/core/node_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ impl Plugin for NodeBuildPlugin {
exit(0);
}

fn install_version(&self, ctx: &InstallContext) -> Result<()> {
fn install_version_impl(&self, ctx: &InstallContext) -> Result<()> {
self.install_node_build()?;
ctx.pr.set_message("running node-build");
let mut cmd = CmdLineRunner::new(&ctx.config.settings, self.node_build_bin())
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/core/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ impl Plugin for PythonPlugin {
Ok(vec![".python-version".to_string()])
}

fn install_version(&self, ctx: &InstallContext) -> Result<()> {
fn install_version_impl(&self, ctx: &InstallContext) -> Result<()> {
self.install_python_build()?;
if matches!(&ctx.tv.request, ToolVersionRequest::Ref(..)) {
return Err(eyre!("Ref versions not supported for python"));
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/core/ruby.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ impl Plugin for RubyPlugin {
Ok(v)
}

fn install_version(&self, ctx: &InstallContext) -> Result<()> {
fn install_version_impl(&self, ctx: &InstallContext) -> Result<()> {

Check warning on line 349 in src/plugins/core/ruby.rs

View check run for this annotation

Codecov / codecov/patch

src/plugins/core/ruby.rs#L349

Added line #L349 was not covered by tests
self.update_build_tool()?;
assert!(matches!(
&ctx.tv.request,
Expand Down
13 changes: 10 additions & 3 deletions src/plugins/external_plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ impl ExternalPlugin {
}
}

pub fn list() -> Result<Vec<Self>> {
Ok(file::dir_subdirs(&dirs::PLUGINS)?
.into_iter()
.map(Self::new)
.collect())
}

fn get_repo_url(&self, config: &Config) -> Result<String> {
self.repo_url
.clone()
Expand Down Expand Up @@ -388,7 +395,7 @@ impl Plugin for ExternalPlugin {

fn latest_stable_version(&self, settings: &Settings) -> Result<Option<String>> {
if !self.has_latest_stable_script() {
return Ok(None);
return self.latest_version(settings, Some("latest".into()));
}
self.latest_stable_cache
.get_or_try_init(|| self.fetch_latest_stable(settings))
Expand Down Expand Up @@ -617,7 +624,7 @@ impl Plugin for ExternalPlugin {
exit(result.status.code().unwrap_or(1));
}

fn install_version(&self, ctx: &InstallContext) -> Result<()> {
fn install_version_impl(&self, ctx: &InstallContext) -> Result<()> {
let mut sm = self.script_man_for_tv(ctx.config, &ctx.tv);

for p in ctx.ts.list_paths(ctx.config) {
Expand All @@ -636,7 +643,7 @@ impl Plugin for ExternalPlugin {
Ok(())
}

fn uninstall_version(&self, config: &Config, tv: &ToolVersion) -> Result<()> {
fn uninstall_version_impl(&self, config: &Config, tv: &ToolVersion) -> Result<()> {
if self.plugin_path.join("bin/uninstall").exists() {
self.script_man_for_tv(config, tv)
.run(&config.settings, &Script::Uninstall)?;
Expand Down
Loading

0 comments on commit 901c4be

Please sign in to comment.