actions_templates/
config.rs1use crate::prompts::Prompts;
2use serde::{Deserialize, Serialize};
3use serde_json::Value;
4use std::path::Path;
5
6use anyhow::Result;
7#[derive(Debug, Serialize, Deserialize, Clone)]
8pub struct Config {
9 pub name: String,
10 #[serde(skip_serializing_if = "Option::is_none")]
11 pub description: Option<String>,
13 #[serde(skip_serializing_if = "Option::is_none")]
15 pub path: Option<String>,
16 pub prompts: Prompts,
17 #[serde(skip_serializing_if = "Option::is_none")]
18 pub success_message: Option<String>,
19}
20
21impl From<String> for Config {
22 fn from(value: String) -> Self {
23 let new_config: Value = serde_json::from_str(value.as_str()).unwrap();
24 serde_json::from_str(new_config.as_str().unwrap()).unwrap()
25 }
26}
27
28impl Config {
29 pub fn from_file<P: AsRef<Path>>(path: P) -> Result<Self> {
30 let file = std::fs::File::open(path)?;
31 Ok(serde_json::from_reader(file)?)
32 }
33}