mirror of
https://github.com/koloideal/Argenta.git
synced 2026-06-10 10:05:28 +03:00
feat: impl docs (#4)
The entire public api is covered with documentation in two languages - Russian and English. the library now supports the latest three versions of python - 3.12, 3.13 and 3.14 minor design changes: now, when a Boolean flag is entered, its value is an empty string, not None. tests have been adapted to the supported versions of python, readmi has been redesigned in two languages, German is no longer available.
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
from typing import cast
|
||||
|
||||
from argenta import Command, Response, Router
|
||||
from argenta.command.flag import Flag, Flags, 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.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:
|
||||
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})")
|
||||
Reference in New Issue
Block a user