pub struct CommandContext {
pub base_command: String,
pub words: Vec<Word>,
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§
§base_command: StringThe base command name (e.g. “git”, “ls”, “cargo”).
words: Vec<Word>All words in the command (pre-tokenized by tree-sitter or 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 CommandContext
impl CommandContext
Sourcepub fn from_command(raw: &str) -> Self
pub fn from_command(raw: &str) -> Self
Build a CommandContext from a raw command string.
Used for simple (non-compound) command evaluation and in tests.
Sourcepub fn from_segment(segment: &ShellSegment) -> Self
pub fn from_segment(segment: &ShellSegment) -> Self
Build a CommandContext from a parsed ShellSegment.
Uses the segment’s pre-tokenized words field directly — tree-sitter
already handles word boundaries correctly, including preserving
substitution syntax ($(...), backticks) as single tokens.
Redirection is detected by parsing the segment’s command text (inline
redirections like cat > file) or inherited from the segment’s
redirection field (wrapping-construct redirections like for ... done > file).
Sourcepub fn env_satisfies(&self, required: &HashMap<String, String>) -> bool
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.
Sourcepub fn has_any_flag(&self, flags: &[&str]) -> bool
pub fn has_any_flag(&self, flags: &[&str]) -> bool
Check if any word matches any of the given flags.