use crate::{AgentSurfaceSpec, LicenseType, RepoInfo};
pub const WORKSPACE_REPO: RepoInfo = RepoInfo::new("tftio-stuff", "tools");
#[derive(Debug, Clone)]
pub struct ToolSpec {
pub bin_name: &'static str,
pub display_name: &'static str,
pub version: &'static str,
pub license: LicenseType,
pub repo: RepoInfo,
pub supports_json: bool,
pub supports_doctor: bool,
pub supports_update: bool,
pub agent_surface: Option<&'static AgentSurfaceSpec>,
}
impl ToolSpec {
#[must_use]
pub const fn new(
bin_name: &'static str,
display_name: &'static str,
version: &'static str,
license: LicenseType,
repo: RepoInfo,
supports_json: bool,
supports_doctor: bool,
supports_update: bool,
) -> Self {
Self {
bin_name,
display_name,
version,
license,
repo,
supports_json,
supports_doctor,
supports_update,
agent_surface: None,
}
}
#[must_use]
pub const fn workspace(
bin_name: &'static str,
display_name: &'static str,
version: &'static str,
license: LicenseType,
supports_json: bool,
supports_doctor: bool,
supports_update: bool,
) -> Self {
Self::new(
bin_name,
display_name,
version,
license,
WORKSPACE_REPO,
supports_json,
supports_doctor,
supports_update,
)
}
#[must_use]
pub const fn with_agent_surface(self, agent_surface: &'static AgentSurfaceSpec) -> Self {
Self {
agent_surface: Some(agent_surface),
..self
}
}
}
#[must_use]
pub const fn workspace_tool(
bin_name: &'static str,
display_name: &'static str,
version: &'static str,
license: LicenseType,
supports_json: bool,
supports_doctor: bool,
supports_update: bool,
) -> ToolSpec {
ToolSpec::workspace(
bin_name,
display_name,
version,
license,
supports_json,
supports_doctor,
supports_update,
)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn tool_spec_new_preserves_fields() {
let spec = ToolSpec::new(
"tool",
"Tool",
"1.2.3",
LicenseType::MIT,
RepoInfo::new("owner", "repo"),
true,
false,
true,
);
assert_eq!(spec.bin_name, "tool");
assert_eq!(spec.display_name, "Tool");
assert_eq!(spec.version, "1.2.3");
assert_eq!(spec.license, LicenseType::MIT);
assert_eq!(spec.repo.owner, "owner");
assert_eq!(spec.repo.name, "repo");
assert!(spec.supports_json);
assert!(!spec.supports_doctor);
assert!(spec.supports_update);
assert!(spec.agent_surface.is_none());
}
#[test]
fn workspace_tool_uses_workspace_repo_defaults() {
let spec = workspace_tool(
"tool",
"Tool",
"1.2.3",
LicenseType::MIT,
true,
false,
false,
);
assert_eq!(spec.repo.owner, WORKSPACE_REPO.owner);
assert_eq!(spec.repo.name, WORKSPACE_REPO.name);
assert_eq!(spec.bin_name, "tool");
assert_eq!(spec.display_name, "Tool");
}
}