Struct bkt::CommandDesc [−][src]
pub struct CommandDesc { /* fields omitted */ }
Expand description
Describes a command to be executed and cached. This struct also serves as the cache key. It consists of a command line invocation and, optionally, a working directory to execute in and environment variables to set. When set these fields contribute to the cache key, therefore two invocations with different working directories set will be cached separately.
let cmd = bkt::CommandDesc::new(&["echo", "Hello World!"]);
let with_cwd = bkt::CommandDesc::new(&["ls"]).with_working_dir("/tmp");
let with_env = bkt::CommandDesc::new(&["date"]).with_env_value("TZ", "America/New_York");
Implementations
Constructs a CommandDesc instance for the given command line.
let cmd = bkt::CommandDesc::new(&["echo", "Hello World!"]);
Sets the working directory the command should be run from, and causes the working directory to be included in the cache key. If unset the working directory will be inherited from the current process’ and will not be used to differentiate invocations in separate working directories.
let cmd = bkt::CommandDesc::new(&["pwd"]).with_working_dir("/tmp");
Sets the working directory to the current process’ working directory. This has no effect on the subprocess that will be executed (assuming the current process’ working directory remains unchanged) but does cause the working directory to be included in the cache key. Commands that depend on the working directory should call this in order to cache executions in different working directories separately.
Errors
This delegates to std::env::current_dir()
and will fail if it does.
Examples
let cmd = bkt::CommandDesc::new(&["pwd"]).with_cwd()?;
Adds the given key/value pair to the environment the command should be run from, and causes this pair to be included in the cache key.
let cmd = bkt::CommandDesc::new(&["pwd"]).with_env_value("FOO", "bar");
Looks up the given environment variable in the current process’ environment and, if set, adds that key/value pair to the environment the command should be run from, and causes this pair to be included in the cache key. This has no effect on the subprocess that will be executed (assuming the current process’ environment remains unchanged).
If the given variable name is not found in the current process’ environment this call is a no-op, and the cache key will remain unchanged.
let cmd = bkt::CommandDesc::new(&["date"]).with_env("TZ");
Adds the given key/value pairs to the environment the command should be run from, and causes these pair to be included in the cache key.
use std::env;
use std::collections::HashMap;
let important_envs : HashMap<String, String> =
env::vars().filter(|&(ref k, _)|
k == "TERM" || k == "TZ" || k == "LANG" || k == "PATH"
).collect();
let cmd = bkt::CommandDesc::new(&["..."]).with_envs(&important_envs);
Trait Implementations
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
Performs the conversion.
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
This method tests for !=
.
Auto Trait Implementations
impl RefUnwindSafe for CommandDesc
impl Send for CommandDesc
impl Sync for CommandDesc
impl Unpin for CommandDesc
impl UnwindSafe for CommandDesc
Blanket Implementations
Mutably borrows from an owned value. Read more