mirror of
https://github.com/koloideal/Argenta.git
synced 2026-06-10 10:05:28 +03:00
docs
This commit is contained in:
@@ -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
|
||||
Reference in New Issue
Block a user