avam-client and oauth2

This commit is contained in:
2024-10-17 00:56:02 +02:00
parent bfc5cbf624
commit f93eb3c429
50 changed files with 5674 additions and 277 deletions

43
avam-client/src/dirs.rs Normal file
View File

@@ -0,0 +1,43 @@
use std::path::PathBuf;
use directories::ProjectDirs;
use thiserror::Error;
pub struct Dirs {}
#[derive(Debug, Error)]
pub enum DirsError {
#[error("Unable to get Project Directories")]
ProjectDirs,
#[error(transparent)]
Io(#[from] std::io::Error),
#[error(transparent)]
Unknown(#[from] anyhow::Error),
}
impl Dirs {
pub fn get_config_dir() -> Result<PathBuf, DirsError> {
let Some(proj_dirs) = ProjectDirs::from("nl", "Avii", "Avam") else {
return Err(DirsError::ProjectDirs);
};
let config_dir = proj_dirs.config_local_dir();
if !config_dir.exists() {
std::fs::create_dir_all(config_dir)?;
}
Ok(config_dir.to_path_buf())
}
pub fn get_config_file() -> Result<PathBuf, DirsError> {
let mut c = Self::get_config_dir()?;
c.push("config.toml");
Ok(c)
}
pub fn get_lock_file() -> Result<PathBuf, DirsError> {
let mut c = Self::get_config_dir()?;
c.push(".lock");
Ok(c)
}
}