use std::collections::BTreeMap;
use std::path::PathBuf;
use serde::Serialize;
use crate::context;
use crate::{EnvironmentInput, Result, WorktreeOptions};
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct EnvOptions {
pub cwd: Option<PathBuf>,
pub root: Option<PathBuf>,
pub environment: EnvironmentInput,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
#[serde(transparent)]
pub struct EnvReport {
pub environment: BTreeMap<String, String>,
}
pub fn inspect_env(options: EnvOptions) -> Result<EnvReport> {
let context = context::resolve(&WorktreeOptions {
cwd: options.cwd,
root: options.root,
environment: options.environment,
})?;
let environment = context
.environment
.into_iter()
.map(|(name, value)| (name, value.to_string_lossy().into_owned()))
.collect();
Ok(EnvReport { environment })
}