1use anyhow::{anyhow, Result};
4use std::path::PathBuf;
5
6const CONFIG_DIR: &str = ".oboron";
7const PROFILES_SUBDIR: &str = "profiles";
8const BACKUP_SUBDIR: &str = "bkp";
9const CONFIG_FILENAME: &str = "config.json";
10
11pub fn config_root() -> Result<PathBuf> {
12 Ok(dirs::home_dir()
13 .ok_or_else(|| anyhow!("could not locate home directory"))?
14 .join(CONFIG_DIR))
15}
16
17pub fn config_path() -> Result<PathBuf> {
18 Ok(config_root()?.join(CONFIG_FILENAME))
19}
20
21pub fn profile_dir() -> Result<PathBuf> {
22 Ok(config_root()?.join(PROFILES_SUBDIR))
23}
24
25pub fn profile_path(name: &str) -> Result<PathBuf> {
26 crate::profile::validate_profile_name(name)?;
27 Ok(profile_dir()?.join(format!("{name}.json")))
28}
29
30pub fn backup_dir() -> Result<PathBuf> {
31 Ok(config_root()?.join(BACKUP_SUBDIR))
32}