mirror of
https://github.com/koloideal/Argenta.git
synced 2026-06-10 10:05:28 +03:00
docs
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
from argenta import Orchestrator, App
|
||||
from argenta.orchestrator.argparser import BooleanArgument, ArgParser
|
||||
from argenta import App, Orchestrator
|
||||
from argenta.orchestrator.argparser import ArgParser, BooleanArgument
|
||||
|
||||
arg_parser = ArgParser(processed_args=[BooleanArgument('config')])
|
||||
orchestrator = Orchestrator(
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
from argenta import Orchestrator, App
|
||||
from argenta import App, Orchestrator
|
||||
from argenta.orchestrator.argparser import ArgParser, ValueArgument
|
||||
|
||||
|
||||
# Определение аргументов приложения
|
||||
arguments = [
|
||||
ValueArgument(
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
from argenta import Router, Response
|
||||
from argenta import Response, Router
|
||||
from argenta.di import FromDishka
|
||||
from argenta.orchestrator.argparser import ArgSpace
|
||||
|
||||
|
||||
router = Router()
|
||||
|
||||
@router.command('get_args')
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
from argenta import Response, Router
|
||||
from argenta.di import FromDishka
|
||||
from argenta.orchestrator.argparser import (ArgSpace, BooleanArgument,
|
||||
ValueArgument)
|
||||
|
||||
router = Router()
|
||||
|
||||
@router.command('get_args')
|
||||
def get_args(response: Response, argspace: FromDishka[ArgSpace]):
|
||||
# Получение всех булевых флагов
|
||||
boolean_flags = argspace.get_by_type(BooleanArgument)
|
||||
print(f"Active flags: {[arg.name for arg in boolean_flags if arg.value]}")
|
||||
|
||||
# Получение всех аргументов со значениями
|
||||
value_args = argspace.get_by_type(ValueArgument)
|
||||
for arg in value_args:
|
||||
print(f"{arg.name} = {arg.value}")
|
||||
|
||||
# Подсчет количества аргументов каждого типа
|
||||
print(f"Boolean arguments: {len(argspace.get_by_type(BooleanArgument))}")
|
||||
print(f"Value arguments: {len(argspace.get_by_type(ValueArgument))}")
|
||||
@@ -0,0 +1,26 @@
|
||||
from argenta import Command
|
||||
from argenta.command import Flag, Flags
|
||||
|
||||
# Простая команда без флагов
|
||||
hello_cmd = Command(
|
||||
"hello",
|
||||
description="Greet the user"
|
||||
)
|
||||
|
||||
# Команда с описанием и псевдонимами
|
||||
quit_cmd = Command(
|
||||
"quit",
|
||||
description="Exit the application",
|
||||
aliases=["exit", "q"]
|
||||
)
|
||||
|
||||
# Команда с флагами
|
||||
deploy_cmd = Command(
|
||||
"deploy",
|
||||
description="Deploy application to server",
|
||||
flags=Flags([
|
||||
Flag("env", help="Environment name", possible_values=["dev", "prod"]),
|
||||
Flag("force", help="Force deployment")
|
||||
]),
|
||||
aliases=["dep"]
|
||||
)
|
||||
@@ -0,0 +1,18 @@
|
||||
from argenta import Router, Command, Response
|
||||
|
||||
router = Router(title="User Management")
|
||||
|
||||
@router.command(Command(
|
||||
"create-user",
|
||||
description="Create a new user account"
|
||||
))
|
||||
def handle_create_user(response):
|
||||
print("Creating new user...")
|
||||
|
||||
@router.command(Command(
|
||||
"delete-user",
|
||||
description="Delete existing user account",
|
||||
aliases=["remove-user", "rm-user"]
|
||||
))
|
||||
def handle_delete_user(response: Response):
|
||||
print("Deleting user...")
|
||||
@@ -0,0 +1,28 @@
|
||||
from argenta import Router, Command, Response
|
||||
from argenta.command import Flag, Flags
|
||||
|
||||
router = Router(title="Server Management")
|
||||
|
||||
@router.command(Command(
|
||||
"start",
|
||||
description="Start the server",
|
||||
flags=Flags([
|
||||
Flag("port", help="Server port", default="8080"),
|
||||
Flag("host", help="Server host", default="localhost"),
|
||||
Flag("debug", help="Enable debug mode")
|
||||
]),
|
||||
aliases=["run"]
|
||||
))
|
||||
def handle_start(response: Response):
|
||||
input_flags = response.input_flags
|
||||
port_flag = input_flags.get_flag_by_name("port")
|
||||
host_flag = input_flags.get_flag_by_name("host")
|
||||
debug_flag = input_flags.get_flag_by_name("debug")
|
||||
|
||||
host = host_flag.input_value if host_flag else "localhost"
|
||||
port = port_flag.input_value if port_flag else "8080"
|
||||
debug = debug_flag and debug_flag.input_value
|
||||
|
||||
print(f"Starting server on {host}:{port}")
|
||||
if debug:
|
||||
print("Debug mode: ON")
|
||||
@@ -0,0 +1,11 @@
|
||||
from argenta.command import InputCommand
|
||||
|
||||
# Парсинг команды без флагов
|
||||
cmd1 = InputCommand.parse("hello")
|
||||
print(cmd1.trigger) # "hello"
|
||||
print(len(cmd1.input_flags)) # 0
|
||||
|
||||
# Парсинг команды с флагами
|
||||
cmd2 = InputCommand.parse("deploy --env prod --force")
|
||||
print(cmd2.trigger) # "deploy"
|
||||
print(len(cmd2.input_flags)) # 2
|
||||
@@ -3,7 +3,6 @@ from sqlite3 import Connection
|
||||
from argenta import Response, Router
|
||||
from argenta.di import FromDishka
|
||||
|
||||
|
||||
router = Router()
|
||||
|
||||
@router.command('connect')
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
from argenta import Response, Router
|
||||
from argenta.orchestrator.argparser import ArgSpace
|
||||
from argenta.di import FromDishka
|
||||
|
||||
from argenta.orchestrator.argparser import ArgSpace
|
||||
|
||||
router = Router()
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from argenta import App
|
||||
from argenta.app import StaticDividingLine, DynamicDividingLine
|
||||
from argenta.app import DynamicDividingLine, StaticDividingLine
|
||||
|
||||
# Создание статической линии из символов "=" длиной 40
|
||||
static_line = StaticDividingLine(unit_part="=", length=40)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from argenta import App
|
||||
|
||||
|
||||
def empty_command_handler():
|
||||
print("Empty command handler called")
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from argenta import App
|
||||
|
||||
|
||||
def incorrect_input_syntax_handler(raw_command: str):
|
||||
print(f"Incorrect input syntax for command: {raw_command}")
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from argenta import App
|
||||
|
||||
|
||||
def repeated_input_flags_handler(raw_command: str):
|
||||
print(f"Repeated input flags: {raw_command}")
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from argenta import App
|
||||
|
||||
|
||||
def empty_command_handler():
|
||||
print("Empty input command")
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
from argenta import App
|
||||
from argenta.command import InputCommand
|
||||
|
||||
|
||||
def unknown_command_handler(command: InputCommand):
|
||||
print(f"Unknown input command with trigger: {command.trigger}")
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from argenta import App, Response
|
||||
|
||||
|
||||
def exit_command_handler(response: Response):
|
||||
print("Exit command handler")
|
||||
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
from argenta.command import Flags, Flag
|
||||
from argenta import Command
|
||||
import re
|
||||
|
||||
|
||||
# Создание коллекции с флагами
|
||||
flags = Flags([
|
||||
Flag("host", possible_values=re.compile(r"^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$")),
|
||||
Flag("port", possible_values=re.compile(r"^\d{1,5}$"))
|
||||
])
|
||||
|
||||
# Использование в команде
|
||||
cmd = Command(
|
||||
"start",
|
||||
description="Start the server",
|
||||
flags=flags
|
||||
)
|
||||
@@ -1,5 +1,6 @@
|
||||
from argenta import App
|
||||
|
||||
|
||||
def custom_print_function(text: str) -> None:
|
||||
"""Простая пользовательская функция вывода с префиксом."""
|
||||
print(f"Префикс: {text}")
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
# main.py
|
||||
from argenta import App, Orchestrator
|
||||
from routers import router
|
||||
|
||||
from argenta import App, Orchestrator
|
||||
|
||||
app: App = App()
|
||||
orchestrator: Orchestrator = Orchestrator()
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# routers.py
|
||||
from argenta import Router, Response, Command
|
||||
from argenta import Command, Response, Router
|
||||
|
||||
router = Router(title="Quickstart Example")
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from argenta.router import Router
|
||||
from argenta.command import Command
|
||||
from argenta.router import Router
|
||||
|
||||
user_router = Router(title="User Management")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user