Command-line library for writing rust style shell scripts
Common rust command-line macros and utilities, to write shell-script like tasks easily in rust programming language. Available at crates.io.
run_cmd! --> CmdResult
let name = "rust";
run_cmd!?;
run_cmd!?;
// pipe commands are also supported
run_cmd!?;
// or a group of commands
// if any command fails, just return Err(...)
let file = "/tmp/f";
let keyword = "rust";
if run_cmd! .is_err
run_fun! --> FunResult
let version = run_fun!.unwrap;
eprintln!;
// with pipes
let n = run_fun!.unwrap;
eprintln!;
Run pipe commands in the builder style
These are low level APIs, without using macros. Parameters could be passed much clearer in this style:
.pipe
.pipe
.?;
// the same run_cmd! macro
run_cmd!?;
new
.pipe
.current_dir
.?;
new
Builtin commands
cd
cd: set procecess current directory
run_cmd! ;
Notice that builtin cd
will only change with current scope
and it will restore the previous current directory when it
exits the scope.
Use std::env::set_current_dir
if you want to change the current
working directory for the whole program.
Complete Example
use ;
Related
See rust-shell-script, which can compile rust-shell-script scripting language directly into rust code.