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
impl Cmd
Sourcepub fn with_options<S>(cmd: S, options: CmdOptions) -> Self
pub fn with_options<S>(cmd: S, options: CmdOptions) -> Self
Creates a new command with given name and options.
§Examples
Cmd::with_options("ls", CmdOptions::default());Sourcepub fn with_args_and_options<S, T, I>(
cmd: S,
args: I,
options: CmdOptions,
) -> Self
pub fn with_args_and_options<S, T, I>( cmd: S, args: I, options: CmdOptions, ) -> Self
Creates a new command with given name, arguments and options.
§Examples
Cmd::with_args_and_options("ls", ["-l"], CmdOptions::default());Sourcepub fn parse(cmd_string: &str) -> Result<Self, CmdError>
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"]));Sourcepub fn parse_with_options(
cmd_string: &str,
options: CmdOptions,
) -> Result<Self, CmdError>
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());Sourcepub fn set_options(&mut self, options: CmdOptions)
pub fn set_options(&mut self, options: CmdOptions)
Set a command options.
§Examples
let mut cmd = Cmd::new("ls");
cmd.set_options(CmdOptions::default());Sourcepub fn add_arg<S>(&mut self, arg: S)
pub fn add_arg<S>(&mut self, arg: S)
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");Sourcepub fn options(&self) -> &CmdOptions
pub fn options(&self) -> &CmdOptions
Get command options.
Sourcepub fn options_mut(&mut self) -> &mut CmdOptions
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<'de> Deserialize<'de> for Cmd
impl<'de> Deserialize<'de> for Cmd
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
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 Runnable for Cmd
impl Runnable for Cmd
impl Eq for Cmd
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> 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