pub struct CommandSpec {
pub program: OsString,
pub args: Vec<OsString>,
pub cwd: Option<PathBuf>,
pub env: Option<HashMap<OsString, OsString>>,
}Expand description
Specification for a command to execute.
All process execution goes through this type to ensure argv-style invocation. This prevents shell injection attacks by ensuring arguments are passed as discrete elements rather than shell strings.
§Security
CommandSpec enforces that:
- Arguments are
Vec<OsString>, NOT shell strings - No shell string evaluation (
sh -c,cmd /C) is used - Arguments cross trust boundaries as discrete elements
§Example
use xchecker_utils::runner::CommandSpec;
use std::ffi::OsString;
let cmd = CommandSpec::new("claude")
.arg("--print")
.arg("--output-format")
.arg("json")
.cwd("/path/to/workspace");
assert_eq!(cmd.program, OsString::from("claude"));
assert_eq!(cmd.args.len(), 3);Fields§
§program: OsStringThe program to execute
args: Vec<OsString>Arguments as discrete elements (NOT shell strings)
cwd: Option<PathBuf>Optional working directory
env: Option<HashMap<OsString, OsString>>Optional environment overrides
Implementations§
Source§impl CommandSpec
impl CommandSpec
Sourcepub fn arg(self, arg: impl Into<OsString>) -> Self
pub fn arg(self, arg: impl Into<OsString>) -> Self
Add a single argument to the command.
Arguments are stored as discrete OsString elements, ensuring no shell
interpretation occurs.
§Arguments
arg- The argument to add. Can be any type that converts toOsString.
§Example
use xchecker_utils::runner::CommandSpec;
let cmd = CommandSpec::new("claude")
.arg("--print")
.arg("--verbose");Sourcepub fn args<I, S>(self, args: I) -> Self
pub fn args<I, S>(self, args: I) -> Self
Add multiple arguments to the command.
Arguments are stored as discrete OsString elements, ensuring no shell
interpretation occurs.
§Arguments
args- An iterator of arguments to add.
§Example
use xchecker_utils::runner::CommandSpec;
let cmd = CommandSpec::new("claude")
.args(["--print", "--output-format", "json"]);Sourcepub fn to_command(&self) -> Command
pub fn to_command(&self) -> Command
Convert this CommandSpec into a std::process::Command.
This is the primary way to execute a CommandSpec. The resulting Command
uses argv-style argument passing, ensuring no shell injection is possible.
§Example
use xchecker_utils::runner::CommandSpec;
let cmd = CommandSpec::new("echo")
.arg("hello")
.arg("world");
let output = cmd.to_command().output().expect("failed to execute");Sourcepub fn to_tokio_command(&self) -> TokioCommand
pub fn to_tokio_command(&self) -> TokioCommand
Convert this CommandSpec into a tokio::process::Command.
This is used for async execution with timeout support.
§Example
use xchecker_utils::runner::CommandSpec;
let cmd = CommandSpec::new("echo")
.arg("hello");
let output = cmd.to_tokio_command().output().await.expect("failed to execute");Trait Implementations§
Source§impl Clone for CommandSpec
impl Clone for CommandSpec
Source§fn clone(&self) -> CommandSpec
fn clone(&self) -> CommandSpec
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more