Skip to main content

CliEnv

Struct CliEnv 

Source
#[non_exhaustive]
pub struct CliEnv { pub linesmith_config: Option<String>, pub xdg_config_home: Option<String>, pub home: Option<String>, pub no_color: bool, pub force_color: bool, pub colorterm: Option<String>, pub term: Option<String>, pub terminal_width: Option<u16>, pub color_capability: Option<Capability>, pub cwd: Option<PathBuf>, pub log_level_env: Option<String>, }
Expand description

Process-ambient inputs the CLI reads: env vars consulted by resolve_config_path, the color-policy env flags, an optional terminal-width override, and an optional color-capability override. Passed through cli_main so tests can drive the whole binary without touching the real process env. #[non_exhaustive] leaves room for future env vars (TERM, …) without breaking external construction.

Env snapshotting is the exclusive job of CliEnv::from_process. CliEnv::default and CliEnv::for_tests do not read any ambient state — the resolver honors only what the struct carries. Production binaries must use from_process; callers passing default() opt out of env awareness entirely (including NO_COLOR / FORCE_COLOR / COLUMNS).

terminal_width = None means “detect lazily when the render path needs it.” Meta commands (--help, --version, --check-config) never probe the terminal, so stray COLUMNS warnings don’t leak into clean stderr.

color_capability = Some(cap) bypasses the entire color-policy precedence chain — reserved for test determinism. Production uses None and lets no_color / force_color / config resolve it.

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§linesmith_config: Option<String>§xdg_config_home: Option<String>§home: Option<String>§no_color: bool§force_color: bool§colorterm: Option<String>

Raw COLORTERM, or None if unset. Threaded to the force-color resolver so it can justify TrueColor when the TTY probe gives up (e.g. piped stdout under Claude Code). from_process snapshots the real env; for_tests/default leave it None so ambient COLORTERM=truecolor can’t leak into captured-output tests.

§term: Option<String>

Raw TERM, or None if unset. Same snapshot discipline as colorterm.

§terminal_width: Option<u16>§color_capability: Option<Capability>§cwd: Option<PathBuf>

cwd used for gix repo discovery. None skips discovery entirely. Self::from_process sets this to std::env::current_dir(); Self::for_tests leaves it None.

§log_level_env: Option<String>

Raw LINESMITH_LOG value, or None if unset. from_process snapshots the real env; for_tests/default leave it None so a developer’s ambient LINESMITH_LOG=debug can’t pollute captured-stderr CLI tests.

Implementations§

Source§

impl CliEnv

Source

pub fn from_process() -> Self

Snapshot the real process env vars. Terminal width and color capability are left unset; run_cli probes them only if a render happens.

Source

pub fn for_tests() -> Self

Test-suite baseline: no env paths, color flags off, terminal_width = Some(200), color_capability = Some(None). Forces the capability override so stdout stays plain under a truecolor host; tests that exercise the color-policy resolver directly use CliEnv::default() instead.

Trait Implementations§

Source§

impl Clone for CliEnv

Source§

fn clone(&self) -> CliEnv

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CliEnv

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for CliEnv

Source§

fn default() -> CliEnv

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.