use crate::error::{Error, Result};
use std::path::PathBuf;
pub fn homeboy() -> Result<PathBuf> {
let config_dir = dirs::config_dir().ok_or_else(|| {
Error::internal_unexpected(
"Unable to resolve a config directory for this OS. This likely indicates a broken environment (missing HOME/USERPROFILE/APPDATA/XDG_CONFIG_HOME) or a bug in the config path resolver."
.to_string(),
)
})?;
Ok(config_dir.join("homeboy"))
}
pub fn projects() -> Result<PathBuf> {
Ok(homeboy()?.join("projects"))
}
pub fn servers() -> Result<PathBuf> {
Ok(homeboy()?.join("servers"))
}
pub fn components() -> Result<PathBuf> {
Ok(homeboy()?.join("components"))
}
pub fn modules() -> Result<PathBuf> {
Ok(homeboy()?.join("modules"))
}
pub fn keys() -> Result<PathBuf> {
Ok(homeboy()?.join("keys"))
}
pub fn backups() -> Result<PathBuf> {
Ok(homeboy()?.join("backups"))
}
pub fn project(id: &str) -> Result<PathBuf> {
Ok(projects()?.join(format!("{}.json", id)))
}
pub fn server(id: &str) -> Result<PathBuf> {
Ok(servers()?.join(format!("{}.json", id)))
}
pub fn component(id: &str) -> Result<PathBuf> {
Ok(components()?.join(format!("{}.json", id)))
}
pub fn module(id: &str) -> Result<PathBuf> {
Ok(modules()?.join(id))
}
pub fn module_manifest(id: &str) -> Result<PathBuf> {
Ok(modules()?.join(id).join(format!("{}.json", id)))
}
pub fn key(server_id: &str) -> Result<PathBuf> {
Ok(keys()?.join(format!("{}_id_rsa", server_id)))
}