1use anyhow::{Context, Result};
2use std::path::PathBuf;
3
4pub fn get_app_dir() -> Result<PathBuf> {
9 #[cfg(target_os = "windows")]
10 {
11 let appdata =
12 std::env::var("APPDATA").context("Could not find APPDATA environment variable")?;
13 Ok(PathBuf::from(appdata).join("doum-cli"))
14 }
15
16 #[cfg(target_os = "macos")]
17 {
18 let home = std::env::var("HOME").context("HOME environment variable not found")?;
19 Ok(PathBuf::from(home).join("Library/Application Support/doum-cli"))
20 }
21
22 #[cfg(target_os = "linux")]
23 {
24 let home = std::env::var("HOME").context("HOME environment variable not found")?;
25 let config_home =
26 std::env::var("XDG_CONFIG_HOME").unwrap_or_else(|_| format!("{}/.config", home));
27 Ok(PathBuf::from(config_home).join("doum-cli"))
28 }
29
30 #[cfg(not(any(target_os = "windows", target_os = "macos", target_os = "linux")))]
31 {
32 anyhow::bail!("Unsupported operating system for determining app directory")
33 }
34}
35
36pub fn get_log_dir() -> Result<PathBuf> {
38 Ok(get_app_dir()?.join("logs"))
39}
40
41pub fn get_config_path() -> Result<PathBuf> {
43 Ok(get_app_dir()?.join("config.toml"))
44}