1use serde::{Deserialize, Serialize};
4use std::path::PathBuf;
5
6#[derive(Debug, Clone, Serialize, Deserialize)]
8pub struct StorageConfig {
9 pub global_path: PathBuf,
11 pub project_path: Option<PathBuf>,
13 pub mode: StorageMode,
15 pub first_run: bool,
17}
18
19#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
21pub enum StorageMode {
22 GlobalOnly,
24 ProjectOnly,
26 Merged,
28}
29
30#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
32pub enum ResourceType {
33 Template,
35 Standard,
37 Spec,
39 Steering,
41 Boilerplate,
43 Rule,
45 CustomCommand,
47 LspLanguageConfig,
49 CompletionLanguageConfig,
51 HooksConfig,
53 RefactoringLanguageConfig,
55}
56
57impl ResourceType {
58 pub fn dir_name(&self) -> &'static str {
60 match self {
61 ResourceType::Template => "templates",
62 ResourceType::Standard => "standards",
63 ResourceType::Spec => "specs",
64 ResourceType::Steering => "steering",
65 ResourceType::Boilerplate => "boilerplates",
66 ResourceType::Rule => "rules",
67 ResourceType::CustomCommand => "commands",
68 ResourceType::LspLanguageConfig => "lsp/languages",
69 ResourceType::CompletionLanguageConfig => "completion/languages",
70 ResourceType::HooksConfig => "hooks",
71 ResourceType::RefactoringLanguageConfig => "refactoring/languages",
72 }
73 }
74}
75
76#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
78pub enum ConfigFormat {
79 Yaml,
81 Toml,
83 Json,
85}
86
87impl ConfigFormat {
88 pub fn extension(&self) -> &'static str {
90 match self {
91 ConfigFormat::Yaml => "yaml",
92 ConfigFormat::Toml => "toml",
93 ConfigFormat::Json => "json",
94 }
95 }
96
97 pub fn from_extension(ext: &str) -> Option<Self> {
99 match ext.to_lowercase().as_str() {
100 "yaml" | "yml" => Some(ConfigFormat::Yaml),
101 "toml" => Some(ConfigFormat::Toml),
102 "json" => Some(ConfigFormat::Json),
103 _ => None,
104 }
105 }
106}
107
108#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
110pub enum DocumentFormat {
111 Yaml,
113 Markdown,
115}
116
117impl DocumentFormat {
118 pub fn extension(&self) -> &'static str {
120 match self {
121 DocumentFormat::Yaml => "yaml",
122 DocumentFormat::Markdown => "md",
123 }
124 }
125
126 pub fn from_extension(ext: &str) -> Option<Self> {
128 match ext.to_lowercase().as_str() {
129 "yaml" | "yml" => Some(DocumentFormat::Yaml),
130 "md" | "markdown" => Some(DocumentFormat::Markdown),
131 _ => None,
132 }
133 }
134}
135
136#[derive(Debug, Clone, PartialEq, Eq)]
138pub enum StorageState {
139 Available,
141 Unavailable { reason: String },
143 ReadOnly { cached_at: String },
145}
146
147#[cfg(test)]
148mod tests {
149 use super::*;
150
151 #[test]
152 fn test_resource_type_dir_names() {
153 assert_eq!(ResourceType::Template.dir_name(), "templates");
154 assert_eq!(ResourceType::Standard.dir_name(), "standards");
155 assert_eq!(ResourceType::Spec.dir_name(), "specs");
156 assert_eq!(ResourceType::Steering.dir_name(), "steering");
157 assert_eq!(ResourceType::Boilerplate.dir_name(), "boilerplates");
158 assert_eq!(ResourceType::Rule.dir_name(), "rules");
159 assert_eq!(ResourceType::CustomCommand.dir_name(), "commands");
160 assert_eq!(ResourceType::HooksConfig.dir_name(), "hooks");
161 assert_eq!(
162 ResourceType::RefactoringLanguageConfig.dir_name(),
163 "refactoring/languages"
164 );
165 }
166
167 #[test]
168 fn test_config_format_extensions() {
169 assert_eq!(ConfigFormat::Yaml.extension(), "yaml");
170 assert_eq!(ConfigFormat::Toml.extension(), "toml");
171 assert_eq!(ConfigFormat::Json.extension(), "json");
172 }
173
174 #[test]
175 fn test_config_format_detection() {
176 assert_eq!(
177 ConfigFormat::from_extension("yaml"),
178 Some(ConfigFormat::Yaml)
179 );
180 assert_eq!(
181 ConfigFormat::from_extension("yml"),
182 Some(ConfigFormat::Yaml)
183 );
184 assert_eq!(
185 ConfigFormat::from_extension("toml"),
186 Some(ConfigFormat::Toml)
187 );
188 assert_eq!(
189 ConfigFormat::from_extension("json"),
190 Some(ConfigFormat::Json)
191 );
192 assert_eq!(ConfigFormat::from_extension("txt"), None);
193 }
194
195 #[test]
196 fn test_document_format_detection() {
197 assert_eq!(
198 DocumentFormat::from_extension("yaml"),
199 Some(DocumentFormat::Yaml)
200 );
201 assert_eq!(
202 DocumentFormat::from_extension("md"),
203 Some(DocumentFormat::Markdown)
204 );
205 assert_eq!(
206 DocumentFormat::from_extension("markdown"),
207 Some(DocumentFormat::Markdown)
208 );
209 assert_eq!(DocumentFormat::from_extension("txt"), None);
210 }
211}