argwerk
Define a simple command-line parser through a declarative macro.
This is not intended to be a complete command-line parser library. Instead this can be used as an alternative quick-and-dirty approach that can be cheaply incorporated into a tool.
For a more complete command-line parsing library, use clap.
We provide:
- A dependency-free command-line parsing framework using declarative macros.
- A flexible mechanism for parsing.
- Formatting of decent looking help messages.
We do not provide:
- As-close-to correct line wrapping with wide unicode characters as possible (see textwrap).
- Complex command structures like subcommands.
For how to use, see the documentation of argwerk::define and argwerk::args.
Examples
Initially when you're adding arguments to your program you can use argwerk::args. This allows for easily parsing out a handful of optional parameters.
This example is available as
simple:
let args = args! ?;
if args.help
dbg!;
After a while you might want to graduate to defining a named struct containing the arguments. This can be useful if you want to pass the arguments around.
This example is available as
tour:
use OsString;
define!
// Note: we're using `parse` here instead of `args` since it works better
// with the example.
let args = parse?;
dbg!;
Time and size compared to other projects
argwerk aims to be a lightweight dependency that is fast to compile. This is how it stacks up to other projects in that regard.
The following table was generated with:
It builds and measures the projects found here. These are the results:
| project | cold build (release) | rebuild* (release) | size (release) |
|---|---|---|---|
| argh | 5.0839426s (4.5671066s) | 405.1443ms (465.8606ms) | 297k (180k) |
| argwerk | 1.2646615s (1.2352931s) | 388.3651ms (471.8421ms) | 265k (185k) |
| clap** | 10.6010515s (12.1861838s) | 522.9817ms (759.0176ms) | 2188k (750k) |
*: Rebuild was triggered by adding a single newline to
main.rs. **: Clap includes ~38 dependencies.
License: MIT/Apache-2.0