1use std::collections::BTreeMap;
2use std::path::PathBuf;
3
4use serde::Serialize;
5
6use crate::context;
7use crate::{EnvironmentInput, Result, WorktreeOptions};
8
9#[derive(Debug, Clone, Default, PartialEq, Eq)]
11pub struct EnvOptions {
12 pub cwd: Option<PathBuf>,
14 pub root: Option<PathBuf>,
16 pub environment: EnvironmentInput,
18}
19
20#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
22#[serde(transparent)]
23pub struct EnvReport {
24 pub environment: BTreeMap<String, String>,
26}
27
28pub fn inspect_env(options: EnvOptions) -> Result<EnvReport> {
37 let context = context::resolve(&WorktreeOptions {
38 cwd: options.cwd,
39 root: options.root,
40 environment: options.environment,
41 })?;
42 let environment = context
43 .environment
44 .into_iter()
45 .map(|(name, value)| (name, value.to_string_lossy().into_owned()))
46 .collect();
47
48 Ok(EnvReport { environment })
49}