olua.app
Class ArgumentParser

olua.lib.Object
└─ olua.app.ArgumentParser

I am a utility class for parsing command line options.

I understand both short and long options, with any number of arguments (although your users may get confused if you use more than one). With a short option, I will automatically detect whether the argument is separated with a space or not.

I don't handle combined short options (ls -lR), or using = to separate the option from the argument.

To use me, instantiate me and then call one of the addOption: methods to add option handlers. When ready, call parse: with a preparsed command line. I will then call the handlers from left to right. Each handler should return the number of arguments consumed; typically 0 or 1. parse: will return a list of leftover command line arguments.

Unrecognised options are handled by throwing olua.app.UnrecognisedOptionException.

You usually don't need to instantiate me directly; olua.app.Application will do it for you.


Method Summary
- addOption: option withHandler: handler
Adds a handler to the parser.
- addOptions: options
Adds a table of handlers to the parser.
- addOptions: options withHandler: handler
Adds several options with the same handler.
- parse: args
Parses a set of command line options.
Method Detail

- addOption: option withHandler: handler

Adds a handler to the parser.

Parameters:
option - the option (e.g. "x" or "extra")
handler - the handler

- addOptions: options

Adds a table of handlers to the parser.

Parameters:
options - the option table (e.g. {x = function()...end})

- addOptions: options withHandler: handler

Adds several options with the same handler.

Parameters:
option - an array of options (e.g. {"x", "extra"})
handler - the handler

- parse: args

Parses a set of command line options.

The options are processed left to right. All option handlers are executed. The unprocessed arguments are returned. Unrecognised options are handled by throwing olua.lib.UnrecognisedOptionError.

Returns:
any unprocessed arguments