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:

PositionalArgument() PositionalArgument(uint position) PositionalArgument(uint position, string placeholder)

Name

Type

Optional/


Required

Description

position

uint

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.

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:

  • 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:

import argparse; struct Params1 { @PositionalArgument(0) string firstName; @PositionalArgument(1, "lastName") string arg; } struct Params2 { @PositionalArgument string firstName; @PositionalArgument string arg; }
Last modified: 06 May 2025