Struct FloweyShell
pub struct FloweyShell { /* private fields */ }Expand description
A wrapper around [xshell::Shell] that supports transparent command
wrapping via an optional CommandWrapperKind.
Implements Deref<Target = xshell::Shell> so that existing usages like
rt.sh.change_dir() and rt.sh.set_var() continue to work unchanged.
Implementations§
§impl FloweyShell
impl FloweyShell
pub fn new() -> Result<FloweyShell, Error>
pub fn new() -> Result<FloweyShell, Error>
Create a new FloweyShell with no command wrapper.
pub fn set_wrapper(&mut self, wrapper: Option<CommandWrapperKind>)
pub fn set_wrapper(&mut self, wrapper: Option<CommandWrapperKind>)
Set (or clear) the command wrapper used for all commands created through this shell.
pub fn xshell(&self) -> &Shell
pub fn xshell(&self) -> &Shell
Access the underlying [xshell::Shell].
This is primarily used by the shell_cmd!
macro to pass the shell reference into [xshell::cmd!].
pub fn wrap<'a>(&'a self, cmd: Cmd<'a>) -> FloweyCmd<'a>
pub fn wrap<'a>(&'a self, cmd: Cmd<'a>) -> FloweyCmd<'a>
Wrap an [xshell::Cmd] into a FloweyCmd that will apply
this shell’s CommandWrapperKind (if any) at execution time.
Methods from Deref<Target = Shell>§
pub fn current_dir(&self) -> PathBuf
pub fn current_dir(&self) -> PathBuf
Returns the working directory for this [Shell].
All relative paths are interpreted relative to this directory, rather
than std::env::current_dir.
pub fn change_dir<P>(&self, dir: P)
pub fn change_dir<P>(&self, dir: P)
Changes the working directory for this [Shell].
Note that this doesn’t affect std::env::current_dir.
pub fn push_dir<P>(&self, path: P) -> PushDir<'_>
pub fn push_dir<P>(&self, path: P) -> PushDir<'_>
Temporary changes the working directory of this [Shell].
Returns a RAII guard which reverts the working directory to the old value when dropped.
Note that this doesn’t affect std::env::current_dir.
pub fn var<K>(&self, key: K) -> Result<String, Error>
pub fn var<K>(&self, key: K) -> Result<String, Error>
Fetches the environmental variable key for this [Shell].
Returns an error if the variable is not set, or set to a non-utf8 value.
Environment of the [Shell] affects all commands spawned via this
shell.
pub fn set_var<K, V>(&self, key: K, val: V)
pub fn set_var<K, V>(&self, key: K, val: V)
Sets the value of key environment variable for this [Shell] to
val.
Note that this doesn’t affect std::env::var.
pub fn push_env<K, V>(&self, key: K, val: V) -> PushEnv<'_>
pub fn push_env<K, V>(&self, key: K, val: V) -> PushEnv<'_>
Temporary sets the value of key environment variable for this
[Shell] to val.
Returns a RAII guard which restores the old environment when dropped.
Note that this doesn’t affect std::env::var.
pub fn read_file<P>(&self, path: P) -> Result<String, Error>
pub fn read_file<P>(&self, path: P) -> Result<String, Error>
Read the entire contents of a file into a string.
pub fn read_binary_file<P>(&self, path: P) -> Result<Vec<u8>, Error>
pub fn read_binary_file<P>(&self, path: P) -> Result<Vec<u8>, Error>
Read the entire contents of a file into a vector of bytes.
pub fn read_dir<P>(&self, path: P) -> Result<Vec<PathBuf>, Error>
pub fn read_dir<P>(&self, path: P) -> Result<Vec<PathBuf>, Error>
Returns a sorted list of paths directly contained in the directory at
path.
pub fn write_file<P, C>(&self, path: P, contents: C) -> Result<(), Error>
pub fn write_file<P, C>(&self, path: P, contents: C) -> Result<(), Error>
Write a slice as the entire contents of a file.
This function will create the file and all intermediate directories if they don’t exist.
pub fn copy_file<S, D>(&self, src: S, dst: D) -> Result<(), Error>
pub fn copy_file<S, D>(&self, src: S, dst: D) -> Result<(), Error>
Copies src into dst.
src must be a file, but dst need not be. If dst is an existing
directory, src will be copied into a file in the dst directory whose
name is same as that of src.
Otherwise, dst is a file or does not exist, and src will be copied into
it.
pub fn create_dir<P>(&self, path: P) -> Result<PathBuf, Error>
pub fn create_dir<P>(&self, path: P) -> Result<PathBuf, Error>
Creates the specified directory.
All intermediate directories will also be created.
pub fn create_temp_dir(&self) -> Result<TempDir, Error>
pub fn create_temp_dir(&self) -> Result<TempDir, Error>
Creates an empty named world-readable temporary directory.
Returns a [TempDir] RAII guard with the path to the directory. When
dropped, the temporary directory and all of its contents will be
removed.
Note that this is an insecure method – any other process on the system will be able to read the data.
pub fn remove_path<P>(&self, path: P) -> Result<(), Error>
pub fn remove_path<P>(&self, path: P) -> Result<(), Error>
Removes the file or directory at the given path.
pub fn path_exists<P>(&self, path: P) -> bool
pub fn path_exists<P>(&self, path: P) -> bool
Returns whether a file or directory exists at the given path.