Update documentation and code snippets

This commit is contained in:
2025-12-02 10:51:44 +03:00
parent 2a96dfcabe
commit 19906c1b1b
28 changed files with 85 additions and 531 deletions
+6 -5
View File
@@ -1,22 +1,23 @@
from argenta import Command, Response, Router
from argenta.command import Flag, Flags
router = Router(title="Example")
router = Router(title="Example")
@router.command(
Command(
"example",
description="Example command with flags",
flags=Flags([Flag("name"), Flag("age")]),
flags=Flags([
Flag("name"),
Flag("age")
]),
)
)
def example_handler(response: Response):
# response.input_flags содержит коллекцию InputFlags
input_flags = response.input_flags
# Проверяем наличие флагов
if input_flags:
print(f"Received {len(input_flags.flags)} flag(s)")
print(f"Received {len(input_flags)} flag(s)")
else:
print("No flags provided")
+4 -7
View File
@@ -1,5 +1,5 @@
from argenta import Command, Response, Router
from argenta.command import Flag, Flags
from argenta.command import Flag, Flags, InputFlag
from argenta.command.flag import ValidationStatus
router = Router(title="Comprehensive Example")
@@ -21,12 +21,11 @@ router = Router(title="Comprehensive Example")
def validate_handler(response: Response):
input_flags = response.input_flags
# Итерируемся по всем флагам и проверяем их статусы
print("Flag validation results:")
valid_flags = []
invalid_flags = []
undefined_flags = []
valid_flags: list[InputFlag] = []
invalid_flags: list[InputFlag] = []
undefined_flags: list[InputFlag] = []
for flag in input_flags:
if flag.status == ValidationStatus.VALID:
@@ -39,13 +38,11 @@ def validate_handler(response: Response):
undefined_flags.append(flag)
print(f" ? {flag.string_entity}: {flag.input_value} (UNDEFINED)")
# Выводим сводку
print("\nSummary:")
print(f" Valid flags: {len(valid_flags)}")
print(f" Invalid flags: {len(invalid_flags)}")
print(f" Undefined flags: {len(undefined_flags)}")
# Обрабатываем только валидные флаги
if valid_flags:
print("\nProcessing valid flags:")
for flag in valid_flags:
+5 -3
View File
@@ -8,13 +8,16 @@ router = Router(title="Get Flag Example")
Command(
"config",
description="Configure settings",
flags=Flags([Flag("host"), Flag("port"), Flag("debug")]),
flags=Flags([
Flag("host"),
Flag("port"),
Flag("debug")
]),
)
)
def config_handler(response: Response):
input_flags = response.input_flags
# Получаем флаг по имени
host_flag = input_flags.get_flag_by_name("host")
port_flag = input_flags.get_flag_by_name("port")
debug_flag = input_flags.get_flag_by_name("debug")
@@ -28,7 +31,6 @@ def config_handler(response: Response):
if debug_flag:
print("Debug mode enabled")
# Если флаг не найден, get_flag_by_name вернёт None
missing_flag = input_flags.get_flag_by_name("nonexistent")
if missing_flag is None:
print("Flag 'nonexistent' not found")
@@ -1,26 +0,0 @@
from argenta import Command, Response, Router
from argenta.command import Flag, Flags
router = Router(title="Iterate Example")
@router.command(
Command(
"process",
description="Process with multiple flags",
flags=Flags([Flag("file"), Flag("format"), Flag("output")]),
)
)
def process_handler(response: Response):
input_flags = response.input_flags
# Итерируемся по всем введённым флагам
print("All flags:")
for flag in input_flags:
status_str = flag.status.name if flag.status else "None"
print(f" {flag.string_entity}: {flag.input_value} (status: {status_str})")
# Также можно использовать enumerate для получения индексов
print("\nFlags with indices:")
for index, flag in enumerate(input_flags):
print(f" [{index}] {flag.name}: {flag.input_value}")
@@ -1,29 +0,0 @@
from argenta import Command, Response, Router
from argenta.command import Flag, Flags
router = Router(title="Index Access Example")
@router.command(
Command(
"example",
description="Example with indexed access",
flags=Flags([Flag("first"), Flag("second"), Flag("third")]),
)
)
def example_handler(response: Response):
input_flags = response.input_flags
# Получаем флаги по индексу
if len(input_flags.flags) > 0:
first_flag = input_flags[0]
print(f"First flag: {first_flag.name} = {first_flag.input_value}")
if len(input_flags.flags) > 1:
second_flag = input_flags[1]
print(f"Second flag: {second_flag.name} = {second_flag.input_value}")
# Можно использовать срез для получения нескольких флагов
if len(input_flags.flags) >= 2:
first_two = input_flags.flags[:2]
print(f"First two flags: {[f.name for f in first_two]}")