Struct Cmd

Source
pub struct Cmd {
    pub inner: Command,
    /* private fields */
}
Expand description

A fancier Command, see the crate’s top-level docs!

Fields§

§inner: Command

The inner Command, in case you need to access it

Implementations§

Source§

impl Cmd

Constructors

Source

pub fn new(command: impl AsRef<OsStr>, summary: impl Into<String>) -> Self

Create a new Command with an additional “summary” of what this is trying to do

Source§

impl Cmd

Builder APIs

Source

pub fn stdout_to_stderr(&mut self) -> &mut Self

Pipe stdout into stderr

This is useful for cases where you want your program to livestream the output of a command to give your user realtime feedback, but the command randomly writes some things to stdout, and you don’t want your own stdout tainted.

If the the “stdout_to_stderr_modern” feature is enabled, this will just do command.stdout(std::io::stderr());, which will actually let the two streams interleave and ideally do the best possible thing. In the future this will be enabled by default (once the MSRV is acceptable).

Otherwise, it will use a polyfilled implementation for output and status that captures child stdout and prints it to the parent stderr at the end. If using status, command.stderr(std::io::Inherit) will be forced on, ignoring your own settings for stderr.

Source

pub fn log(&mut self, strategy: impl Into<Option<LogStrategy>>) -> &mut Self

Set how executions of this command should logged, accepting:

You can explicitly invoke the selected logging with Cmd::log_command

Source

pub fn check(&mut self, checked: bool) -> &mut Self

Set whether Status::success should be checked after executions (except spawn, which doesn’t yet have a Status to check).

Defaults to true.

If true, an Err will be produced by those execution commands.

Executions which produce status will pass them to Cmd::maybe_check_status, which uses this setting.

Source§

impl Cmd

Execution APIs

Source

pub fn run(&mut self) -> Result<()>

Equivalent to Cmd::status, but doesn’t bother returning the actual status code (because it’s captured in the Result)

Source

pub fn spawn(&mut self) -> Result<Child>

Equivalent to std::process::Command::spawn, but logged and with the error wrapped.

Source

pub fn output(&mut self) -> Result<Output>

Equivalent to std::process::Command::output, but logged, with the error wrapped, and status checked (by default)

Source

pub fn status(&mut self) -> Result<ExitStatus>

Equivalent to std::process::Command::status but logged, with the error wrapped, and status checked (by default)

Source§

impl Cmd

Transparently forwarded std::process::Command APIs

Source

pub fn arg<S: AsRef<OsStr>>(&mut self, arg: S) -> &mut Self

Source

pub fn env<K, V>(&mut self, key: K, val: V) -> &mut Self
where K: AsRef<OsStr>, V: AsRef<OsStr>,

Source

pub fn envs<I, K, V>(&mut self, vars: I) -> &mut Self
where I: IntoIterator<Item = (K, V)>, K: AsRef<OsStr>, V: AsRef<OsStr>,

Source

pub fn env_remove<K: AsRef<OsStr>>(&mut self, key: K) -> &mut Self

Source

pub fn env_clear(&mut self) -> &mut Self

Source

pub fn current_dir<P: AsRef<Path>>(&mut self, dir: P) -> &mut Self

Source

pub fn stdin<T: Into<Stdio>>(&mut self, cfg: T) -> &mut Self

Source

pub fn stdout<T: Into<Stdio>>(&mut self, cfg: T) -> &mut Self

Source

pub fn stderr<T: Into<Stdio>>(&mut self, cfg: T) -> &mut Self

Source

pub fn get_program(&self) -> &OsStr

Source

pub fn get_args(&self) -> CommandArgs<'_>

Source

pub fn get_envs(&self) -> CommandEnvs<'_>

Source

pub fn get_current_dir(&self) -> Option<&Path>

Source§

impl Cmd

Diagnostic APIs (used internally, but available for yourself)

Source

pub fn check_status(&self, status: ExitStatus) -> Result<()>

Check Status::success, producing a contextful Error if it’s false.`

Source

pub fn maybe_check_status(&self, status: ExitStatus) -> Result<()>

Invoke Cmd::check_status if Cmd::check is true (defaults to true).

Source

pub fn log_command(&self)

Log the current Command using the method specified by Cmd::log (defaults to tracing::info!).

Auto Trait Implementations§

§

impl Freeze for Cmd

§

impl !RefUnwindSafe for Cmd

§

impl Send for Cmd

§

impl Sync for Cmd

§

impl Unpin for Cmd

§

impl !UnwindSafe for Cmd

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more