Expand description
A zx-compatible API (modelled on google/zx 8.x) for writing shell scripts in Rust.
The core pieces mirror zx:
Shellis the$: a command factory carryingOptions(cwd, env, shell, prefix, verbose, quiet, nothrow, timeout, …). Thezx!macro interpolates arguments with zx quoting ($'...'for bash).ProcessPromiseis a configured command;.await(orrun) yieldsOk(ProcessOutput)on success andErr(ProcessOutput)on failure unlessnothrowis set.ProcessOutputholds stdout, stderr, stdall, the exit code, signal and duration, and formats zx-style error messages.within,configureandcdprovide scoped settings, and the goods (sleep,retry,spinner,tempdir,parse_argv, …) cover the script helpers.
use command_stream::zx;
use command_stream::zx::Shell;
let name = "hello world";
let out = zx!("echo {}", name).await?;
assert_eq!(out.stdout, "hello world\n");
let failed = zx!(Shell::new().nothrow(true), "exit 3").await?;
assert_eq!(failed.exit_code, Some(3));Re-exports§
pub use argv::minimist;pub use argv::parse_argv;pub use argv::ArgvOptions;pub use argv::Booleans;pub use error::ZxError;pub use goods::echo;pub use goods::exp_backoff;pub use goods::glob;pub use goods::retry;pub use goods::retry_with_backoff;pub use goods::retry_with_delay;pub use goods::sleep;pub use goods::spinner;pub use goods::tempdir;pub use goods::tempfile;pub use goods::which;pub use kill::kill;pub use log::format_cmd;pub use log::LogEntry;pub use log::Logger;pub use md::transform_markdown;pub use output::ErrorInfo;pub use output::ProcessOutput;pub use process::PipeFrom;pub use process::ProcessPromise;pub use process::RunningProcess;pub use process::ZxResult;pub use shell::cd;pub use shell::configure;pub use shell::current_options;pub use shell::use_bash;pub use shell::use_powershell;pub use shell::use_pwsh;pub use shell::within;pub use shell::within_sync;pub use shell::Options;pub use shell::PreferLocal;pub use shell::Shell;pub use util::parse_duration;pub use util::quote;pub use util::quote_powershell;pub use util::IntoZxArg;pub use util::ZxArg;
Modules§
- argv
- Command line parsing compatible with
minimist(as re-exported by zx) and zx’sparseArgvwrapper. - dotenv
.envparsing and serialization (thedotenvhelpers zx re-exports).- error
- zx-compatible failure formatting (
Failhelpers): exit code and errno descriptions plus the multi-line messages attached to failed commands. - goods
- zx “goods”: small helpers for scripts (
sleep,retry,spinner, …). - kill
- Process-tree termination (zx
kill(pid, signal)). - log
- Verbose logging (zx
log) and the command highlighter (zxformatCmd). - md
- Markdown to script transform (zx
transformMarkdown). - output
ProcessOutput: the settled result of a zx command.- process
ProcessPromise(a prepared zx command) andRunningProcess(a spawned one), plus the runner that drives the child processes.- shell
- The
Shellbuilder (zx$), its options and the scoped defaults used bywithin,configureandcd. - util
- Small helpers shared by the zx-compatible API: quoting, duration parsing, command assembly and name normalisation.