pub struct Command {
pub command_line: String,
pub working_dir: Option<PathBuf>,
pub env: HashMap<String, String>,
pub timeout: Option<Duration>,
pub capture_output: bool,
pub max_output_bytes: Option<u64>,
}Expand description
A command to be executed in a shell session.
Fields§
§command_line: StringThe command line to execute.
working_dir: Option<PathBuf>Working directory override (if any).
env: HashMap<String, String>Environment variables to set.
timeout: Option<Duration>Maximum execution time.
capture_output: boolWhether to capture output.
max_output_bytes: Option<u64>Cap on the output the result keeps, in bytes.
None means [super::executor::DEFAULT_MAX_OUTPUT_BYTES]. There is no
value meaning “unbounded” — see that constant.
Implementations§
Source§impl Command
impl Command
Sourcepub fn new(command_line: impl Into<String>) -> Self
pub fn new(command_line: impl Into<String>) -> Self
Create a new command with the given command line.
Sourcepub fn working_dir(self, dir: impl Into<PathBuf>) -> Self
pub fn working_dir(self, dir: impl Into<PathBuf>) -> Self
Set the working directory.
Sourcepub fn env(self, key: impl Into<String>, value: impl Into<String>) -> Self
pub fn env(self, key: impl Into<String>, value: impl Into<String>) -> Self
Add an environment variable.
Sourcepub fn capture_output(self, capture: bool) -> Self
pub fn capture_output(self, capture: bool) -> Self
Set whether to capture output.
Sourcepub fn max_output_bytes(self, bytes: u64) -> Self
pub fn max_output_bytes(self, bytes: u64) -> Self
Cap the output the result keeps.
Sourcepub fn effective_timeout(&self) -> Duration
pub fn effective_timeout(&self) -> Duration
The deadline this command will actually run under.
timeout records what the caller asked for; this is
what they get. Absent, it is [DEFAULT_TIMEOUT]; present, it is bounded
by [MIN_TIMEOUT] and [MAX_TIMEOUT] — the range docs/openapi.json
has published all along without anything enforcing it.
This is deliberately the only place the deadline is computed. It used
to be worked out twice — once in the blocking core to time the command
out, and once in execute_async to decide when a stalled streaming
consumer stops being waited on. Two copies of one rule is a bug waiting
for the first edit that reaches only one of them, and clamping was
exactly such an edit: applied to the first alone, a command would have
been killed at the ceiling while the stream went on being fed to a
consumer for the hours the caller originally named.