1use serde::{Deserialize, Serialize};
2use std::path::PathBuf;
3
4#[derive(Debug, Clone, Default, Serialize, Deserialize)]
5pub struct AppConfig {
6 #[serde(default)]
7 pub default_branch_prefix: Option<String>,
8}
9
10impl AppConfig {
11 pub fn config_path() -> Option<PathBuf> {
12 #[cfg(target_os = "macos")]
13 {
14 dirs::home_dir().map(|home| home.join(".config/kanban/config.toml"))
15 }
16 #[cfg(target_os = "linux")]
17 {
18 dirs::config_dir().map(|config| config.join("kanban/config.toml"))
19 }
20 #[cfg(target_os = "windows")]
21 {
22 dirs::config_dir().map(|config| config.join("kanban\\config.toml"))
23 }
24 #[cfg(not(any(target_os = "macos", target_os = "linux", target_os = "windows")))]
25 {
26 None
27 }
28 }
29
30 pub fn load() -> Self {
31 if let Some(config_path) = Self::config_path() {
32 if config_path.exists() {
33 if let Ok(content) = std::fs::read_to_string(&config_path) {
34 if let Ok(config) = toml::from_str(&content) {
35 return config;
36 }
37 }
38 }
39 }
40 Self::default()
41 }
42
43 pub fn effective_default_sprint_prefix(&self) -> &str {
44 self.default_branch_prefix.as_deref().unwrap_or("sprint")
45 }
46
47 pub fn effective_default_card_prefix(&self) -> &str {
48 self.default_branch_prefix.as_deref().unwrap_or("task")
49 }
50
51 #[deprecated(
52 since = "0.1.10",
53 note = "use effective_default_sprint_prefix or effective_default_card_prefix instead"
54 )]
55 pub fn effective_default_prefix(&self) -> &str {
56 self.effective_default_card_prefix()
57 }
58}