Struct sheller::Sheller

source ยท
pub struct Sheller<'a> { /* private fields */ }
Expand description

Sheller is a builder for std::process::Command that sets the shell program and arguments.

Please see the Sheller::new method for more information.

Implementationsยง

sourceยง

impl<'a> Sheller<'a>

source

pub fn new(script: &'a str) -> Self

Create a new Sheller with the given script and platform-specific defaults.

ยงPlatform-specific defaults
ยงWindows

When target_family is windows.

Set the COMSPEC environment variable to program, and if the environment variable is not set, use cmd.exe as the fallback program.

Also set the args to ["/D", "/S", "/C"].

ยงUnix

When target_family is unix.

Set the SHELL environment variable to program, and if the environment variable is not set, use /bin/sh as the fallback program.

Also set the args to ["-c"].

ยงArguments
  • script - The shell script to run. This is dependent on the shell program.
ยงExamples
use sheller::Sheller;

let mut command = Sheller::new("echo hello").build();
assert!(command.status().unwrap().success());
source

pub fn build(self) -> Command

Returns std::process::Command with the shell program and arguments set.

ยงExamples
use sheller::Sheller;

let mut command = Sheller::new("echo hello").build();
assert!(command.status().unwrap().success());
source

pub fn run(self)

Run the shell command and panic if the command failed to run.

ยงExamples
use sheller::{Sheller, CommandExt};
let sheller = Sheller::new("echo hello");
sheller.run();
ยงPanics

Panics if the command failed to run.

source

pub fn try_run(self) -> Result<(), Error>

Run the shell command and return a Result with Ok if the command was successful, and Err if the command failed.

ยงExamples
use sheller::{Sheller, CommandExt};
let sheller = Sheller::new("echo hello");
sheller.try_run().unwrap();
ยงErrors

Returns an Err if the command failed to run.

source

pub fn run_with_config(self, config: &Config)

Run the shell command with the given config and panic if the command failed to run.

ยงExamples
use sheller::{Sheller, Config, CommandExt};
let sheller = Sheller::new("echo hello");
let config = Config::default();
sheller.run_with_config(&config);
ยงPanics

Panics if the command failed to run.

source

pub fn try_run_with_config(self, config: &Config) -> Result<(), Error>

Run the shell command with the given config and return a Result with Ok if the command was successful, and Err if the command failed.

ยงExamples
use sheller::{Sheller, Config, CommandExt};
let sheller = Sheller::new("echo hello");
let config = Config::default();
sheller.try_run_with_config(&config).unwrap();
ยงErrors

Returns an Err if the command failed to run.

Trait Implementationsยง

sourceยง

impl<'a> Debug for Sheller<'a>

sourceยง

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
sourceยง

impl Default for Sheller<'_>

sourceยง

fn default() -> Self

Returns the โ€œdefault valueโ€ for a type. Read more

Auto Trait Implementationsยง

ยง

impl<'a> RefUnwindSafe for Sheller<'a>

ยง

impl<'a> Send for Sheller<'a>

ยง

impl<'a> Sync for Sheller<'a>

ยง

impl<'a> Unpin for Sheller<'a>

ยง

impl<'a> UnwindSafe for Sheller<'a>

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> Instrument for T

sourceยง

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
sourceยง

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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<T, U> TryFrom<U> for T
where U: Into<T>,

ยง

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>,

ยง

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.
sourceยง

impl<T> WithSubscriber for T

sourceยง

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
sourceยง

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more