bare-script
The type-safe scripting authority for Rust.
A framework for building robust shell commands and automation with "Parse, don't validate" philosophy.
Overview
bare-script provides a type-safe approach to building shell commands and automation scripts in Rust:
- Type-safe commands - Strongly typed command arguments and options
- Validation at boundaries - Parse and validate input once, then trust throughout execution
- Cross-platform - Works consistently across Linux, macOS, and Windows
- Composable - Build complex pipelines from simple commands
- Zero runtime overhead - After validation, command execution is cost-free
Philosophy
Parse, Don't Validate
Traditional shell scripting relies on loose string manipulation and runtime checks. bare-script enforces:
- Parse - Convert command-line input into strongly typed values
- Validate - Ensure values meet constraints at command invocation
- Trust - Use validated values without re-checking during execution
This eliminates common shell scripting pitfalls and ensures type safety.
Quick Start
use CommandBuilder;
Async Quick Start
use CommandBuilder;
async
Features
- Type-safe command building - Compile-time guarantee of valid command structure
- Type-safe arguments -
Argsbuilder for validated CLI arguments - Cross-platform execution - Consistent behavior across operating systems
- Pipeline support - Chain commands with pipes (sync & async)
- Output capture - Capture stdout, stderr, and exit codes
- Environment control - Set and manage environment variables
- Working directory management - Execute commands in specific directories
- Timeout support - Execute commands with timeouts
- Shell integration helpers -
which,command_exists,eval
Examples
Pipeline
use Pipeline;
let output = new
.arg
.pipe
.arg
.capture_output
.execute?;
Type-safe Arguments
use Args;
let args = new
.flag
.option
.value
.positional
.validate?;
Shell Helpers
use shell;
// Find executable in PATH
if let Some = which?
// Execute shell command
let output = eval?;
Timeout
use Duration;
use CommandBuilder;
let result = new
.arg
.execute_with_timeout;
assert!;
Roadmap
- Core command execution framework
- Type-safe argument parsing
- Pipeline and redirection support
- Cross-platform compatibility layer
- Environment variable management
- Output streaming (via Pipeline)
- Background process management
- Shell integration helpers
MSRV (Minimum Supported Rust Version)
This crate requires Rust 1.85.0 or later. This is due to:
- Edition 2024 features and syntax
- Strict linting configuration (
#![forbid(unsafe_code)]) - Advanced type-state pattern usage
We aim to support the two latest stable Rust releases.
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE)
- MIT License (LICENSE-MIT)
Contributing
Contributions are welcome! Please open an issue or submit a PR.
Testing
This project includes multiple test suites:
# Run all tests
# Run with coverage
# Run benchmarks
# Run fuzz tests (requires nightly)
Fuzzing
For fuzz testing, we use cargo-fuzz:
# Install cargo-fuzz
# Run fuzz tests
Note: Fuzzing requires nightly Rust.
Related Crates
- bare-types - Zero-cost foundation for type-safe domain modeling
- bare-config - Type-safe configuration authority