Positional arguments
Positional arguments are arguments that have specific position within the command line. This argument can be declared using PositionalArgument
UDA. It has the following parameters:
Name | Type | Optional/ Required | Description |
---|---|---|---|
|
| required | Zero-based position of the argument. If it's omitted then the order of positional arguments is the same as the order of member declaration. |
|
| optional | Name of this argument that is shown in help text. If not provided, then the name of data member is used. |
Since that both named and positional arguments can be mixed in the command line, argparse
enforces the following restrictions to be able to parse a command line unambiguously:
Mixing of
PositionalArgument
with and without position is not allowed.Positions of positional arguments must be consecutive starting with zero without missing or repeating.
Positional argument must not have variable number of values except for the last argument.
Optional positional argument must come after required positional arguments.
If a command has default subcommand (see Subcommand section for details) the optional positional argument is not allowed in this command.
Example: