pub struct CommandState { /* private fields */ }
Expand description
The stateful sibling of CommandDesc
which represents a command to be executed and cached
along with environment state (e.g. the current working directory) at the time the CommandState
instance is constructed. It consists of a command line invocation and application state
determining how the command should be cached and executed. Additional with_*
methods are
provided on this type for further modifying how the subprocess will be executed.
Calling any of these methods changes how the invocation’s cache key will be constructed,
therefore two invocations with different configured state will be cached separately, in the same
manner as the with_*
methods on CommandDesc
.
§Examples
let cmd = bkt::CommandDesc::new(["echo", "Hello World!"]).capture_state();
let with_custom_wd = bkt::CommandDesc::new(["ls"]).capture_state()?.with_working_dir("/");
let with_env = bkt::CommandDesc::new(["date"]).capture_state()?.with_env("TZ", "UTC");
Implementations§
source§impl CommandState
impl CommandState
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 this 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"]);
let state = cmd.capture_state()?.with_working_dir("/tmp");
sourcepub fn with_env<K, V>(self, key: K, value: V) -> Self
pub fn with_env<K, V>(self, key: K, value: V) -> Self
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"]);
let state = cmd.capture_state()?.with_env("FOO", "bar");
sourcepub fn with_envs<I, K, V>(self, envs: I) -> Self
pub fn with_envs<I, K, V>(self, envs: I) -> Self
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(["..."]);
let state = cmd.capture_state()?.with_envs(&important_envs);
Trait Implementations§
source§impl Clone for CommandState
impl Clone for CommandState
source§fn clone(&self) -> CommandState
fn clone(&self) -> CommandState
1.6.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for CommandState
impl Debug for CommandState
source§impl<'de> Deserialize<'de> for CommandState
impl<'de> Deserialize<'de> for CommandState
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>,
source§impl From<&CommandState> for Command
impl From<&CommandState> for Command
source§fn from(cmd: &CommandState) -> Self
fn from(cmd: &CommandState) -> Self
source§impl Hash for CommandState
impl Hash for CommandState
source§impl PartialEq for CommandState
impl PartialEq for CommandState
source§impl Serialize for CommandState
impl Serialize for CommandState
source§impl TryFrom<&CommandDesc> for CommandState
impl TryFrom<&CommandDesc> for CommandState
impl Eq for CommandState
impl StructuralPartialEq for CommandState
Auto Trait Implementations§
impl Freeze for CommandState
impl RefUnwindSafe for CommandState
impl Send for CommandState
impl Sync for CommandState
impl Unpin for CommandState
impl UnwindSafe for CommandState
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)