gfw.common.cli.Command#

class Command[source]#

Abstract base class representing a CLI command or subcommand.

This class defines the essential interface that any command implementation must follow to be compatible with the CLI framework.

Subclasses must provide the command’s name, description, options, and implement the run() method which contains the command’s logic.

Properties:
name:

The name of the command (used as the CLI argument, e.g., mycli <name>). For subcommands, this distinguishes them from the main command.

description:

A brief help message describing what the subcommand does.

options:

A list of Option instances representing CLI arguments specific to this subcommand.

run()[source]#

A callable to execute when the subcommand is invoked. It should accept keyword arguments corresponding to the CLI options.

Return type:

Any

Methods

copy_with

Returns a new command changing some of its properties.

defaults

Returns a dictionary of default values for all CLI options.

run

Executes the command logic.

Attributes

description

The command's description.

header

Returns a descriptive title for the command's options group.

name

The name of the command (used as the CLI argument, e.g., mycli <name>).

options

The command's options.

abstract property name: str#

The name of the command (used as the CLI argument, e.g., mycli <name>).

For subcommands, this distinguishes them from the main command.

abstract property description: str#

The command’s description.

abstract property options: List[Option]#

The command’s options.

abstractmethod run(config, **kwargs)[source]#

Executes the command logic.

Return type:

Any

property header: str#

Returns a descriptive title for the command’s options group.

defaults()[source]#

Returns a dictionary of default values for all CLI options.

Returns:

A dictionary mapping option dest (as used in argparse) to their default values.

Return type:

dict[str, Any]

copy_with(**kwargs)[source]#

Returns a new command changing some of its properties.

Return type:

ParametrizedCommand