Trait cradle::CmdArgument[][src]

pub trait CmdArgument { }
Expand description

All types that are possible arguments to cmd! have to implement this trait.

Implementations on Foreign Types

Blanket implementation for &_.

Arguments of type &str are passed into the child process as arguments.

Arguments of type String are passed into the child process as arguments.

Allows to use split to split your argument into words:

use cradle::*;

let StdoutTrimmed(output) = cmd!("echo foo".split(' '));
assert_eq!(output, "foo");

Arguments to split must be of type char.

Allows to use split_whitespace to split your argument into words:

use cradle::*;

let StdoutTrimmed(output) = cmd!("echo foo".split_whitespace());
assert_eq!(output, "foo");

Allows to use split_ascii_whitespace to split your argument into words:

use cradle::*;

let StdoutTrimmed(output) = cmd!("echo foo".split_ascii_whitespace());
assert_eq!(output, "foo");

All elements of the given Vec are used as arguments to cmd!. Same as passing in the elements separately.

use cradle::*;

let StdoutTrimmed(output) = cmd!(vec!["echo", "foo"]);
assert_eq!(output, "foo");

Similar to the implementation for Vec<T>. All elements of the array will be used as arguments.

use cradle::*;

let StdoutTrimmed(output) = cmd!(["echo", "foo"]);
assert_eq!(output, "foo");

Only works on rust version 1.51 and up.

Similar to the implementation for Vec<T>. All elements of the slice will be used as arguments.

Implementors

Passing in LogCommand as an argument to cmd! will cause it to log the commands (including all arguments) to stderr. (This is similar bash’s -x option.)

use cradle::*;

cmd_unit!(LogCommand, %"echo foo");
// writes '+ echo foo' to stderr

Splits the contained string by whitespace (using split_whitespace) and uses the resulting words as separate arguments.

use cradle::*;

let StdoutTrimmed(output) = cmd!(Split("echo foo"));
assert_eq!(output, "foo");

Since this is such a common case, cradle also provides a syntactic shortcut for Split, the % symbol:

use cradle::*;

let StdoutTrimmed(output) = cmd!(%"echo foo");
assert_eq!(output, "foo");

By default child processes inherit the current directory from their parent. You can override this with CurrentDir:

use cradle::*;

let StdoutTrimmed(output) = cmd!("pwd", CurrentDir("/tmp"));
assert_eq!(output, "/tmp");

Paths that are relative to the parent’s current directory are allowed.