use aleo_std;
use leo_errors::{CliError, Result};
use leo_package::Manifest;
use aleo_std::aleo_dir;
use std::{env::current_dir, path::PathBuf};
#[derive(Clone)]
pub struct Context {
pub path: Option<PathBuf>,
pub home: Option<PathBuf>,
pub recursive: bool,
}
impl Context {
pub fn new(path: Option<PathBuf>, home: Option<PathBuf>, recursive: bool) -> Result<Context> {
Ok(Context { path, home, recursive })
}
pub fn parent_dir(&self) -> Result<PathBuf> {
match &self.path {
Some(path) => {
let mut path = path.clone();
path.pop();
Ok(path)
}
None => Ok(current_dir().map_err(CliError::cli_io_error)?),
}
}
pub fn dir(&self) -> Result<PathBuf> {
match &self.path {
Some(path) => Ok(path.clone()),
None => Ok(current_dir().map_err(CliError::cli_io_error)?),
}
}
pub fn home(&self) -> Result<PathBuf> {
match &self.home {
Some(path) => Ok(path.clone()),
None => Ok(aleo_dir()),
}
}
pub fn open_manifest(&self) -> Result<Manifest> {
let path = self.dir()?;
let manifest_path = path.join(leo_package::MANIFEST_FILENAME);
let manifest = Manifest::read_from_file(manifest_path)?;
Ok(manifest)
}
}