An ultra simple CLI arguments parser.
=
.-vvv
or -abc
).```rust use pico_args::Arguments;
struct Args {
help: bool,
version: bool,
number: u32,
opt_number: Option
fn parsewidth(s: &str) -> Result
fn main() -> Result<(), BoxFromStr
.
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(())
} ```
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 |
.text
section size of an app with
arguments parsing and a hello world app.hyperfine 'cargo clean; cargo build --release'
.test-apps/
.MIT