use crate::error::{Error, Result};
use std::env;
use std::path::PathBuf;
pub fn homeboy() -> Result<PathBuf> {
#[cfg(windows)]
{
let appdata = env::var("APPDATA").map_err(|_| {
Error::internal_unexpected(
"APPDATA environment variable not set on Windows".to_string(),
)
})?;
Ok(PathBuf::from(appdata).join("homeboy"))
}
#[cfg(not(windows))]
{
let home = env::var("HOME").map_err(|_| {
Error::internal_unexpected(
"HOME environment variable not set on Unix-like system".to_string(),
)
})?;
Ok(PathBuf::from(home).join(".config").join("homeboy"))
}
}
pub fn homeboy_json() -> Result<PathBuf> {
Ok(homeboy()?.join("homeboy.json"))
}
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)))
}