Lexopt is an argument parser for Rust. It tries to have the simplest possible design that's still correct. It's so simple that it's a bit tedious to use.
Lexopt is:
- Small: one file, no dependencies, no macros. Easy to audit.
- Correct: standard conventions are supported and ambiguity is avoided.
- Imperative: options are returned as they are found, nothing is declared ahead of time.
- Minimalist: only basic functionality is provided.
- Unhelpful: there is no help generation and error messages often lack context.
For basic usage, see examples/cargo.rs.
For more details, see src/tests.rs.
The following conventions are supported:
- Short options (
-q) - Long options (
--verbose) --to mark the end of options=to separate options from values (--option=value,-o=value)- The nonstandard
-o=valuesyntax can be disabled byParser::set_short_equals().
- The nonstandard
- Spaces to separate options from values (
--option value,-o value) - Unseparated short options (
-ovalue) - Combined short options (
-abcto mean-a -b -c) - Options with optional arguments (like GNU sed's
-i, which can be used standalone or as-iSUFFIX) (Parser::optional_value())
These are not supported out of the box:
- Single-dash long options (like find's
-name) - Abbreviated long options (GNU's getopt lets you write
--numinstead of--numberif it can be expanded unambiguously)
This library may not be worth using if:
- You don't care about code size
- You do care about great error messages
- You hate boilerplate