Response

Response is an object that is passed to the command handler. It is created automatically when processing user input and contains validation status and entered flags.

See also

Documentation for InputFlags — collection of entered command flags.

Documentation for ResponseStatus — command flag validation statuses.

Documentation for InputFlag — individual entered flag.


Initialization

1__init__(
2    self, status: ResponseStatus,
3    input_flags: InputFlags = EMPTY_INPUT_FLAGS,
4)

Creates a new response object.

  • status: Overall flag validation status from the ResponseStatus enumeration.

  • input_flags: Collection of entered flags (InputFlags). Empty by default.

Warning

Instances of this class are not intended for direct creation. They are automatically formed by the system and passed to the command handler as the first required argument.

Attributes:

status

Overall validation status of all command flags (ResponseStatus). Indicates whether there were any incorrect or unregistered flags among the entered ones.

input_flags

Collection of all flags passed with the command (InputFlags). Contains all processed flags with their values and validation statuses.

Usage example:

 1from argenta import Command, Response, Router
 2from argenta.response import ResponseStatus
 3
 4router = Router(title="Example")
 5
 6
 7@router.command(Command("greet", description="Greet the user"))
 8def greet_handler(response: Response):
 9    if response.status == ResponseStatus.ALL_FLAGS_VALID:
10        print("Hello! All flags are valid.")
11    else:
12        print("Warning: Some flags have issues.")

Working with Flags

Response provides access to entered flags through the input_flags attribute. You can check their presence, get values, and validation statuses.

Example of working with flags:

 1from argenta import Command, Response, Router
 2from argenta.command import Flag, Flags
 3from argenta.command.flag import ValidationStatus
 4from argenta.response import ResponseStatus
 5
 6router = Router(title="Flags Example")
 7
 8
 9@router.command(
10    Command(
11        "process",
12        description="Process with flags",
13        flags=Flags([Flag("format", possible_values=["json", "xml"]), Flag("verbose")]),
14    )
15)
16def process_handler(response: Response):
17    print(f"Status: {response.status}")
18
19    format_flag = response.input_flags.get_flag_by_name("format")
20    verbose_flag = response.input_flags.get_flag_by_name("verbose")
21
22    if format_flag:
23        format_value = format_flag.input_value
24        print(f"Format: {format_value}")
25
26    if verbose_flag:
27        print("Verbose mode enabled")
28
29    if response.status == ResponseStatus.ALL_FLAGS_VALID:
30        print("All flags are valid, proceeding...")
31    elif response.status == ResponseStatus.INVALID_VALUE_FLAGS:
32        print("Warning: Some flags have invalid values")
33        for flag in response.input_flags:
34            if flag.status == ValidationStatus.INVALID:
35                print(f"  Invalid flag: {flag.string_entity} = {flag.input_value}")

ResponseStatus

ResponseStatus is an enumeration that defines the overall validation status of all command flags. Used in the status attribute of the Response object.

ALL_FLAGS_VALID

1ResponseStatus.ALL_FLAGS_VALID = 'ALL_FLAGS_VALID'

All entered flags passed validation. There are no incorrect or unregistered flags.

UNDEFINED_FLAGS

1ResponseStatus.UNDEFINED_FLAGS = 'UNDEFINED_FLAGS'

Among the entered flags, there are unregistered ones, but no flags with incorrect values.

INVALID_VALUE_FLAGS

1ResponseStatus.INVALID_VALUE_FLAGS = 'INVALID_VALUE_FLAGS'

Among the entered flags, there are flags with incorrect values, but no unregistered ones.

UNDEFINED_AND_INVALID_FLAGS

1ResponseStatus.UNDEFINED_AND_INVALID_FLAGS = 'UNDEFINED_AND_INVALID_FLAGS'

Among the entered flags, there are both unregistered flags and flags with incorrect values.