Skip to main content

LabelCommand

A management command which takes one or more arbitrary arguments (labels) on the command line, and does something with each of them.

Attributes

AttributeTypeDescription
labelstring = "label"A string representing the name of the argument used as a metavariable in the command help and as a placeholder in error messages.
missing_args_messagestring = "Enter at least one %s."The error message displayed to the user when no arguments are provided on the command line.

Constructor

Signature

def LabelCommand(
*args: any,
**kwargs: any
) - > null

Parameters

NameTypeDescription
*argsanyVariable length argument list.
**kwargsanyArbitrary keyword arguments.

Methods


add_arguments()

@classmethod
def add_arguments(
parser: ArgumentParser
) - > null

Configures the argument parser to accept one or more positional label arguments from the command line.

Parameters

NameTypeDescription
parserArgumentParserThe argument parser instance to which the label positional arguments will be added.

Returns

TypeDescription
nullNothing is returned; the parser object is modified in place.

handle()

@classmethod
def handle(
labels: tuple,
options: dict
) - > string

Iterates through the provided labels and aggregates the output from handle_label for each.

Parameters

NameTypeDescription
labelstupleA sequence of arbitrary string arguments provided via the command line.
optionsdictA dictionary of configuration options and flags passed to the management command.

Returns

TypeDescription
stringA single string containing the concatenated output of all handle_label calls, separated by newlines.

handle_label()

@classmethod
def handle_label(
label: string,
options: dict
) - > string

Perform the command's actions for label, which will be the string as given on the command line.

Parameters

NameTypeDescription
labelstringThe specific command-line argument currently being processed by the command.
optionsdictThe configuration options and flags used to customize the behavior of the label processing.

Returns

TypeDescription
stringThe output string resulting from processing the specific label, which will be collected by the handle method.