tango.util.ArgParser

License:

BSD style: see license.txt

Version:

Initial release: December 2005

Author:

Lars Ivar Igesund, Eric Anderton
alias void delegate (char[] value) ArgParserCallback #
An alias to a delegate taking a char[] as a parameter. The value parameter will hold any chars immediately following the argument.
alias void delegate (char[] value,uint ordinal) DefaultArgParserCallback #
An alias to a delegate taking a char[] as a parameter. The value parameter will hold any chars immediately following the argument.
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. This can be reset to zero in new calls to parse.
alias void delegate () ArgParserSimpleCallback #
An alias to a delegate taking no parameters
struct Argument #
A struct that represents a "{Prefix}{Identifier}" string.
Argument opCall(char[] prefix, char[] identifier) [static] #
Creates a new Argument instance with given prefix and identifier.
alias Argument Arg #
Alias for for the lazy people.
class ArgParser #
A utility class to parse and handle your command line arguments.
struct PrefixCallback [protected] #
A helper struct containing a callback and an id, corresponding to the argId passed to one of the bind methods.
void bind(char[] argPrefix, char[] argId, ArgParserCallback cb) [public] #
Binds a delegate callback to argument with a prefix and a argId.

Params:

argPrefixthe prefix of the argument, e.g. a dash '-'.
argIdthe name of the argument, what follows the prefix
cbthe delegate that should be called when this argument is found
this() [public, deprecated] #
The constructor, creates an empty ArgParser instance.
this(DefaultArgParserCallback callback) [public, deprecated] #
The constructor, creates an ArgParser instance with a defined default callback.
void bind(char[] argPrefix, char[] argId, ArgParserSimpleCallback cb) [public] #
Binds a delegate callback to argument with a prefix and a argId.

Params:

argPrefixthe prefix of the argument, e.g. a dash '-'.
argIdthe name of the argument, what follows the prefix
cbthe delegate that should be called when this argument is found
void bindDefault(char[] argPrefix, DefaultArgParserCallback callback) [public] #
Binds a delegate callback to all arguments with prefix argPrefix, but that do not conform to an argument bound in a call to bind().

Params:

argPrefixthe prefix for the callback
callbackthe default callback
void bindDefault(DefaultArgParserCallback callback) [public] #
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.

Params:

callbackthe default callback
void bind(Argument argument, ArgParserCallback callback) [public] #
Binds a delegate callback to an argument.

Params:

argumentargument to respond to
callbackthe delegate that should be called when the argument is found
void bind(Argument[] arguments, void delegate(char[]) callback) [public] #
Binds a delegate callback to any number of arguments.

Params:

argumentsan array of Argument struct instances
callbackthe delegate that should be called when one of the arguments is found
void bindPosix(char[] identifier, ArgParserCallback callback) [public] #
Binds a delegate callback to an identifier with Posix-like prefixes. This means, it binds for both prefixes "-" and "--", as well as identifier with, and without a delimiting "=" between identifier and value.

Params:

identifierargument identifier
callbackthe delegate that should be called when one of the arguments is found
void bindPosix(char[][] identifiers, ArgParserCallback callback) [public] #
Binds a delegate callback to any number of identifiers with Posix-like prefixes. See bindPosix(identifier, callback).

Params:

argumentsan array of argument identifiers
callbackthe delegate that should be called when one of the arguments is found
void parse(char[][] arguments, bool resetOrdinals = false) [public] #
Parses the arguments provided by the parameter. The bound callbacks are called as arguments are recognized. If two arguments have the same prefix, and start with the same characters (e.g.: --open, --opened), the longest matching bound callback is called.

Params:

argumentsthe command line arguments from the application
resetOrdinalsif true, all ordinal counts will be set to zero