use crate::settings::{Settings, STUB};
use crate::storage::Storage;
use crate::tools::git;
use std::collections::HashMap;
use std::convert::TryFrom;
pub struct Environment {
pub settings: Settings,
pub vars: HashMap<String, String>,
pub output: Storage,
pub repo: Option<git::Repo>,
}
impl Environment {
#[must_use]
pub fn new(settings: Settings) -> Self {
let vars = HashMap::<String, String>::new();
let output = Storage::new();
let repo = git::Repo::try_from(settings.repo_path.as_deref()).ok();
Self {
settings,
vars,
output,
repo,
}
}
#[must_use]
pub fn stub() -> Self {
Self::new(STUB.clone())
}
#[must_use]
pub const fn repo(&self) -> Option<&git::Repo> {
self.repo.as_ref()
}
}