getopt3 - cli parser with GNU extension for Rust
Version 2.0.0 MIT Licensed
Features
- Rust ported well tested Scala code
- GNU argument parsing rules. Options can be anywhere in command line before --
- GNU -- extension. Everything after -- is not treated as options
- Multiple options not requiring argument can be grouped together. -abc is the same as -a -b -c
- Argument does not require space. -wfile is same as -w file
- Zero dependencies
- 41 unit tests + 7 integration tests + 1 doc test
Usage
Create getopt instance
let g = getopt3::new(arguments, optstring)
getopt3::new constructor arguments:
- arguments command line arguments as Vec<String>
- optstring is a &str containing the legitimate option characters. If such a character is followed by a colon, the option requires an argument.
Check for results
getopt structure returned by constructor has following members:
- arguments : Vec <String> command line arguments with options removed
- options_map : HashMap <char, bool> map of recognized options. option -> have_argument
- options : HashMap <char, String> options parsed. If option do not have argument, it is mapped to "" String, otherwise it is mapped to its argument as string.
Optional - Check if options are parsed correctly
You can run strictness check by calling validate(getopt) function. Returns Result with getopt instance or error as String.
Example usage
use args;
let rc = new;
if let Ok = rc ;