pub struct Command { /* private fields */ }Implementations§
Source§impl Command
impl Command
pub fn new(value: impl AsRef<OsStr>) -> Self
pub fn argument(self, value: impl AsRef<OsStr>) -> Self
pub fn optional_argument(self, optional: Option<impl AsRef<OsStr>>) -> Self
Sourcepub fn optional_flag(self, condition: bool, flag: impl AsRef<OsStr>) -> Self
pub fn optional_flag(self, condition: bool, flag: impl AsRef<OsStr>) -> Self
Adds a flag argument only if the condition is true.
let verbose = true;
cmd_proc::Command::new("echo")
.optional_flag(verbose, "--verbose");Sourcepub fn option(self, name: impl AsRef<OsStr>, value: impl AsRef<OsStr>) -> Self
pub fn option(self, name: impl AsRef<OsStr>, value: impl AsRef<OsStr>) -> Self
Adds a CLI option (name + value).
cmd_proc::Command::new("git")
.option("--message", "hello");
// equivalent to: .argument("--message").argument("hello")Sourcepub fn optional_option(
self,
name: impl AsRef<OsStr>,
value: Option<impl AsRef<OsStr>>,
) -> Self
pub fn optional_option( self, name: impl AsRef<OsStr>, value: Option<impl AsRef<OsStr>>, ) -> Self
Adds a CLI option (name + value) only if the value is Some.
cmd_proc::Command::new("git")
.optional_option("--author", Some("Alice"));
// adds "--author Alice" only if Somepub fn arguments<T: AsRef<OsStr>>( self, value: impl IntoIterator<Item = T>, ) -> Self
pub fn working_directory(self, dir: impl AsRef<Path>) -> Self
pub fn env(self, key: &EnvVariableName<'_>, val: impl AsRef<OsStr>) -> Self
pub fn envs<'a, I, V>(self, vars: I) -> Self
Sourcepub fn env_remove(self, key: &EnvVariableName<'_>) -> Self
pub fn env_remove(self, key: &EnvVariableName<'_>) -> Self
Remove an environment variable from the child process.
pub fn stdin_bytes(self, data: impl Into<Vec<u8>>) -> Self
Sourcepub fn stdout_capture(self) -> CaptureSingle<Stdout>
pub fn stdout_capture(self) -> CaptureSingle<Stdout>
Capture stdout from this command.
Sourcepub fn stderr_capture(self) -> CaptureSingle<Stderr>
pub fn stderr_capture(self) -> CaptureSingle<Stderr>
Capture stderr from this command.
Sourcepub fn stdout_null(self) -> Self
pub fn stdout_null(self) -> Self
Redirect stdout to /dev/null.
Sourcepub fn stderr_null(self) -> Self
pub fn stderr_null(self) -> Self
Redirect stderr to /dev/null.
Sourcepub fn stdout_inherit(self) -> Self
pub fn stdout_inherit(self) -> Self
Inherit stdout from the parent process (default).
Sourcepub fn stderr_inherit(self) -> Self
pub fn stderr_inherit(self) -> Self
Inherit stderr from the parent process (default).
Sourcepub fn build(self) -> Command
pub fn build(self) -> Command
Consume the builder and return the underlying tokio::process::Command.
Use this when you need full control over the child process (e.g. interactive stdin/stdout piping) beyond what the capture API provides.
Sourcepub async fn status(self) -> Result<(), CommandError>
pub async fn status(self) -> Result<(), CommandError>
Execute the command and return success or an error.
Auto Trait Implementations§
impl Freeze for Command
impl !RefUnwindSafe for Command
impl Send for Command
impl Sync for Command
impl Unpin for Command
impl !UnwindSafe for Command
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more