doum_cli/system/
paths.rs

1use crate::system::error::{DoumError, Result};
2use std::path::PathBuf;
3
4/// doum-cli의 기본 디렉터리 경로를 반환
5/// - Windows: C:\Users\{user}\AppData\Roaming\doum-cli
6/// - macOS: ~/Library/Application Support/doum-cli
7/// - Linux: ~/.config/doum-cli
8pub fn get_app_dir() -> Result<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 = std::env::var("XDG_CONFIG_HOME")
28            .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("지원하지 않는 운영체제입니다".to_string()))
35    }
36}
37
38/// 로그 디렉터리 경로를 반환
39pub fn get_log_dir() -> Result<PathBuf> {
40    Ok(get_app_dir()?.join("logs"))
41}
42
43/// 설정 파일 경로를 반환
44pub fn get_config_path() -> Result<PathBuf> {
45    Ok(get_app_dir()?.join("config.toml"))
46}