1use crate::system::error::{DoumError, DoumResult};
2use std::path::PathBuf;
3
4pub fn get_app_dir() -> DoumResult<PathBuf> {
9 #[cfg(target_os = "windows")]
10 {
11 let appdata = std::env::var("APPDATA")
12 .map_err(|_| DoumError::Config("APPDATA 환경 변수를 찾을 수 없습니다".to_string()))?;
13 Ok(PathBuf::from(appdata).join("doum-cli"))
14 }
15
16 #[cfg(target_os = "macos")]
17 {
18 let home = std::env::var("HOME")
19 .map_err(|_| DoumError::Config("HOME 환경 변수를 찾을 수 없습니다".to_string()))?;
20 Ok(PathBuf::from(home).join("Library/Application Support/doum-cli"))
21 }
22
23 #[cfg(target_os = "linux")]
24 {
25 let home = std::env::var("HOME")
26 .map_err(|_| DoumError::Config("HOME 환경 변수를 찾을 수 없습니다".to_string()))?;
27 let config_home =
28 std::env::var("XDG_CONFIG_HOME").unwrap_or_else(|_| format!("{}/.config", home));
29 Ok(PathBuf::from(config_home).join("doum-cli"))
30 }
31
32 #[cfg(not(any(target_os = "windows", target_os = "macos", target_os = "linux")))]
33 {
34 Err(DoumError::Config(
35 "지원하지 않는 운영체제입니다".to_string(),
36 ))
37 }
38}
39
40pub fn get_log_dir() -> DoumResult<PathBuf> {
42 Ok(get_app_dir()?.join("logs"))
43}
44
45pub fn get_config_path() -> DoumResult<PathBuf> {
47 Ok(get_app_dir()?.join("config.toml"))
48}