Struct bkt::CommandDesc
source · [−]pub struct CommandDesc { /* private fields */ }
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
sourceimpl CommandDesc
impl CommandDesc
sourcepub fn new<I, S>(command: I) -> Self where
I: IntoIterator<Item = S>,
S: Into<OsString>,
pub fn new<I, S>(command: I) -> Self where
I: IntoIterator<Item = S>,
S: Into<OsString>,
Constructs a CommandDesc instance for the given command line.
let cmd = bkt::CommandDesc::new(["echo", "Hello World!"]);
sourcepub fn with_working_dir<P: AsRef<Path>>(self, cwd: P) -> Self
pub fn with_working_dir<P: AsRef<Path>>(self, cwd: P) -> Self
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");
sourcepub fn with_cwd(self) -> Result<Self>
pub fn with_cwd(self) -> Result<Self>
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()?;
sourcepub fn with_env_value<K, V>(self, key: K, value: V) -> Self where
K: AsRef<OsStr>,
V: AsRef<OsStr>,
pub fn with_env_value<K, V>(self, key: K, value: V) -> Self where
K: AsRef<OsStr>,
V: AsRef<OsStr>,
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");
sourcepub fn with_env<K>(self, key: K) -> Self where
K: AsRef<OsStr>,
pub fn with_env<K>(self, key: K) -> Self where
K: AsRef<OsStr>,
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");
sourcepub fn with_envs<I, K, V>(self, envs: I) -> Self where
I: IntoIterator<Item = (K, V)>,
K: AsRef<OsStr>,
V: AsRef<OsStr>,
pub fn with_envs<I, K, V>(self, envs: I) -> Self where
I: IntoIterator<Item = (K, V)>,
K: AsRef<OsStr>,
V: AsRef<OsStr>,
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
sourceimpl Clone for CommandDesc
impl Clone for CommandDesc
sourcefn clone(&self) -> CommandDesc
fn clone(&self) -> CommandDesc
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Debug for CommandDesc
impl Debug for CommandDesc
sourceimpl<'de> Deserialize<'de> for CommandDesc
impl<'de> Deserialize<'de> for CommandDesc
sourcefn 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
sourceimpl From<&'_ CommandDesc> for Command
impl From<&'_ CommandDesc> for Command
sourcefn from(desc: &CommandDesc) -> Self
fn from(desc: &CommandDesc) -> Self
Converts to this type from the input type.
sourceimpl Hash for CommandDesc
impl Hash for CommandDesc
sourceimpl PartialEq<CommandDesc> for CommandDesc
impl PartialEq<CommandDesc> for CommandDesc
sourcefn eq(&self, other: &CommandDesc) -> bool
fn eq(&self, other: &CommandDesc) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourcefn ne(&self, other: &CommandDesc) -> bool
fn ne(&self, other: &CommandDesc) -> bool
This method tests for !=
.
sourceimpl Serialize for CommandDesc
impl Serialize for CommandDesc
impl Eq for CommandDesc
impl StructuralEq for CommandDesc
impl StructuralPartialEq for CommandDesc
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more