Cmd

Struct Cmd 

Source
pub struct Cmd { /* private fields */ }
Expand description

Cmd represents a single command.

It requires at least to set a command name. Command’s arguments and options are optional.

Note that using input/output redirection symbols (eg. |, >>, 2>) as command arguments will fail. Instead use Script.

Implementations§

Source§

impl Cmd

Source

pub fn new<S>(cmd: S) -> Self
where S: Into<String>,

Creates a new command with given name.

§Examples
Cmd::new("echo");
Source

pub fn with_args<S, T, I>(cmd: S, args: I) -> Self
where S: Into<String>, T: Into<String>, I: IntoIterator<Item = T>,

Creates a new command with given name and arguments.

§Examples
Cmd::with_args("ls", ["-l", "~"]);
Source

pub fn with_options<S>(cmd: S, options: CmdOptions) -> Self
where S: Into<String>,

Creates a new command with given name and options.

§Examples
Cmd::with_options("ls", CmdOptions::default());
Source

pub fn with_args_and_options<S, T, I>( cmd: S, args: I, options: CmdOptions, ) -> Self
where S: Into<String>, T: Into<String>, I: IntoIterator<Item = T>,

Creates a new command with given name, arguments and options.

§Examples
Cmd::with_args_and_options("ls", ["-l"], CmdOptions::default());
Source

pub fn parse(cmd_string: &str) -> Result<Self, CmdError>

Try to create a new command from given whitespace separated string. Notice that it will trim all whitespace characters.

§Examples
let cmd = Cmd::parse("ls -l /some/path").unwrap();
assert_eq!(cmd, Cmd::with_args("ls", ["-l", "/some/path"]));
Source

pub fn parse_with_options( cmd_string: &str, options: CmdOptions, ) -> Result<Self, CmdError>

Try to create a new command from given whitespace separated string and options. Notice that it will trim all whitespace characters.

§Examples
let cmd = Cmd::parse_with_options("ls -l /some/path", CmdOptions::default());
Source

pub fn set_args<S, I>(&mut self, args: I)
where S: Into<String>, I: IntoIterator<Item = S>,

Set a command arguments.

§Examples
let mut cmd = Cmd::new("ls");
cmd.set_args(["-la", "~"]);
Source

pub fn set_options(&mut self, options: CmdOptions)

Set a command options.

§Examples
let mut cmd = Cmd::new("ls");
cmd.set_options(CmdOptions::default());
Source

pub fn add_arg<S>(&mut self, arg: S)
where S: Into<String>,

Add a new argument to the end of argument list.

§Examples
let mut cmd = Cmd::new("ls");
cmd.add_arg("-l");
cmd.add_arg("/some/directory");
Source

pub fn cmd(&self) -> &str

Get command name.

Source

pub fn args(&self) -> &[String]

Get command arguments.

Source

pub fn options(&self) -> &CmdOptions

Get command options.

Source

pub fn options_mut(&mut self) -> &mut CmdOptions

Update command options via mutable reference.

§Examples
let mut cmd = Cmd::new("env");
cmd.options_mut().add_env("TEST_ENV_VAR", "value");

Trait Implementations§

Source§

impl Clone for Cmd

Source§

fn clone(&self) -> Cmd

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Cmd

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Cmd

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for Cmd

Source§

fn eq(&self, other: &Cmd) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Runnable for Cmd

Source§

fn bootstrap_cmd(&self, _process_dir: &Path) -> Result<Cmd, String>

This method should prepare process to run and return Cmd used to spawn a custom process. If you need to create some files for properly spawning a process, do it inside provided process_dir directory.
Source§

fn clean_after_fail(&self, process_dir: &Path) -> Result<(), String>

This method is called when process spawning fails. Notice that process_dir will be deleted automatically, so there is no need to delete it here.
Source§

impl Serialize for Cmd

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for Cmd

Source§

impl StructuralPartialEq for Cmd

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,