1use std::path::PathBuf;
2
3use serde::{Deserialize, Serialize};
4
5use crate::scanner::ProjectKind;
6
7#[derive(Debug, Clone, Default, Serialize, Deserialize)]
9pub struct DevSweepConfig {
10 #[serde(default)]
12 pub ignore_paths: Vec<PathBuf>,
13
14 #[serde(default)]
16 pub exclude_kinds: Vec<ProjectKind>,
17
18 #[serde(default)]
20 pub default_roots: Vec<PathBuf>,
21
22 #[serde(default)]
24 pub max_depth: Option<usize>,
25}
26
27impl DevSweepConfig {
28 pub fn load() -> Self {
30 let config_path = Self::config_path();
31 if config_path.exists() {
32 match std::fs::read_to_string(&config_path) {
33 Ok(contents) => serde_json::from_str(&contents).unwrap_or_default(),
34 Err(_) => Self::default(),
35 }
36 } else {
37 Self::default()
38 }
39 }
40
41 pub fn save(&self) -> anyhow::Result<()> {
43 let config_path = Self::config_path();
44 if let Some(parent) = config_path.parent() {
45 std::fs::create_dir_all(parent)?;
46 }
47 let json = serde_json::to_string_pretty(self)?;
48 std::fs::write(&config_path, json)?;
49 Ok(())
50 }
51
52 pub fn config_path() -> PathBuf {
54 dirs::config_dir()
55 .unwrap_or_else(|| PathBuf::from("~/.config"))
56 .join("dev-sweep")
57 .join("config.json")
58 }
59}