🌿 Sap
A small, simple and sweet argument parser for Rust
Sap is a minimal, zero-dependency Unix command-line argument parser for Rust. It provides full control over argument parsing with an iterator-based API that handles GNU-style options while maintaining simplicity and flexibility.
✨ Features
- GNU-style option parsing: Support for short (
-a), long (--verbose), and combined options (-abc) - Flexible value handling: Options with values via
--name=valueor separate arguments - POSIX compliance: Handle
--separator and-(stdin) arguments correctly - Zero dependencies: Pure Rust implementation with no external crates
- Iterator-based: Works with any
Iterator<Item = Into<String>>for maximum flexibility - Comprehensive error handling: Descriptive error messages for invalid input
🚀 Quick Start
Add Sap to your Cargo.toml:
[]
= "0.0.5"
📖 Usage
Basic Example
use ;
// Parse from command line arguments
let mut parser = from_env.unwrap;
while let Some = parser.forward.unwrap
Parsing Custom Arguments
use ;
// Parse from any iterator of string-like values
let mut parser = from_arbitrary.unwrap;
while let Some = parser.forward.unwrap
🎯 Argument Types
Sap recognizes four types of arguments:
Argument::Short(char)- Short options like-v,-x, and combined ones like-abcArgument::Long(&str)- Long options like--verbose,--file, including values like--file=foo.txtArgument::Value(Cow<str>)- Positional arguments and operandsArgument::Stdio- The special-argument (stdin/stdout)
📚 Complete Example
Here's a more comprehensive example showing a typical CLI application:
use ;
🔍 Real-World Examples
For comprehensive examples of Sap in action, check out puppyutils - a collection of Unix utilities reimplemented in Rust. Sap was originally created as the argument parser for this project, so you'll find extensive real-world usage patterns.
🤝 Acknowledgments
Special thanks to Esther who wrote the original parser design for this library <3
License
This project is licensed under the Apache-2.0 License. For more information, please see the LICENSE file.