#command-line-arguments #arguments-parser #syntax

arg-kit

A featherweight toolkit to help iterate long/short arguments

2 stable releases

1.0.1 Aug 4, 2024

#306 in Command-line interface

Custom license

17KB
225 lines

arg-kit is a featherweight library that helps parse arguments using one of Rust's most versatile and powerful syntaxes: match {}

Do you really need bloated proc macros when collecting arguments can be simplified to a .next()? You have zero indication of what's going on under the hood, so you can't implement your own behaviour.

That is why I don't call it an "argument parser" on its own. Your program parses the arguments, this just helps iterate over it, like so:

let mut argv = std::env::args();
for_args!(argv; {
    arg!(-h | --help) => eprintln!("{HELP_TEXT}"),
    arg!(-v | --value) => do_something(argv.next()?),
    unknown => panic!("Unknown argument {unknown}"),
});

...which expands to:

let mut argv = std::env::args();
while let Some(args) = argv.next() {
    for arg in args.as_arg() {
        match arg {
            ...

Take a look through the docs for specific details. The sauce is hosted on my website because GitHub is gay.

No runtime deps