fetchium_core/plugin/
manifest.rs1use crate::error::FetchiumError;
4use serde::{Deserialize, Serialize};
5
6#[derive(Debug, Clone, Serialize, Deserialize)]
8pub struct PluginManifest {
9 pub name: String,
10 pub version: String,
11 pub plugin_type: String,
13 pub runtime: String,
15 pub description: String,
16 pub author: Option<String>,
17 pub homepage: Option<String>,
18 pub config_schema: Option<serde_json::Value>,
19}
20
21impl PluginManifest {
22 pub fn load(path: &std::path::Path) -> Result<Self, FetchiumError> {
24 let content = std::fs::read_to_string(path)?;
25 toml::from_str(&content)
26 .map_err(|e| FetchiumError::Config(format!("plugin.toml parse error: {e}")))
27 }
28
29 pub fn scaffold(
31 name: &str,
32 plugin_type: &str,
33 path: &std::path::Path,
34 ) -> Result<(), FetchiumError> {
35 let manifest = PluginManifest {
36 name: name.to_string(),
37 version: "0.1.0".to_string(),
38 plugin_type: plugin_type.to_string(),
39 runtime: "native".to_string(),
40 description: format!("A Fetchium {plugin_type} plugin"),
41 author: None,
42 homepage: None,
43 config_schema: None,
44 };
45 let content = toml::to_string_pretty(&manifest)
46 .map_err(|e| FetchiumError::Config(format!("serialise error: {e}")))?;
47 std::fs::write(path, content)?;
48 Ok(())
49 }
50}