Skip to main content

CommandContext

Struct CommandContext 

Source
pub struct CommandContext<'a> {
    pub raw: &'a str,
    pub base_command: String,
    pub words: Vec<String>,
    pub env_vars: Vec<(String, String)>,
    pub redirection: Option<Redirection>,
    pub accumulated_env: HashMap<String, String>,
}
Expand description

Context for evaluating a single command segment.

Fields§

§raw: &'a str

The full command text of this segment.

§base_command: String

The base command name (e.g. “git”, “ls”, “cargo”).

§words: Vec<String>

All words in the command (tokenized via shlex).

§env_vars: Vec<(String, String)>

Leading KEY=VALUE environment variable assignments.

§redirection: Option<Redirection>

Detected output redirection, if any.

§accumulated_env: HashMap<String, String>

Environment variables accumulated from prior segments in a compound command (e.g. export FOO=bar ; git push makes FOO=bar available to the git push segment).

Implementations§

Source§

impl<'a> CommandContext<'a>

Source

pub fn from_command(raw: &'a str) -> Self

Build a CommandContext from a raw command string.

Source

pub fn env_satisfies(&self, required: &HashMap<String, String>) -> bool

Check if all required env var entries are satisfied.

For each entry, checks the command’s inline env vars first (exact key+value match), then falls back to the process environment (std::env::var). Returns true only if ALL entries match. Some entries may come from inline env and others from the process environment — each is checked independently.

Config values are shell-expanded (~, $HOME, $VAR) before comparison, since shells expand these in env assignments before they reach the process.

Source

pub fn args(&self) -> &[String]

Get words after skipping env vars and the base command.

Source

pub fn has_flag(&self, flag: &str) -> bool

Check if any word matches a flag.

Source

pub fn has_any_flag(&self, flags: &[&str]) -> bool

Check if any word matches any of the given flags.

Trait Implementations§

Source§

impl<'a> Debug for CommandContext<'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for CommandContext<'a>

§

impl<'a> RefUnwindSafe for CommandContext<'a>

§

impl<'a> Send for CommandContext<'a>

§

impl<'a> Sync for CommandContext<'a>

§

impl<'a> Unpin for CommandContext<'a>

§

impl<'a> UnsafeUnpin for CommandContext<'a>

§

impl<'a> UnwindSafe for CommandContext<'a>

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> 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, 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.