mirror of
https://github.com/koloideal/Argenta.git
synced 2026-06-10 10:05:28 +03:00
docs
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from argenta import Router, Command, Response
|
||||
from argenta import Command, Response, Router
|
||||
|
||||
router = Router(title="User Management")
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from argenta import Router, Command, Response
|
||||
from argenta import Command, Response, Router
|
||||
from argenta.command import Flag, Flags
|
||||
|
||||
router = Router(title="Server Management")
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from argenta.command.flag.defaults import PredefinedFlags
|
||||
from argenta.command import Flags
|
||||
from argenta.command.flag.defaults import PredefinedFlags
|
||||
|
||||
# Использование предопределенных флагов при создании команды
|
||||
command_flags = Flags([
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
from argenta.command import Flag, PossibleValues
|
||||
import re
|
||||
|
||||
from argenta.command import Flag, PossibleValues
|
||||
|
||||
# Простой флаг с любыми значениями
|
||||
verbose_flag = Flag(name="verbose")
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
from argenta.command.flag.models import Flag, PossibleValues
|
||||
import re
|
||||
|
||||
from argenta.command.flag.models import Flag, PossibleValues
|
||||
|
||||
# Флаг со списком допустимых значений
|
||||
format_flag = Flag(name="format", possible_values=["json", "xml", "csv"])
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from argenta.command import Flags, Flag
|
||||
from argenta import Command
|
||||
import re
|
||||
|
||||
from argenta import Command
|
||||
from argenta.command import Flag, Flags
|
||||
|
||||
# Создание коллекции с флагами
|
||||
flags = Flags([
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from argenta.command import Flags, Flag
|
||||
from argenta.command import Flag, Flags
|
||||
|
||||
# Создание коллекции
|
||||
flags: Flags = Flags()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from argenta.command import Flags, Flag
|
||||
from argenta.command import Flag, Flags
|
||||
from argenta.command.flag.defaults import PredefinedFlags
|
||||
|
||||
# Начальная коллекция
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from argenta.command import Flags, Flag
|
||||
from argenta.command import Flag, Flags
|
||||
from argenta.command.flag.defaults import PredefinedFlags
|
||||
|
||||
flags = Flags([
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from argenta.command import Flags, Flag
|
||||
from argenta.command import Flag, Flags
|
||||
from argenta.command.flag.defaults import PredefinedFlags
|
||||
|
||||
flags = Flags([
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from argenta.command import Flags, Flag
|
||||
from argenta.command import Flag, Flags
|
||||
|
||||
flags = Flags([
|
||||
Flag("first"),
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from argenta import Router, Command, Response
|
||||
from argenta import Command, Response, Router
|
||||
from argenta.command import Flag, Flags
|
||||
|
||||
router = Router(title="Example")
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from argenta import Router, Command, Response
|
||||
from argenta import Command, Response, Router
|
||||
from argenta.command import Flag, Flags
|
||||
from argenta.command.flag import ValidationStatus
|
||||
|
||||
@@ -35,7 +35,7 @@ def validate_handler(response: Response):
|
||||
print(f" ? {flag.string_entity}: {flag.input_value} (UNDEFINED)")
|
||||
|
||||
# Выводим сводку
|
||||
print(f"\nSummary:")
|
||||
print("\nSummary:")
|
||||
print(f" Valid flags: {len(valid_flags)}")
|
||||
print(f" Invalid flags: {len(invalid_flags)}")
|
||||
print(f" Undefined flags: {len(undefined_flags)}")
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from argenta import Router, Command, Response
|
||||
from argenta import Command, Response, Router
|
||||
from argenta.command import Flag, Flags
|
||||
|
||||
router = Router(title="Get Flag Example")
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from argenta import Router, Command, Response
|
||||
from argenta.command.flag import InputFlag, ValidationStatus, InputFlags
|
||||
from argenta import Command, Response, Router
|
||||
from argenta.command.flag import InputFlag, InputFlags, ValidationStatus
|
||||
|
||||
router = Router(title="Add Flag Example")
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from argenta.command.flag import InputFlag, ValidationStatus, InputFlags
|
||||
from argenta.command.flag import InputFlag, InputFlags, ValidationStatus
|
||||
|
||||
# Создаём коллекцию InputFlags
|
||||
flags = InputFlags()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from argenta import Router, Command, Response
|
||||
from argenta import Command, Response, Router
|
||||
from argenta.command import Flag, Flags
|
||||
|
||||
router = Router(title="Iterate Example")
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from argenta import Router, Command, Response
|
||||
from argenta import Command, Response, Router
|
||||
from argenta.command import Flag, Flags
|
||||
|
||||
router = Router(title="Index Access Example")
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from argenta import Router, Command, Response
|
||||
from argenta import Command, Response, Router
|
||||
from argenta.command import Flag, Flags
|
||||
|
||||
router = Router(title="Bool Check Example")
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from argenta.command.flag.flags.models import InputFlags
|
||||
from argenta.command.flag import InputFlag, ValidationStatus
|
||||
from argenta.command.flag.flags.models import InputFlags
|
||||
|
||||
# Создаём первую коллекцию
|
||||
flags1 = InputFlags([
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from argenta import Router, Command, Response
|
||||
from argenta import Command, Response, Router
|
||||
from argenta.command import Flag, Flags
|
||||
from argenta.command.flag import InputFlag, ValidationStatus
|
||||
from argenta.command.flag import InputFlag
|
||||
|
||||
router = Router(title="Contains Example")
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
from argenta.command import Flag, PossibleValues
|
||||
import re
|
||||
|
||||
from argenta.command import Flag, PossibleValues
|
||||
|
||||
# Флаг без значения
|
||||
verbose_flag = Flag(
|
||||
name="verbose",
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
from typing import cast
|
||||
|
||||
from argenta import Command, Response, Router
|
||||
from argenta.command import Flag, Flags
|
||||
from argenta.command.flag.models import ValidationStatus
|
||||
from argenta.di import FromDishka
|
||||
|
||||
from .repository import Priority, Task, TaskRepository
|
||||
|
||||
router = Router(title="Task Manager")
|
||||
|
||||
@router.command(
|
||||
Command(
|
||||
"add-task",
|
||||
description="Add a new task",
|
||||
flags=Flags([
|
||||
Flag("description"),
|
||||
Flag("priority", possible_values=["low", "medium", "high"]),
|
||||
])
|
||||
)
|
||||
)
|
||||
def add_task(response: Response, repo: FromDishka[TaskRepository]):
|
||||
description_flag = response.input_flags.get_flag_by_name("description")
|
||||
|
||||
if not description_flag or not description_flag.input_value:
|
||||
print("Error: --description flag is required.")
|
||||
return
|
||||
task_description = description_flag.input_value
|
||||
|
||||
priority_flag = response.input_flags.get_flag_by_name("priority")
|
||||
|
||||
if priority_flag and priority_flag.status == ValidationStatus.VALID:
|
||||
priority_value = priority_flag.input_value
|
||||
else:
|
||||
priority_value = "medium"
|
||||
|
||||
priority = cast(Priority, priority_value)
|
||||
|
||||
task = Task(description=task_description, priority=priority)
|
||||
repo.add_task(task)
|
||||
print(f"Added task: '{task.description}' with priority '{task.priority}'")
|
||||
|
||||
@router.command(Command("list-tasks", description="List all tasks"))
|
||||
def list_tasks(response: Response, repo: FromDishka[TaskRepository]):
|
||||
tasks = repo.get_all_tasks()
|
||||
if not tasks:
|
||||
print("No tasks found.")
|
||||
return
|
||||
|
||||
print("Tasks:")
|
||||
for i, task in enumerate(tasks, 1):
|
||||
print(f" {i}. {task.description} (Priority: {task.priority})")
|
||||
@@ -0,0 +1,18 @@
|
||||
from argenta import App, Orchestrator
|
||||
|
||||
from .handlers import router
|
||||
from .provider import TaskProvider
|
||||
|
||||
# 1. Создаем экземпляр приложения
|
||||
app = App(
|
||||
initial_message="Task Manager",
|
||||
prompt="Enter a command: ",
|
||||
)
|
||||
|
||||
# 2. Подключаем роутер с нашими командами
|
||||
app.include_router(router)
|
||||
|
||||
# 3. Создаем и запускаем оркестратор
|
||||
if __name__ == "__main__":
|
||||
orchestrator = Orchestrator(custom_providers=[TaskProvider()])
|
||||
orchestrator.start_polling(app)
|
||||
@@ -0,0 +1,9 @@
|
||||
from dishka import Provider, Scope, provide
|
||||
|
||||
from .repository import TaskRepository
|
||||
|
||||
|
||||
class TaskProvider(Provider):
|
||||
@provide(scope=Scope.APP)
|
||||
def get_repository(self) -> TaskRepository:
|
||||
return TaskRepository()
|
||||
@@ -0,0 +1,19 @@
|
||||
from dataclasses import dataclass
|
||||
from typing import Literal
|
||||
|
||||
Priority = Literal["low", "medium", "high"]
|
||||
|
||||
@dataclass
|
||||
class Task:
|
||||
description: str
|
||||
priority: Priority = "medium"
|
||||
|
||||
class TaskRepository:
|
||||
def __init__(self):
|
||||
self._tasks: list[Task] = []
|
||||
|
||||
def add_task(self, task: Task):
|
||||
self._tasks.append(task)
|
||||
|
||||
def get_all_tasks(self) -> list[Task]:
|
||||
return self._tasks
|
||||
@@ -1,4 +1,4 @@
|
||||
from argenta import Router, Command, Response
|
||||
from argenta import Command, Response, Router
|
||||
from argenta.response import ResponseStatus
|
||||
|
||||
router = Router(title="Example")
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from argenta import Router, Command, Response
|
||||
from argenta import Command, Response, Router
|
||||
|
||||
router = Router(title="Data Example")
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from argenta import Router, Command, Response
|
||||
from argenta import Command, Response, Router
|
||||
|
||||
router = Router(title="Get Data Example")
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from argenta import Router, Command, Response
|
||||
from argenta import Command, Response, Router
|
||||
|
||||
router = Router(title="Clear Data Example")
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from argenta import Router, Command, Response
|
||||
from argenta import Command, Response, Router
|
||||
|
||||
router = Router(title="Delete Data Example")
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from argenta import Router, Command, Response
|
||||
from argenta import Command, Response, Router
|
||||
from argenta.command import Flag, Flags
|
||||
from argenta.response import ResponseStatus
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
from argenta.command.flag import Flag, InputFlag, ValidationStatus, PossibleValues
|
||||
import re
|
||||
|
||||
from argenta.command.flag import (Flag, InputFlag, PossibleValues,
|
||||
ValidationStatus)
|
||||
|
||||
# Создаём различные типы флагов
|
||||
verbose_flag = Flag("verbose", possible_values=PossibleValues.NEITHER)
|
||||
output_flag = Flag("output", possible_values=PossibleValues.ALL)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from argenta.command.flag import Flag, InputFlag, ValidationStatus, PossibleValues
|
||||
from argenta.command.flag import (Flag, InputFlag, PossibleValues,
|
||||
ValidationStatus)
|
||||
|
||||
# Создание флага без значения
|
||||
help_flag = Flag("help", possible_values=PossibleValues.NEITHER)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from argenta import InputFlag, ValidationStatus
|
||||
|
||||
|
||||
def process_input_flag(input_flag: InputFlag) -> None:
|
||||
"""Обрабатывает входной флаг в зависимости от его статуса валидации"""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user