Parsed arguments module.

This module contains functionality for handling the parsed command line arguments.

ProgramArgs instance is created and returned by parse function. It contains values of flags, options and arguments, which can be read with .flag, .option and .arg functions respectively. Those functions work on _unique names_, not on option full/short names such as -l or --help.

For repeating options and arguments, plural form functions can be used: .options, .args, which return all values rather than last one.

When a command or program has sub-commands returned ProgramArgs object forms a hierarchy, where every subcommand is another instance of ProgramArgs, starting from root which is program args, going down to selected sub-command.

To simplify working with subcommands, you can use on command that allows to register command handlers with a simple interface. E.g. consider git-like tool:

1 auto program = new Program("grit")
2        .add(new Flag("v", "verbose", "verbosity"))
3        .add(new Command("branch", "branch management")
4            .add(new Command("add", "adds branch")
5                .add(new Argument("name"))
6            )
7            .add(new Command("rm", "removes branch")
8                .add(new Argument("name"))
9            )
10        )
11     ;
12 auto programArgs = program.parse(args);
13 programArgs
14  .on("branch", (args) {
15      writeln("verbosity: ", args.flag("verbose"));
16      args.on("rm", (args) { writeln("removing branch ", args.arg("name")); })
17          .on("add", (args) { writeln("adding branch", args.arg("name")); })
18  })



class ProgramArgs

Parsed program/command arguments.

See Also