FloweyShell

Struct FloweyShell 

Source
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§

Source§

impl FloweyShell

Source

pub fn new() -> Result<Self>

Create a new FloweyShell with no command wrapper.

Source

pub fn set_wrapper(&mut self, wrapper: Option<CommandWrapperKind>)

Set (or clear) the command wrapper used for all commands created through this shell.

Source

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!].

Source

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

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)
where P: AsRef<Path>,

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<'_>
where P: AsRef<Path>,

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>
where K: AsRef<OsStr>,

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 var_os<K>(&self, key: K) -> Option<OsString>
where K: AsRef<OsStr>,

Fetches the environmental variable key for this [Shell] as OsString Returns None if the variable is not set.

Environment of the [Shell] affects all commands spawned via this shell.

pub fn set_var<K, V>(&self, key: K, val: V)
where K: AsRef<OsStr>, V: AsRef<OsStr>,

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<'_>
where K: AsRef<OsStr>, V: AsRef<OsStr>,

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>
where P: AsRef<Path>,

Read the entire contents of a file into a string.

pub fn read_binary_file<P>(&self, path: P) -> Result<Vec<u8>, Error>
where P: AsRef<Path>,

Read the entire contents of a file into a vector of bytes.

pub fn read_dir<P>(&self, path: P) -> Result<Vec<PathBuf>, Error>
where P: AsRef<Path>,

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>
where P: AsRef<Path>, C: AsRef<[u8]>,

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>
where S: AsRef<Path>, D: AsRef<Path>,

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.

Hardlinks src to dst.

pub fn create_dir<P>(&self, path: P) -> Result<PathBuf, Error>
where P: AsRef<Path>,

Creates the specified directory.

All intermediate directories will also be created.

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>
where P: AsRef<Path>,

Removes the file or directory at the given path.

pub fn path_exists<P>(&self, path: P) -> bool
where P: AsRef<Path>,

Returns whether a file or directory exists at the given path.

pub fn cmd<P>(&self, program: P) -> Cmd<'_>
where P: AsRef<Path>,

Creates a new [Cmd] that executes the given program.

Trait Implementations§

Source§

impl Deref for FloweyShell

Source§

type Target = Shell

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Shell

Dereferences the value.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.