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