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:
kolo
2025-12-04 21:55:19 +03:00
committed by GitHub
parent a2ac6a608f
commit ce7e24b924
210 changed files with 13770 additions and 1183 deletions
@@ -0,0 +1,23 @@
from argenta import Command, Response, Router
from argenta.command import Flag, Flags
router = Router(title="Example")
@router.command(
Command(
"example",
description="Example command with flags",
flags=Flags([
Flag("name"),
Flag("age")
]),
)
)
def example_handler(response: Response):
input_flags = response.input_flags
if input_flags:
print(f"Received {len(input_flags)} flag(s)")
else:
print("No flags provided")
@@ -0,0 +1,49 @@
from argenta import Command, Response, Router
from argenta.command import Flag, Flags, InputFlag
from argenta.command.flag import ValidationStatus
router = Router(title="Comprehensive Example")
@router.command(
Command(
"validate",
description="Validate all flags",
flags=Flags(
[
Flag("format", possible_values=["json", "xml"]),
Flag("output"),
Flag("force"),
]
),
)
)
def validate_handler(response: Response):
input_flags = response.input_flags
print("Flag validation results:")
valid_flags: list[InputFlag] = []
invalid_flags: list[InputFlag] = []
undefined_flags: list[InputFlag] = []
for flag in input_flags:
if flag.status == ValidationStatus.VALID:
valid_flags.append(flag)
print(f"{flag.string_entity}: {flag.input_value} (VALID)")
elif flag.status == ValidationStatus.INVALID:
invalid_flags.append(flag)
print(f"{flag.string_entity}: {flag.input_value} (INVALID)")
elif flag.status == ValidationStatus.UNDEFINED:
undefined_flags.append(flag)
print(f" ? {flag.string_entity}: {flag.input_value} (UNDEFINED)")
print("\nSummary:")
print(f" Valid flags: {len(valid_flags)}")
print(f" Invalid flags: {len(invalid_flags)}")
print(f" Undefined flags: {len(undefined_flags)}")
if valid_flags:
print("\nProcessing valid flags:")
for flag in valid_flags:
print(f" Processing {flag.name} = {flag.input_value}")
@@ -0,0 +1,36 @@
from argenta import Command, Response, Router
from argenta.command import Flag, Flags
router = Router(title="Get Flag Example")
@router.command(
Command(
"config",
description="Configure settings",
flags=Flags([
Flag("host"),
Flag("port"),
Flag("debug")
]),
)
)
def config_handler(response: Response):
input_flags = response.input_flags
host_flag = input_flags.get_flag_by_name("host")
port_flag = input_flags.get_flag_by_name("port")
debug_flag = input_flags.get_flag_by_name("debug")
if host_flag:
print(f"Host: {host_flag.input_value}")
if port_flag:
print(f"Port: {port_flag.input_value}")
if debug_flag:
print("Debug mode enabled")
missing_flag = input_flags.get_flag_by_name("nonexistent")
if missing_flag is None:
print("Flag 'nonexistent' not found")
@@ -0,0 +1,19 @@
from argenta import Command, Response, Router
from argenta.command.flag import InputFlag, InputFlags, ValidationStatus
router = Router(title="Add Flag Example")
@router.command(Command("test", description="Test command"))
def test_handler(response: Response):
# Create new InputFlags collection
new_flags = InputFlags()
# Add one flag
test_flag = InputFlag(
name="test", prefix="--", input_value="value", status=ValidationStatus.VALID
)
new_flags.add_flag(test_flag)
print(f"Flags count: {len(new_flags.flags)}")
print(f"First flag: {new_flags.flags[0].name}")
@@ -0,0 +1,24 @@
from argenta.command.flag import InputFlag, InputFlags, ValidationStatus
# Create InputFlags collection
flags = InputFlags()
# Create several flags
flag1 = InputFlag(
name="option1", prefix="--", input_value="value1", status=ValidationStatus.VALID
)
flag2 = InputFlag(
name="option2", prefix="--", input_value="value2", status=ValidationStatus.VALID
)
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)}")
for flag in flags:
print(f" - {flag.string_entity}: {flag.input_value}")
@@ -0,0 +1,27 @@
from argenta import Command, Response, Router
from argenta.command import Flag, Flags
router = Router(title="Bool Check Example")
@router.command(
Command(
"action",
description="Action with optional flags",
flags=Flags([Flag("option1"), Flag("option2")]),
)
)
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:
print(f" - {flag.name}: {flag.input_value}")
else:
print("No flags provided, using defaults")
# Alternative way to check
has_flags = bool(input_flags)
print(f"\nHas flags: {has_flags}")
@@ -0,0 +1,37 @@
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),
InputFlag(name="flag2", input_value="value2", status=ValidationStatus.VALID),
]
)
# Create second collection with same flags
flags2 = InputFlags(
[
InputFlag(name="flag1", input_value="value1", status=ValidationStatus.VALID),
InputFlag(name="flag2", input_value="value2", status=ValidationStatus.VALID),
]
)
# Create third collection with different values
flags3 = InputFlags(
[
InputFlag(name="flag1", input_value="different", status=ValidationStatus.VALID),
InputFlag(name="flag2", input_value="value2", status=ValidationStatus.VALID),
]
)
print(f"flags1 == flags2: {flags1 == flags2}") # True (same names)
print(
f"flags1 == flags3: {flags1 == flags3}"
) # 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 (different flags)
@@ -0,0 +1,33 @@
from argenta import Command, Response, Router
from argenta.command import Flag, Flags
from argenta.command.flag import InputFlag
router = Router(title="Contains Example")
@router.command(
Command(
"check",
description="Check flags",
flags=Flags([Flag("verbose"), Flag("debug"), Flag("quiet")]),
)
)
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")
# 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:
print("Verbose flag found using 'in' operator")