1use std::path::{Path, PathBuf};
4
5pub const CONFIG_DIR: &str = ".strixonomy";
7
8pub const CACHE_SUBDIR: &str = "cache";
10
11pub const PLUGINS_SUBDIR: &str = "plugins";
13
14pub const DIAGNOSTICS_FILE: &str = "diagnostics.toml";
16
17pub const PLUGIN_OUT_REL: &str = ".strixonomy/plugin-out";
19
20pub const PLUGIN_DISABLED_REL: &str = ".strixonomy/plugin-disabled.json";
22
23pub fn resolve_config_path(workspace: &Path, leaf: &str) -> PathBuf {
25 workspace.join(CONFIG_DIR).join(leaf)
26}
27
28pub fn resolve_dotted_config_path(workspace: &Path, rel: &str) -> PathBuf {
30 workspace.join(rel)
31}
32
33pub fn plugins_dir(workspace: &Path) -> PathBuf {
35 resolve_config_path(workspace, PLUGINS_SUBDIR)
36}
37
38pub fn plugin_search_dirs(workspace: &Path) -> Vec<PathBuf> {
40 vec![plugins_dir(workspace)]
41}
42
43pub fn cache_dir(workspace: &Path) -> PathBuf {
45 resolve_config_path(workspace, CACHE_SUBDIR)
46}
47
48pub fn diagnostics_config_path(workspace: &Path) -> PathBuf {
50 resolve_config_path(workspace, DIAGNOSTICS_FILE)
51}
52
53#[cfg(test)]
54mod tests {
55 use super::*;
56 use std::fs;
57
58 #[test]
59 fn uses_primary_config_dir() {
60 let dir = tempfile::tempdir().unwrap();
61 fs::create_dir_all(dir.path().join(".strixonomy/cache")).unwrap();
62 assert_eq!(cache_dir(dir.path()), dir.path().join(".strixonomy/cache"));
63 }
64
65 #[test]
66 fn defaults_to_primary_when_missing() {
67 let dir = tempfile::tempdir().unwrap();
68 assert_eq!(
69 diagnostics_config_path(dir.path()),
70 dir.path().join(".strixonomy/diagnostics.toml")
71 );
72 assert_eq!(plugins_dir(dir.path()), dir.path().join(".strixonomy/plugins"));
73 }
74}