Crate lapp [] [src]

lapp provides a straightforward way to parse command-line arguments, using the usage text as a pattern.

Example

extern crate lapp;

let args = lapp::parse_args("
   A test program
   -v,--verbose  verbose output
   -k         (default 10)
   -s, --save (default 'out.txt')
   <out>      (default 'stdout')
");
assert_eq!(args.get_bool("verbose"),false);
assert_eq!(args.get_integer("k"),10);
assert_eq!(args.get_string("save"),"out.txt");
assert_eq!(args.get_string("out"),"stdout");

The usage text or specification follows these simple rules: line begining with one of '-short, --long', '--long' or '-short' (flags) or begining with (positional arguments). These may be followed by a type/default specifier () - otherwise considered a bool flag with default false. This specifier can be a type (like '(integer)') or a default, like '(default 10)`. If there's a default, the type is infered from the value - can always use single quotes to insist that the flag value is a string. Otherwise this flag is required and must be present!

The currently supported types are 'string','integer','bool' and 'float'. There are corresponding access methods like get_string("flag") and so forth.

The flag may be followed by '...' (e.g '-I... ()') and it is then a multiple flag; its value will be a vector. This vector may be empty (flag is not required). If the '...' appears inside the type specifier (e.g. '-p (integer...)') then the flag is expecting several space-separated values (like -p '10 20 30'); it is also represented by a vector.

Rest of line (or any other kind of line) is ignored.

lapp scans command-line arguments using GNU-style short and long flags. Short flags may be combined, and may immediately followed by a value, e.g '-vk5'. As an extension, you can say '--flag=value' or '-f:value'.

Structs

Args

Functions

parse_args

parse the command-line specification and use it to parse the program's command line args. As before, quits on any error.