Positional arguments (--positional
) are not named on the command line. By contrast, a named command-line entry might look like this...
> MyProgram --ticker MSFT
--ticker
is the name of the command. An unnamed or --positional
example of the same program might look like this... > MyProgram MSFT
--ticker
is not part of the command-line entry.
Another way to describe --positional
arguments is that they are ordered in nature. Whereas named arguments are unordered.
To make an argument positional, just include the --positional parameter.
CmdLine.create("--type string --key ticker --positional");
The --key (name) is still required since the name is used internally if you need to query the Argument system for something about the argument. cmdLine.arg("--ticker")
is still used to find it.
There can be more than 1 positional argument. In this case they are parsed in the order in which they are defined.
CmdLine.create( "--type string --key ticker --positional", "--type date --key year --positional --format yyyy");
> MyProgram MSFT 2010
Argument parses the command-line by first looking for all named arguments, and then all positional arguments. As it finds each argument it processes it and removes it and it's value(s) from the command-line. After all named arguments are removed all that is left is the positional arguments. In this example there is one named argument and the same two positional arguments as in the previous examples. Notice all of the valid command-lines.
CmdLine.create( "--type string --key x exchange --list NYSE, NASDAC", "--type string --key ticker --positional", "--type date --key year --positional --format yyyy");
> MyProgram MSFT 2010 > MyProgram -x NYSE MSFT 2010 > MyProgram MSFT -x NYSE 2010 > MyProgram MSFT 2010 -x NYSE