Crate sprint

Source
Expand description

§About

The sprint crate provides the Shell struct which represents a shell session in your library or CLI code and can be used for running commands:

Shell exposes its properties so you can easily create a custom shell or modify an existing shell with the settings you want.

§Examples

§Run command(s) and show the output

use sprint::*;

let shell = Shell::default();

shell.run(&[Command::new("ls"), Command::new("ls -l")]);

// or equivalently:
//shell.run_str(&["ls", "ls -l"]);

§Run command(s) and return the output

use sprint::*;

let shell = Shell::default();

let results = shell.run(&[Command {
    command: String::from("ls"),
    stdout: Pipe::string(),
    codes: vec![0],
    ..Default::default()
}]);

assert_eq!(
    results[0].stdout,
    Pipe::String(Some(String::from("\
Cargo.lock
Cargo.toml
CHANGELOG.md
Makefile.md
README.md
src
t
target
tests
\
    "))),
);

§Customize

use sprint::*;

let shell = Shell {
    shell: Some(String::from("sh -c")),

    dry_run: false,
    sync: true,
    print: true,
    color: ColorOverride::Auto,

    fence: String::from("```"),
    info: String::from("text"),
    prompt: String::from("$ "),

    fence_style: style("#555555").expect("style"),
    info_style: style("#555555").expect("style"),
    prompt_style: style("#555555").expect("style"),
    command_style: style("#00ffff+bold").expect("style"),
    error_style: style("#ff0000+bold+italic").expect("style"),
};

shell.run(&[Command::new("ls"), Command::new("ls -l")]);

§Modify

use sprint::*;

let mut shell = Shell::default();

shell.shell = None;

shell.run(&[Command::new("ls"), Command::new("ls -l")]);

shell.sync = false;

shell.run(&[Command::new("ls"), Command::new("ls -l")]);

Structs§

Command
Shell
Command runner

Enums§

ColorOverride
Pipe

Functions§

style
Create a Style from a &str specification