This commit is contained in:
2025-11-02 01:04:31 +03:00
parent 64c984a704
commit 9c58c10152
70 changed files with 341 additions and 391 deletions
+2 -2
View File
@@ -3,14 +3,14 @@ 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.")
+9 -6
View File
@@ -2,16 +2,20 @@ from argenta import Command, Response, Router
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"}
})
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):
# Получаем данные из глобального хранилища
@@ -19,4 +23,3 @@ def show_handler(response: Response):
if "user_name" in data:
print(f"User: {data['user_name']}")
print(f"Settings: {data.get('settings', {})}")
+2 -2
View File
@@ -2,15 +2,15 @@ from argenta import Command, Response, Router
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")
+2 -1
View File
@@ -2,12 +2,14 @@ from argenta import Command, Response, Router
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()
@@ -15,4 +17,3 @@ def check_handler(response: Response):
print(f"Storage contains {len(data)} item(s)")
else:
print("Storage is empty")
+10 -7
View File
@@ -2,25 +2,28 @@ from argenta import Command, Response, Router
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"
})
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")
+12 -13
View File
@@ -4,29 +4,29 @@ 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")
])
))
@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...")
@@ -35,4 +35,3 @@ def process_handler(response: Response):
for flag in response.input_flags:
if flag.status and flag.status.name == "INVALID":
print(f" Invalid flag: {flag.string_entity} = {flag.input_value}")