Module Arg

Description

Argument parsing module

This module supports two rather different methods of argument parsing. The first is suitable quick argument parsing without much in the way of checking:

int main( int c, array(string) argv )
{
  mapping arguments = Arg.parse(argv);
  array files = arguments[Arg.REST];
  if( arguments->help ) print_help();
  ...
}

The Arg.parse method will return a mapping from argument name to the argument value, if any.

Non-option arguments will be placed in the index Arg.REST

The second way to use this module is to inherit the Options class and add supported arguments.

class MyArguments {
   inherit Arg.Options;
   Opt verbose = NoOpt("-v")|NoOpt("--verbose");
   Opt help = MaybeOpt("--help");
   Opt output = HasOpt("--output")|HasOpt("-o");
};

Then, in main:

MyArguments args = MyArguments(argv);

See the documentation for OptLibrary for details about the various Opt classes.


Constant APP

constant Arg.APP

Description

Constant used to represent the name of the application from the command line. Can be used when indexing an Options object.


Constant PATH

constant Arg.PATH

Description

Constant used to represent the full paht of the applicatiojn from the command line. Can be used when indexing an Options object.


Constant REST

constant Arg.REST

Description

Constant used to represent command line arguments not identified as options. Can be used both in the response mapping from parse and when indexing an Options object.