Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/vfox/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ path = "src/bin.rs"

[dependencies]
homedir = "0.3"
indexmap = "2"
indexmap = { version = "2", features = ["serde"] }
itertools = "0.14"
log = "0.4"
mlua = { version = "0.11", features = [
Expand Down
6 changes: 5 additions & 1 deletion crates/vfox/src/hooks/backend_exec_env.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
use mlua::{FromLua, IntoLua, Lua, Value, prelude::LuaError};
use indexmap::IndexMap;
use std::path::PathBuf;

use mlua::{FromLua, IntoLua, Lua, LuaSerdeExt, Value, prelude::LuaError};

use crate::{Plugin, error::Result, hooks::env_keys::EnvKey};

#[derive(Debug, Clone)]
pub struct BackendExecEnvContext {
pub tool: String,
pub version: String,
pub install_path: PathBuf,
pub options: IndexMap<String, String>,
}

#[derive(Debug)]
Expand Down Expand Up @@ -38,6 +41,7 @@ impl IntoLua for BackendExecEnvContext {
"install_path",
self.install_path.to_string_lossy().to_string(),
)?;
table.set("options", lua.to_value(&self.options)?)?;
Ok(Value::Table(table))
}
}
Expand Down
6 changes: 5 additions & 1 deletion crates/vfox/src/hooks/backend_install.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use mlua::{FromLua, IntoLua, Lua, Value, prelude::LuaError};
use indexmap::IndexMap;
use std::path::PathBuf;

use mlua::{FromLua, IntoLua, Lua, LuaSerdeExt, Value, prelude::LuaError};

use crate::{Plugin, error::Result};

#[derive(Debug)]
Expand All @@ -9,6 +11,7 @@ pub struct BackendInstallContext {
pub version: String,
pub install_path: PathBuf,
pub download_path: PathBuf,
pub options: IndexMap<String, String>,
}

#[derive(Debug)]
Expand Down Expand Up @@ -41,6 +44,7 @@ impl IntoLua for BackendInstallContext {
"download_path",
self.download_path.to_string_lossy().to_string(),
)?;
table.set("options", lua.to_value(&self.options)?)?;
Ok(Value::Table(table))
}
}
Expand Down
5 changes: 5 additions & 0 deletions crates/vfox/src/vfox.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use indexmap::IndexMap;
use itertools::Itertools;
use reqwest::Url;
use std::collections::BTreeMap;
Expand Down Expand Up @@ -262,13 +263,15 @@ impl Vfox {
version: &str,
install_path: PathBuf,
download_path: PathBuf,
options: IndexMap<String, String>,
) -> Result<()> {
let plugin = self.get_sdk(sdk)?;
let ctx = BackendInstallContext {
tool: tool.to_string(),
version: version.to_string(),
install_path,
download_path,
options,
};
plugin.backend_install(ctx).await?;
Ok(())
Expand All @@ -280,12 +283,14 @@ impl Vfox {
tool: &str,
version: &str,
install_path: PathBuf,
options: IndexMap<String, String>,
) -> Result<Vec<EnvKey>> {
let plugin = self.get_sdk(sdk)?;
let ctx = BackendExecEnvContext {
tool: tool.to_string(),
version: version.to_string(),
install_path,
options,
};
plugin.backend_exec_env(ctx).await.map(|r| r.env_vars)
}
Expand Down
4 changes: 4 additions & 0 deletions docs/backend-plugin-development.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,11 @@ function PLUGIN:BackendInstall(ctx)
local version = ctx.version
local install_path = ctx.install_path
local download_path = ctx.download_path
local options = ctx.options

-- Your logic to install the tool
-- Example: download files, extract archives, etc.
-- Access custom options via options["key"] or options.key

return {}
end
Expand All @@ -70,9 +72,11 @@ Sets up environment variables for a tool:
```lua
function PLUGIN:BackendExecEnv(ctx)
local install_path = ctx.install_path
local options = ctx.options

-- Your logic to set up environment variables
-- Example: add bin directories to PATH
-- Access custom options via options["key"] or options.key

return {
env_vars = {
Expand Down
14 changes: 11 additions & 3 deletions src/backend/vfox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,14 @@ impl Backend for VfoxBackend {
if self.is_backend_plugin() {
Settings::get().ensure_experimental("custom backends")?;
let tool_name = self.get_tool_name()?;
let tool_opts = tv.request.options();
vfox.backend_install(
&self.pathname,
tool_name,
&tv.version,
tv.install_path(),
tv.download_path(),
tool_opts.opts.clone(),
)
.await
.wrap_err("Backend install method failed")?;
Expand Down Expand Up @@ -292,9 +294,15 @@ impl VfoxBackend {
// Use backend methods if the plugin supports them
let env_keys = if self.is_backend_plugin() {
let tool_name = self.get_tool_name()?;
vfox.backend_exec_env(&self.pathname, tool_name, &tv.version, tv.install_path())
.await
.wrap_err("Backend exec env method failed")?
vfox.backend_exec_env(
&self.pathname,
tool_name,
&tv.version,
tv.install_path(),
opts.opts.clone(),
)
.await
.wrap_err("Backend exec env method failed")?
} else {
vfox.env_keys(&self.pathname, &tv.version, &opts.opts)
.await?
Expand Down
Loading