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.
If arguments was not specified during Cmd creation, it will create new argument list with given argument.
§Examples
let mut cmd = Cmd::new("ls");
cmd.add_arg("-l");
cmd.add_arg("/some/directory");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");