Files
Argenta/docs/code_snippets/response/snippet6.py
T
kolo ce7e24b924 feat: impl docs (#4)
The entire public api is covered with documentation in two languages - Russian and English.

the library now supports the latest three versions of python - 3.12, 3.13 and 3.14

minor design changes: now, when a Boolean flag is entered, its value is an empty string, not None.

tests have been adapted to the supported versions of python, readmi has been redesigned in two languages, German is no longer available.
2025-12-04 21:55:19 +03:00

39 lines
1.2 KiB
Python

from argenta import Command, Response, Router
from argenta.command import Flag, Flags
from argenta.command.flag import ValidationStatus
from argenta.response import ResponseStatus
router = Router(title="Flags Example")
@router.command(
Command(
"process",
description="Process with flags",
flags=Flags([
Flag("format", possible_values=["json", "xml"]),
Flag("verbose")
]),
)
)
def process_handler(response: Response):
print(f"Status: {response.status}")
format_flag = response.input_flags.get_flag_by_name("format")
verbose_flag = response.input_flags.get_flag_by_name("verbose")
if format_flag:
format_value = format_flag.input_value
print(f"Format: {format_value}")
if verbose_flag:
print("Verbose mode enabled")
if response.status == ResponseStatus.ALL_FLAGS_VALID:
print("All flags are valid, proceeding...")
elif response.status == ResponseStatus.INVALID_VALUE_FLAGS:
print("Warning: Some flags have invalid values")
for flag in response.input_flags:
if flag.status == ValidationStatus.INVALID:
print(f" Invalid flag: {flag.string_entity} = {flag.input_value}")