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,
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"),
error_color: bunt::style!("#ff0000+bold+italic"),
};
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 runner
Enums
Functions
- Get stdout as a [
StandardStream
] - Clear the color style