Documentation

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(&["ls", "ls -l"]).unwrap();

Run command(s) and return the output

use sprint::*;

let shell = Shell::default();

assert_eq!(
    shell.pipe(&["ls"]),
    vec![(
      String::from(
          "\
Cargo.lock
Cargo.toml
CHANGELOG.md
Makefile.md
README.md
src
t
target
tests
\
          ",
      ),
      String::default(),
      Some(0),
    )],
);

Customize

use sprint::*;

let shell = Shell {
    // Common options

    // Shell
    shell: Some(String::from("sh -c")),
    //shell: None, // Run directly

    // ---

    // Options for run, run_check

    // Print extra content

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

    fence_color: bunt::style!("#555555"),
    info_color: bunt::style!("#555555"),
    prompt_color: bunt::style!("#555555"),
    command_color: bunt::style!("#00ffff+bold"),

    print: true,

    // Don't run command(s)
    dry_run: false,
    //dry_run: true,

    // ---

    // Options for pipe, pipe_with

    // Run commands synchronously
    sync: true,
    //sync: false,
};

shell.run(&["ls", "ls -l"]).unwrap();

Modify

use sprint::*;

let mut shell = Shell::default();

shell.shell = None;
shell.sync = false;

let results = shell.pipe(&["ls", "ls -l"]);

Changelog

  • 0.1.0 (2023-12-22): Initial release