Command line parser for rust (clpr)
A bare-bones rust command line parser.
Dependencies
This project has no external dependencies
Usage
Add the crate to your Cargo.toml file and you can use it to parse incoming arguments and flags.
= "0.1.1"
And in the file that will consume the crate:
extern crate cmdparser;
Parse incoming arguments and flags by calling "parse()" and receiving a touple.
let = new.parse;
First element of the touple is a HashMap<String, String> that contains all of the key value arguments received from the command line. By default both "-" and "--" prefixes are parsed and accepted.
If you want to limit the user to a certain prefix(es) use the strict_prefix(prefixes: Vec<String>)
method.
let prefixes = vec!;
let = new.strict_prefix.parse;
The given parser will only accept arguments prefixed with a tilda (~) character.
Example
Running your program with the following arguments:
Yields the following:
ArgumentList:
Flags:
To consume them the simplest pattern would be:
let foo = arguments.get.or.expect;
The given code would look for -foo or -f and in case they're not found panic with the erro message.
Contributing
As this is a very basic parser, and I don't have a lot of Rust experience, if you want to contribute and improve something, submit a pull request.
Contributors
Nenad Lukic - lnenad