LabelCommand
A management command which takes one or more arbitrary arguments (labels) on the command line, and does something with each of them.
Attributes
| Attribute | Type | Description |
|---|---|---|
| label | string = "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_message | string = "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
| Name | Type | Description |
|---|---|---|
| *args | any | Variable length argument list. |
| **kwargs | any | Arbitrary 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
| Name | Type | Description |
|---|---|---|
| parser | ArgumentParser | The argument parser instance to which the label positional arguments will be added. |
Returns
| Type | Description |
|---|---|
null | Nothing 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
| Name | Type | Description |
|---|---|---|
| labels | tuple | A sequence of arbitrary string arguments provided via the command line. |
| options | dict | A dictionary of configuration options and flags passed to the management command. |
Returns
| Type | Description |
|---|---|
string | A 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
| Name | Type | Description |
|---|---|---|
| label | string | The specific command-line argument currently being processed by the command. |
| options | dict | The configuration options and flags used to customize the behavior of the label processing. |
Returns
| Type | Description |
|---|---|
string | The output string resulting from processing the specific label, which will be collected by the handle method. |