This commit is contained in:
2025-11-01 11:54:46 +03:00
parent e4a5c6d398
commit 9b28ef17ff
18 changed files with 916 additions and 2 deletions
+16
View File
@@ -0,0 +1,16 @@
from argenta import Router, Command, Response
from argenta.response import ResponseStatus
router = Router(title="Example")
@router.command(Command("greet", description="Greet the user"))
def greet_handler(response: Response):
# response автоматически передаётся в обработчик
# response.status содержит статус валидации флагов
# response.input_flags содержит все введённые флаги
if response.status == ResponseStatus.ALL_FLAGS_VALID:
print("Hello! All flags are valid.")
else:
print("Warning: Some flags have issues.")
+22
View File
@@ -0,0 +1,22 @@
from argenta import Router, Command, Response
router = Router(title="Data Example")
@router.command(Command("set", description="Set data"))
def set_handler(response: Response):
# Обновляем глобальное хранилище данных
response.update_data({
"user_name": "John",
"timestamp": "2024-01-01",
"settings": {"theme": "dark", "language": "ru"}
})
print("Data updated successfully")
@router.command(Command("show", description="Show data"))
def show_handler(response: Response):
# Получаем данные из глобального хранилища
data = response.get_data()
if "user_name" in data:
print(f"User: {data['user_name']}")
print(f"Settings: {data.get('settings', {})}")
+16
View File
@@ -0,0 +1,16 @@
from argenta import Router, Command, Response
router = Router(title="Get Data Example")
@router.command(Command("info", description="Show all stored data"))
def info_handler(response: Response):
# Получаем все данные из глобального хранилища
all_data = response.get_data()
if all_data:
print("Stored data:")
for key, value in all_data.items():
print(f" {key}: {value}")
else:
print("No data stored")
+18
View File
@@ -0,0 +1,18 @@
from argenta import Router, Command, Response
router = Router(title="Clear Data Example")
@router.command(Command("clear", description="Clear all stored data"))
def clear_handler(response: Response):
# Очищаем всё хранилище данных
response.clear_data()
print("All data cleared")
@router.command(Command("check", description="Check if data exists"))
def check_handler(response: Response):
data = response.get_data()
if data:
print(f"Storage contains {len(data)} item(s)")
else:
print("Storage is empty")
+26
View File
@@ -0,0 +1,26 @@
from argenta import Router, Command, Response
router = Router(title="Delete Data Example")
@router.command(Command("store", description="Store data"))
def store_handler(response: Response):
response.update_data({
"temp_key": "temporary value",
"important_key": "important value",
"another_key": "another value"
})
print("Data stored")
@router.command(Command("remove", description="Remove specific key"))
def remove_handler(response: Response):
# Удаляем конкретный ключ из хранилища
try:
response.delete_from_data("temp_key")
print("Key 'temp_key' deleted")
# Проверяем, что осталось
remaining = response.get_data()
print(f"Remaining keys: {list(remaining.keys())}")
except KeyError:
print("Key not found")
+38
View File
@@ -0,0 +1,38 @@
from argenta import Router, Command, Response
from argenta.command import Flag, Flags
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.value}")
# Работаем с флагами
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 and flag.status.name == "INVALID":
print(f" Invalid flag: {flag.string_entity} = {flag.input_value}")