Command-Builder
I thought that the std::process::Command
was not ergonomic to use, mostly due
to it's transient nature. This crate facilitates an ergonomic and
reusable/printable wrapper around the Command
process. I implement Debug
(which displays like a sh script) as well as the set of common logical operators
(&&
, ||
, |
, ;
) to use shell commands.
Motivating Example
// I was interested in bundling a set of commands, then exporting them with certain environmental variables set.
// For debugging purposes, I wanted to see what commands had been run . I ended up with functions like this:
;
// This would call a command like so:
// brew install (opts)* primary_arg
// plus the env configuration. I was also handling logic like
if test_for_brew? else
// when my mental model was
brew 2&> /null && brew command
// The last pain point was debug. I wanted non-transient commands to exist. This would allow me to collect
// and search previous commands.
This library wrappes the std::process::Command
with a struct that holds the
information necessary to compute the command. This struct is then clonable,
printable (with debug)
Using command-builder
use ;
let grep_for = new.a.a;
let direct_input = "lorim ipsum, spelling in latin is hard.";
let latin_file = new.a;
let searched_file = latin_file.pipe;
let direct_search = grep_for.input;
// Is the file what we expect?
searched_file.run?.stdout == direct_seach.run?.stdout
// confirm the commands were right
println!;
// cat file_name | grep ip -c
println!;
// grep ip -c < "lorim ipsum, spelling in latin is hard."