use std::path::{Path, PathBuf};
pub const CONFIG_DIR: &str = ".strixonomy";
pub const CACHE_SUBDIR: &str = "cache";
pub const PLUGINS_SUBDIR: &str = "plugins";
pub const DIAGNOSTICS_FILE: &str = "diagnostics.toml";
pub const PLUGIN_OUT_REL: &str = ".strixonomy/plugin-out";
pub const PLUGIN_DISABLED_REL: &str = ".strixonomy/plugin-disabled.json";
pub fn resolve_config_path(workspace: &Path, leaf: &str) -> PathBuf {
workspace.join(CONFIG_DIR).join(leaf)
}
pub fn resolve_dotted_config_path(workspace: &Path, rel: &str) -> PathBuf {
workspace.join(rel)
}
pub fn plugins_dir(workspace: &Path) -> PathBuf {
resolve_config_path(workspace, PLUGINS_SUBDIR)
}
pub fn plugin_search_dirs(workspace: &Path) -> Vec<PathBuf> {
vec![plugins_dir(workspace)]
}
pub fn cache_dir(workspace: &Path) -> PathBuf {
resolve_config_path(workspace, CACHE_SUBDIR)
}
pub fn diagnostics_config_path(workspace: &Path) -> PathBuf {
resolve_config_path(workspace, DIAGNOSTICS_FILE)
}
#[cfg(test)]
mod tests {
use super::*;
use std::fs;
#[test]
fn uses_primary_config_dir() {
let dir = tempfile::tempdir().unwrap();
fs::create_dir_all(dir.path().join(".strixonomy/cache")).unwrap();
assert_eq!(cache_dir(dir.path()), dir.path().join(".strixonomy/cache"));
}
#[test]
fn defaults_to_primary_when_missing() {
let dir = tempfile::tempdir().unwrap();
assert_eq!(
diagnostics_config_path(dir.path()),
dir.path().join(".strixonomy/diagnostics.toml")
);
assert_eq!(plugins_dir(dir.path()), dir.path().join(".strixonomy/plugins"));
}
}