https://github.com/blobfolio/argyle
A lightweight, agnostic CLI argument parsing library for Rust.
https://github.com/blobfolio/argyle
argument-parser cli rust
Last synced: 6 months ago
JSON representation
A lightweight, agnostic CLI argument parsing library for Rust.
- Host: GitHub
- URL: https://github.com/blobfolio/argyle
- Owner: Blobfolio
- License: wtfpl
- Created: 2021-02-20T20:59:18.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2025-04-03T18:26:48.000Z (over 1 year ago)
- Last Synced: 2025-04-12T13:45:50.095Z (over 1 year ago)
- Topics: argument-parser, cli, rust
- Language: Rust
- Homepage:
- Size: 209 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# Argyle
[](https://docs.rs/argyle/)
[](https://github.com/Blobfolio/argyle/blob/master/CHANGELOG.md)
[](https://crates.io/crates/argyle)
[](https://github.com/Blobfolio/argyle/actions)
[](https://deps.rs/crate/argyle/)
[](https://en.wikipedia.org/wiki/WTFPL)
[](https://github.com/Blobfolio/argyle/issues)
This crate provides an `argue!` macro for generating a CLI argument enum and parsing iterator, ideal for use cases requiring more than the standard library's barebones `args_os` helper, but less than full-service options like [clap](https://crates.io/crates/clap).
## Example
The [docs](https://docs.rs/argyle/latest/argyle/) contain a lot of addition details, but here's a minimal preview to give you an idea of what it's all about.
```rust
use argyle::argue;
// Construct the enum and iterator.
argue! {
Help "-h" "--help",
Version "-V" "--version",
Stderr "--stderr",
@options
Format "--format",
Level "-l" "--level",
}
/// # Main.
fn main() {
// Example settings.
let mut stderr = false;
let mut format: Option = None;
let mut level = 0_u8;
let mut paths: Vec = Vec::new();
// Loop through the environmental arguments, taking whatever actions
// make sense for your application.
for arg in Argument::args_os() {
match arg {
// You named these!
Argument::Help => print_help(),
Argument::Version => print_version(),
Argument::Stderr => { stderr = true; },
// Options come with the value as a String.
Argument::Format(v) => {
format = Format::from_str(v);
},
Argument::Level(v) => {
level = v.parse().unwrap_or(0);
},
// Unmatched String values map to the first generic catchall.
Argument::Other(v) => {
eprintln!("Warning: unrecognized CLI argument {v}.");
},
// Unmatched values with invalid UTF-8 will be passed through
// to the second generic catchall as OsString values.
Argument::OtherOs(v) => {
eprintln!(
"Warning: unrecognized CLI argument {}.",
v.display(),
);
},
}
}
// Now that the settings have been worked out, do something!
// …
}
```
## Installation
Add `argyle` to your `dependencies` in `Cargo.toml`, like:
```toml
[dependencies]
argyle = "0.14.*"
```