utils.ArgParser

This module holds a utility class that can parse your command line arguments.

A sample program would instantiate the ArgParser class, bind some delegates (can be anonymous), then call parse with the arguments as a parameter.

Note that the delegates must return the correct number of consumed characters to ensure that the ArgParser operates correctly. Simple arguments that don't use the value parameter of the callback, should return 0 consumed characters. This behaviour will ensure that ArgParser will correctly handle all arguments, even when there are no space between them.

Authors:
Eric Anderton, Lars Ivar Igesund

License:
BSD Derivative (see source for details)

alias ArgParserCallback;
An alias to a delegate taking a char[] as a parameter and returning an uint. The value parameter will hold any chars immediately following the argument. The returned value tell how many chars of value was used by the callback.

alias DefaultArgParserCallback;
An alias to a delegate taking a char[] as a parameter and returning an uint. The value parameter will hold any chars immediately following the argument. The returned value tell how many chars of value was used by the callback.

The ordinal argument represents which default argument this is for the given stream of arguments. The first default argument will be ordinal=0 with each successive call to this callback having ordinal values of 1, 2, 3 and so forth.

alias ArgParserSimpleCallback;
An alias to a delegate taking no parameters and returning nothing.

class ArgParser;
A utility class to parse and handle your command line arguments.

struct PrefixCallback;
A helper struct containing a callback and an id to, corresponding to the argId passed to one of the bind methods.

void bind(char[] argPrefix, char[] argId, uint delegate(char[] value) cb);
Binds a delegate callback to argument with a prefix and a argId.

char[] argPrefix the prefix of the argument, e.g. a dash '-'.
char[] argId the name of the argument, what follows the prefix
uint delegate(char[] value) cb the delegate that should be called when this argument is found


this();
The constructor, creates an empty ArgParser instance.

this(uint delegate(char[] value, uint ordinal) callback);
The constructor, creates an ArgParser instance with a defined default callback.

void bind(char[] argPrefix, char[] argId, void delegate() cb);
Binds a delegate callback to argument with a prefix and a argId.

char[] argPrefix the prefix of the argument, e.g. a dash '-'.
char[] argId the name of the argument, what follows the prefix
void delegate() cb the delegate that should be called when this argument is found


void bindDefault(char[] argPrefix, uint delegate(char[] value, uint ordinal) callback);
Binds a delegate callback to all arguments with prefix argPrefix, but that do not conform to an argument bound in a call to bind().

char[] argPrefix the prefix for the callback
uint delegate(char[] value, uint ordinal) callback the default callback


void bindDefault(uint delegate(char[] value, uint ordinal) callback);
Binds a delegate callback to all arguments not conforming to an argument bound in a call to bind(). These arguments will be passed to the delegate without having any matching prefixes removed.

uint delegate(char[] value, uint ordinal) callback the default callback


void parse(char[][] arguments);
Parses the arguments provided by the parameter. The bound callbacks are called as arguments are recognized.

char[][] arguments the command line arguments from the application