pico-args

Build Status Crates.io Documentation

An ultra simple CLI arguments parser.

Example

```rust use pico_args::Arguments;

struct Args { help: bool, version: bool, number: u32, opt_number: Option, width: u32, free: Vec, }

fn parsewidth(s: &str) -> Result { s.parse().maperr(|| "not a number".tostring()) }

fn main() -> Result<(), Box> { let mut args = Arguments::fromenv(); // Arguments can be parsed in any order. let args = Args { // You can use a slice for multiple commands help: args.contains(["-h", "--help"]), // or just a string for a single one. version: args.contains("-V"), // Parses a value that implements FromStr. number: args.valuefromstr("--number")?.unwrapor(5), // Parses an optional value that implements FromStr. optnumber: args.valuefromstr("--opt-number")?, // Parses a value using a specified function. width: args.valuefromfn("--width", parsewidth)?.unwrap_or(10), // Will return all free arguments or an error if any flags are left. free: args.free()?, };

Ok(())

} ```

Alternatives

The core idea of pico-args is to provide some "sugar" for arguments parsing without a lot of overhead (binary or compilation time wise). There are no point in comparing parsing features since pico-args supports only the bare minimum. So we will compare only the size overhead and compilation time.

There are a lot of arguments parsing implementations, but we will use only these one:

| | pico-args | clap | gumdrop | structopt | |-------------------|-------------|----------|-----------|-------------| | Binary overhead | 20.0KiB | 435.1KiB | 23.0KiB | 436.8KiB | | Build time | 1s | 15s | 31s | 27s | | Tested version | 0.2.0 | 2.33.0 | 0.6.0 | 0.2.18 |

License

MIT