use crate::Result;
use crate::dir_context::path_consts::{AIPACK_DIR_NAME, CONFIG_FILE_NAME, PACK_CUSTOM};
use camino::Utf8PathBuf;
use simple_fs::SPath;
use std::ops::Deref;
#[derive(Debug, Clone)]
pub struct AipackWksDir {
path: SPath,
}
impl AipackWksDir {
pub fn new_from_wks_dir(wks_dir: &SPath) -> Result<Self> {
let aipack_wks_path = wks_dir.join(AIPACK_DIR_NAME);
Ok(Self { path: aipack_wks_path })
}
pub fn path(&self) -> &SPath {
&self.path
}
pub fn get_config_toml_path(&self) -> Result<SPath> {
let path = self.join(CONFIG_FILE_NAME);
Ok(path)
}
pub fn get_pack_custom_dir(&self) -> Result<SPath> {
let dir = self.join(PACK_CUSTOM);
Ok(dir)
}
}
impl AipackWksDir {
pub fn exists(&self) -> bool {
self.path.exists()
}
pub fn join(&self, leaf_path: impl Into<Utf8PathBuf>) -> SPath {
self.path.join(leaf_path)
}
}
impl AsRef<SPath> for AipackWksDir {
fn as_ref(&self) -> &SPath {
&self.path
}
}
impl Deref for AipackWksDir {
type Target = SPath;
fn deref(&self) -> &Self::Target {
&self.path
}
}
#[cfg(test)]
impl AipackWksDir {
pub fn new_for_test(path: impl Into<SPath>) -> Result<Self> {
let path = path.into();
Ok(Self { path })
}
}