mirror of
https://github.com/koloideal/Argenta.git
synced 2026-06-10 10:05:28 +03:00
Update documentation and code snippets
This commit is contained in:
@@ -6,10 +6,10 @@ router = Router(title="Add Flag Example")
|
||||
|
||||
@router.command(Command("test", description="Test command"))
|
||||
def test_handler(response: Response):
|
||||
# Создаём новую коллекцию InputFlags
|
||||
# Create new InputFlags collection
|
||||
new_flags = InputFlags()
|
||||
|
||||
# Добавляем один флаг
|
||||
# Add one flag
|
||||
test_flag = InputFlag(
|
||||
name="test", prefix="--", input_value="value", status=ValidationStatus.VALID
|
||||
)
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
from argenta.command.flag import InputFlag, InputFlags, ValidationStatus
|
||||
|
||||
# Создаём коллекцию InputFlags
|
||||
# Create InputFlags collection
|
||||
flags = InputFlags()
|
||||
|
||||
# Создаём несколько флагов
|
||||
# Create several flags
|
||||
flag1 = InputFlag(
|
||||
name="option1", prefix="--", input_value="value1", status=ValidationStatus.VALID
|
||||
)
|
||||
@@ -16,7 +16,7 @@ flag3 = InputFlag(
|
||||
name="option3", prefix="---", input_value="value3", status=ValidationStatus.VALID
|
||||
)
|
||||
|
||||
# Добавляем все флаги одним вызовом
|
||||
# Add all flags in one call
|
||||
flags.add_flags([flag1, flag2, flag3])
|
||||
|
||||
print(f"Total flags: {len(flags.flags)}")
|
||||
|
||||
@@ -14,7 +14,7 @@ router = Router(title="Bool Check Example")
|
||||
def action_handler(response: Response):
|
||||
input_flags = response.input_flags
|
||||
|
||||
# Проверяем наличие флагов
|
||||
# Check for flags presence
|
||||
if input_flags:
|
||||
print("Flags were provided:")
|
||||
for flag in input_flags:
|
||||
@@ -22,6 +22,6 @@ def action_handler(response: Response):
|
||||
else:
|
||||
print("No flags provided, using defaults")
|
||||
|
||||
# Альтернативный способ проверки
|
||||
# Alternative way to check
|
||||
has_flags = bool(input_flags)
|
||||
print(f"\nHas flags: {has_flags}")
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from argenta.command.flag import InputFlag, ValidationStatus
|
||||
from argenta.command.flag.flags.models import InputFlags
|
||||
|
||||
# Создаём первую коллекцию
|
||||
# Create first collection
|
||||
flags1 = InputFlags(
|
||||
[
|
||||
InputFlag(name="flag1", input_value="value1", status=ValidationStatus.VALID),
|
||||
@@ -9,7 +9,7 @@ flags1 = InputFlags(
|
||||
]
|
||||
)
|
||||
|
||||
# Создаём вторую коллекцию с теми же флагами
|
||||
# Create second collection with same flags
|
||||
flags2 = InputFlags(
|
||||
[
|
||||
InputFlag(name="flag1", input_value="value1", status=ValidationStatus.VALID),
|
||||
@@ -17,7 +17,7 @@ flags2 = InputFlags(
|
||||
]
|
||||
)
|
||||
|
||||
# Создаём третью коллекцию с другими флагами
|
||||
# Create third collection with different values
|
||||
flags3 = InputFlags(
|
||||
[
|
||||
InputFlag(name="flag1", input_value="different", status=ValidationStatus.VALID),
|
||||
@@ -25,13 +25,13 @@ flags3 = InputFlags(
|
||||
]
|
||||
)
|
||||
|
||||
print(f"flags1 == flags2: {flags1 == flags2}") # True (одинаковые имена)
|
||||
print(f"flags1 == flags2: {flags1 == flags2}") # True (same names)
|
||||
print(
|
||||
f"flags1 == flags3: {flags1 == flags3}"
|
||||
) # True (имена одинаковые, значения не учитываются)
|
||||
) # True (same names, values are not considered)
|
||||
|
||||
# Разные коллекции
|
||||
# Different collections
|
||||
flags4 = InputFlags(
|
||||
[InputFlag(name="flag3", input_value="value3", status=ValidationStatus.VALID)]
|
||||
)
|
||||
print(f"flags1 == flags4: {flags1 == flags4}") # False (разные флаги)
|
||||
print(f"flags1 == flags4: {flags1 == flags4}") # False (different flags)
|
||||
|
||||
@@ -15,18 +15,18 @@ router = Router(title="Contains Example")
|
||||
def check_handler(response: Response):
|
||||
input_flags = response.input_flags
|
||||
|
||||
# Проверяем наличие конкретного флага
|
||||
# Check for specific flag presence
|
||||
verbose_flag = input_flags.get_flag_by_name("verbose")
|
||||
debug_flag = input_flags.get_flag_by_name("debug")
|
||||
|
||||
# Используем оператор in для проверки
|
||||
# Use 'in' operator for checking
|
||||
if verbose_flag and verbose_flag in input_flags:
|
||||
print("Verbose flag is present")
|
||||
|
||||
if debug_flag and debug_flag in input_flags:
|
||||
print("Debug flag is present")
|
||||
|
||||
# Можно создать флаг для проверки (сравнение идёт по имени)
|
||||
# You can create a flag for checking (comparison is by name)
|
||||
test_flag = InputFlag(name="verbose", prefix="--", input_value="any", status=None)
|
||||
|
||||
if test_flag in input_flags:
|
||||
|
||||
Reference in New Issue
Block a user