Pike v8.1 release 6

Method Arg.parse()


Method parse

mapping(string:string|int(1..)) parse(array(string) argv)

Description

Convenience function for simple argument parsing.

Handles the most common cases.

The return value is a mapping from option name to the option value.

The special index Arg.REST will be set to the remaining arguments after all options have been parsed.

The following argument syntaxes are supported:

--foo         ->  "foo":1
--foo=bar     ->  "foo":"bar"
-bar          ->  "b":1,"a":1,"r":1
-bar=foo      ->  "b":1,"a":1,"r":"foo" (?)
--foo --bar   ->  "foo":1,"bar":1
--foo - --bar ->  "foo":1
--foo x --bar ->  "foo":1 (?)
-foo          ->  "f":1,"o":2
-x -x -x      ->  "x":3
Example
void main(int n, array argv)
{
  mapping opts = Arg.parse(argv);
  argv = opts[Arg.REST];
  if( opts->help ) /*... */
}