plugin_interfaces/
config.rs1use std::fs;
2
3#[derive(Debug, Clone)]
5pub struct PluginConfig {
6 pub id: String,
7 pub disabled: bool,
8 pub name: String,
9 pub description: String,
10 pub version: String,
11 pub author: Option<String>,
12}
13
14impl PluginConfig {
15 pub fn from_file() -> Result<Self, Box<dyn std::error::Error>> {
17 let config_content = fs::read_to_string("config.toml")?;
19
20 let config: toml::Value = toml::from_str(&config_content)?;
22
23 let plugin = config
25 .get("plugin")
26 .ok_or("Missing [plugin] section in config.toml")?;
27
28 let id = plugin
29 .get("id")
30 .and_then(|v| v.as_str())
31 .ok_or("Missing 'id' in [plugin] section")?
32 .to_string();
33
34 let disabled = plugin
35 .get("disabled")
36 .and_then(|v| v.as_bool())
37 .unwrap_or(false);
38
39 let name = plugin
40 .get("name")
41 .and_then(|v| v.as_str())
42 .ok_or("Missing 'name' in [plugin] section")?
43 .to_string();
44
45 let description = plugin
46 .get("description")
47 .and_then(|v| v.as_str())
48 .ok_or("Missing 'description' in [plugin] section")?
49 .to_string();
50
51 let version = plugin
52 .get("version")
53 .and_then(|v| v.as_str())
54 .ok_or("Missing 'version' in [plugin] section")?
55 .to_string();
56
57 let author = plugin
58 .get("author")
59 .and_then(|v| v.as_str())
60 .map(|s| s.to_string());
61
62 Ok(PluginConfig {
63 id,
64 disabled,
65 name,
66 description,
67 version,
68 author,
69 })
70 }
71}