Skip to main content

ontocore_plugin/
manifest.rs

1use serde::Deserialize;
2use std::path::PathBuf;
3
4/// Parsed plugin manifest from workspace TOML.
5#[derive(Debug, Clone, PartialEq, Eq)]
6pub struct PluginManifest {
7    pub name: String,
8    pub version: String,
9    pub kind: String,
10    pub id: Option<String>,
11    pub api_version: Option<String>,
12    pub entry: Option<String>,
13    pub capabilities: PluginCapabilities,
14}
15
16#[derive(Debug, Clone, Default, PartialEq, Eq, Deserialize)]
17pub struct PluginCapabilities {
18    #[serde(default)]
19    pub build: bool,
20    #[serde(default)]
21    pub validate: bool,
22    #[serde(default)]
23    pub release: bool,
24    #[serde(default)]
25    pub diagnostics: bool,
26    #[serde(default)]
27    pub export: bool,
28}
29
30#[derive(Debug, Clone, PartialEq, Eq)]
31pub struct DiscoveredPlugin {
32    pub manifest: PluginManifest,
33    pub manifest_path: PathBuf,
34}
35
36#[derive(Debug, Deserialize)]
37struct ManifestFile {
38    plugin: PluginSection,
39    #[serde(default)]
40    capabilities: PluginCapabilities,
41}
42
43#[derive(Debug, Deserialize)]
44struct PluginSection {
45    name: String,
46    version: String,
47    kind: String,
48    #[serde(default)]
49    id: Option<String>,
50    #[serde(default)]
51    api_version: Option<String>,
52    #[serde(default)]
53    entry: Option<String>,
54}
55
56/// Parse a plugin manifest from TOML text.
57pub fn parse_manifest(text: &str) -> Result<PluginManifest, toml::de::Error> {
58    let file: ManifestFile = toml::from_str(text)?;
59    Ok(PluginManifest {
60        name: file.plugin.name,
61        version: file.plugin.version,
62        kind: file.plugin.kind,
63        id: file.plugin.id,
64        api_version: file.plugin.api_version,
65        entry: file.plugin.entry,
66        capabilities: file.capabilities,
67    })
68}
69
70#[cfg(test)]
71mod tests {
72    use super::*;
73
74    #[test]
75    fn parses_example_manifest() {
76        let text = r#"
77[plugin]
78name = "example-workflow"
79version = "0.1.0"
80kind = "workflow"
81
82[capabilities]
83build = true
84validate = true
85"#;
86        let manifest = parse_manifest(text).expect("parse");
87        assert_eq!(manifest.name, "example-workflow");
88        assert_eq!(manifest.kind, "workflow");
89        assert!(manifest.capabilities.build);
90        assert!(manifest.capabilities.validate);
91    }
92}