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>
impl<'a> Sheller<'a>
sourcepub fn new(script: &'a str) -> Self
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());sourcepub fn build(self) -> Command
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());sourcepub fn run_with_config(self, config: &Config)
pub fn run_with_config(self, config: &Config)
sourcepub fn try_run_with_config(self, config: &Config) -> Result<(), Error>
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.