command

command utilities.

Functions

has_subparsers

Checks whether the parser had subparsers.

iter_subparsers

Iterates through the subparsers.

register_command

Registers a command to a parent subparser and returns the newly created parser.

register_main_command

Registers the main command entrypoint and returns the parser.

Classes

Command

Base class for defining commands.

RecursiveHelpAction

class Command[source]

Bases: object

Base class for defining commands.

Command instances must implement the setup() method, and they should implement the execute() method if they perform any functionality beyond defining subparsers.

static execute(parser, args)[source]

Executes the command.

Parameters:
  • parser (ArgumentParser) – The argument parser.

  • args (Namespace) – The arguments.

Returns:

static setup(parser)[source]

Sets up the command.

Parameters:

parser (ArgumentParser) – The argument parser.

Returns:

class RecursiveHelpAction(option_strings, dest='==SUPPRESS==', default='==SUPPRESS==', help=None)[source]

Bases: _HelpAction

has_subparsers(parser)[source]

Checks whether the parser had subparsers.

Parameters:

parser (ArgumentParser)

Return type:

bool

Returns:

iter_subparsers(parser)[source]

Iterates through the subparsers.

Parameters:

parser (ArgumentParser)

Returns:

register_command(parent, name, command, recursive_help=True)[source]

Registers a command to a parent subparser and returns the newly created parser.

Parameters:
  • parent (ArgumentParser)

  • name (str)

  • command (Type[Command])

  • recursive_help

Return type:

ArgumentParser

Returns:

register_main_command(command, version=None, recursive_help=True)[source]

Registers the main command entrypoint and returns the parser.

Parameters:
  • command (Type[Command])

  • version (str)

  • recursive_help (bool)

Return type:

ArgumentParser

Returns: