argparse documentation Help

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

1

position

uint

required

Zero-based unsigned position of the argument.

2

placeholder

string

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:

  • 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 have index greater than 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:

import argparse; struct Params { @PositionalArgument(0) string firstName; @PositionalArgument(1, "lastName") string arg; }
Last modified: 07 August 2024