Files
sausage/userland/brush/source/docs/reference/examples.md
T
2026-11-11 22:04:16 +00:00

2.1 KiB

Examples

Each crate that has something to demonstrate keeps runnable examples in its examples/ directory. Run one with:

cargo run --package <crate> --example <name>

A few need a Cargo feature, noted below.

Example Crate What it shows Useful when
readme brush-core The shortest embedding: build a Shell, run a string of shell code, check the result. This is the snippet in the repository README; a test keeps the two identical. You want the minimum needed to run shell code inside your own program.
call-func brush-core Define a shell function from Rust, list the functions the shell knows, invoke one with arguments, and redirect its stdout using ExecutionParameters. Your program calls into user-supplied shell code and needs control over its I/O.
custom-builtin brush-clap-adapter A builtin implemented in Rust and registered alongside the standard ones: the ParseArgs and Builtin traits, arguments parsed by clap through brush-clap-adapter, thiserror errors mapped to exit codes, and access to shell state and I/O through the execution context. You want to extend the shell with commands specific to your application.
serde brush-parser (--features serde) Parse a script and serialize the syntax tree to JSON, then deserialize it back. Tooling that inspects, stores, or transmits shell syntax trees.
miette brush-parser (--features diagnostics) Parse a file given on the command line and render any parse error as a miette diagnostic with source spans. Editors, linters, and other tools that need to show where a parse failed.
gen brush-shell (--features schema) Generate the config file's JSON schema, which needs the shell linked. Driven by cargo xtask gen schema config. You're a maintainer regenerating distributed artifacts.