Update documentation and code snippets

This commit is contained in:
2025-12-02 22:26:30 +03:00
parent eae8cdbb58
commit e6645730f0
8 changed files with 37 additions and 37 deletions
+6 -5
View File
@@ -6,6 +6,7 @@ app = App(
prompt=">> ",
initial_message="Simple App",
farewell_message="Goodbye!",
repeat_command_groups_printing=False
)
orchestrator = Orchestrator()
@@ -14,11 +15,11 @@ main_router = Router(title="Main commands")
# 3. Define command and its handler
@main_router.command(
Command(
"hello", description="Prints greeting message", flags=Flag("name")
)
)
@main_router.command(Command(
"hello",
description="Prints greeting message",
flags=Flag("name")
))
def hello_handler(response: Response):
"""This handler will be called for 'hello' command."""
name = response.input_flags.get_flag_by_name("name")
@@ -1,7 +1,7 @@
from typing import cast
from argenta import Command, Response, Router
from argenta.command.flag import ValidationStatus, Flag, Flags
from argenta.command.flag import Flag, Flags, ValidationStatus
from argenta.di import FromDishka
from .repository import Priority, Task, TaskRepository
@@ -9,26 +9,25 @@ from .repository import Priority, Task, TaskRepository
router = Router(title="Task Manager")
@router.command(
Command(
@router.command(Command(
"add-task",
description="Add a new task",
flags=Flags(
[
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.status == ValidationStatus.VALID:
print("Error: --description flag is required.")
return
task_description = description_flag.input_value or ""
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:
@@ -38,12 +37,14 @@ def add_task(response: Response, repo: FromDishka[TaskRepository]):
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
+2 -2
View File
@@ -25,7 +25,7 @@
**Результат**
.. image:: https://i.ibb.co/JwK9Vv4j/2025-11-03-135118.png
.. image:: https://i.ibb.co/35q24Bh8/image.png
:alt: Simple App Example
-----
@@ -43,7 +43,7 @@
2. **Определение моделей данных и репозитория**
Сначала определим модели данных для задачи и репозиторий для их хранения. Это будет наша "бизнес-логика".
Сначала определим модели данных для задачи и репозиторий для их хранения.
.. literalinclude:: ../code_snippets/quickstart/task_manager/repository.py
:language: python