avam-client and oauth2
This commit is contained in:
43
avam-client/src/dirs.rs
Normal file
43
avam-client/src/dirs.rs
Normal 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)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user