Trait sheller::CommandExt

source ·
pub trait CommandExt {
    // Required methods
    fn run(&mut self);
    fn run_with_config(&mut self, config: &Config);
    fn try_run(&mut self) -> Result<(), Error>;
    fn try_run_with_config(&mut self, config: &Config) -> Result<(), Error>;
}

Required Methods§

source

fn run(&mut self)

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

§Examples
use sheller::CommandExt;
use std::process::Command;

#[cfg(windows)]
fn example() {
    let mut command = Command::new("cmd.exe");
    command.args(["/D", "/S", "/C", "echo hello"]).run();
}

#[cfg(unix)]
fn example() {
    let mut command = Command::new("echo");
    command.arg("hello").run();
}

example();
§Panics

Panics if the command failed to run.

source

fn run_with_config(&mut self, config: &Config)

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

§Examples
use sheller::{CommandExt, Config};
use std::process::Command;

#[cfg(windows)]
fn example() {
    let mut command = Command::new("cmd.exe");
    let config = Config {
        prefix: "🦀 $ ".to_string(),
        ..Default::default()
    };
    command
        .args(["/D", "/S", "/C", "echo hello"])
        .run_with_config(&config);
}

#[cfg(unix)]
fn example() {
    let mut command = Command::new("echo");
    let config = Config {
        prefix: "🦀 $ ".to_string(),
        ..Default::default()
    };
    command.arg("hello").run_with_config(&config);
}
example();
§Panics

Panics if the command failed to run.

source

fn try_run(&mut self) -> Result<(), Error>

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

§Examples
use sheller::CommandExt;
use std::process::Command;

#[cfg(windows)]
fn example() {
    let mut command = Command::new("cmd.exe");
    command
        .args(["/D", "/S", "/C", "echo hello"])
        .try_run()
        .unwrap();
}

#[cfg(unix)]
fn example() {
    let mut command = Command::new("echo");
    command.arg("hello").try_run().unwrap();
}

example();
§Errors

Returns an Err if the command failed to run.

source

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

Run the 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::{CommandExt, Config};
use std::process::Command;
#[cfg(windows)]
fn example() {
    let mut command = Command::new("cmd.exe");
    let config = Config {
        prefix: "🦀 $ ".to_string(),
        ..Default::default()
    };
    command
        .args(["/D", "/S", "/C", "echo hello"])
        .try_run_with_config(&config)
        .unwrap();
}

#[cfg(unix)]
fn example() {
    let mut command = Command::new("echo");
    let config = Config {
        prefix: "🦀 $ ".to_string(),
        ..Default::default()
    };
    command.arg("hello").try_run_with_config(&config).unwrap();
}

example();
§Errors

Returns an Err if the command failed to run.

Implementations on Foreign Types§

source§

impl CommandExt for Command

source§

fn run(&mut self)

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

§Examples
use sheller::CommandExt;
use std::process::Command;

#[cfg(windows)]
fn example() {
    let mut command = Command::new("cmd.exe");
    command.args(["/D", "/S", "/C", "echo hello"]).run();
}

#[cfg(unix)]
fn example() {
    let mut command = Command::new("echo");
    command.arg("hello").run();
}

example();
§Panics

Panics if the command failed to run.

source§

fn run_with_config(&mut self, config: &Config)

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

§Examples
use sheller::{CommandExt, Config};
use std::process::Command;

#[cfg(windows)]
fn example() {
    let mut command = Command::new("cmd.exe");
    let config = Config {
        prefix: "🦀 $ ".to_string(),
        ..Default::default()
    };
    command
        .args(["/D", "/S", "/C", "echo hello"])
        .run_with_config(&config);
}

#[cfg(unix)]
fn example() {
    let mut command = Command::new("echo");
    let config = Config {
        prefix: "🦀 $ ".to_string(),
        ..Default::default()
    };
    command.arg("hello").run_with_config(&config);
}
example();
§Panics

Panics if the command failed to run.

source§

fn try_run(&mut self) -> Result<(), Error>

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

§Examples
use sheller::CommandExt;
use std::process::Command;

#[cfg(windows)]
fn example() {
    let mut command = Command::new("cmd.exe");
    command
        .args(["/D", "/S", "/C", "echo hello"])
        .try_run()
        .unwrap();
}

#[cfg(unix)]
fn example() {
    let mut command = Command::new("echo");
    command.arg("hello").try_run().unwrap();
}

example();
§Errors

Returns an Err if the command failed to run.

source§

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

Run the 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::{CommandExt, Config};
use std::process::Command;

#[cfg(windows)]
fn example() {
    let mut command = Command::new("cmd.exe");
    let config = Config {
        prefix: "🦀 $ ".to_string(),
        ..Default::default()
    };
    command
        .args(["/D", "/S", "/C", "echo hello"])
        .try_run_with_config(&config)
        .unwrap();
}

#[cfg(unix)]
fn example() {
    let mut command = Command::new("echo");
    let config = Config {
        prefix: "🦀 $ ".to_string(),
        ..Default::default()
    };
    command.arg("hello").try_run_with_config(&config).unwrap();
}

example();
§Errors

Returns an Err if the command failed to run.

Implementors§