A very simple command line argument parser.
``rust
// The argument to
newis the description for the application.
let mut parser = Parser::new("An example argument parsing application");
// Adds some
paramparameters, which take a single value.
// There is no special requirement for parameter prefixes.
-/--are used here by convention.
// Aliases can be applied using the builder pattern.
parser.add_parameter(Parameter::param("--arg0", "Argument 0, type: u32.").alias("-a"));
// Adds a flag parameter, which takes no value - it is
trueif present,
false` otherwise
parser.add_parameter(Parameter::flag("--arg1", "Argument 1, flag").alias("-a1"));
// Parsing arguments returns an Args
struct which has 3 major features.
let args = parser.parse_args();
// 1. You can access positional arguments directly. for positional in &args.positional { println!("Found positional argument: {}", positional); }
// 2. The get
function allows you to access parameters.
if let Some(arg0) = args.get::
// 3. The flag
function allows you to check the value of flags.
if args.flag("--arg2") {
println!("Found Arg 2 flag!");
}
```