Update documentation and code snippets

This commit is contained in:
2026-01-22 22:02:19 +03:00
parent f9a85da430
commit f27f7b135b
26 changed files with 301 additions and 160 deletions
+2 -3
View File
@@ -1,9 +1,8 @@
from argenta import App, Orchestrator
from argenta.app import StaticDividingLine
from .handlers import router
app = App(initial_message="metrics", prompt=">>> ", dividing_line=None)
app = App(initial_message="metrics")
orchestrator = Orchestrator()
+2 -1
View File
@@ -1,4 +1,5 @@
from .pre_cycle_setup import *
from .most_similar_command import *
from .finds_appropriate_handler import *
from .validate_routers_for_collisions import *
from .validate_routers_for_collisions import *
from .input_command_parse import *
+3
View File
@@ -160,3 +160,6 @@ class Benchmarks:
def get_benchmark_by_name(self, name: str) -> Benchmark | None:
return self._benchmarks_paired_by_name.get(name)
def get_types(self) -> set[str]:
return set(self._benchmarks_grouped_by_type.keys())
+51
View File
@@ -0,0 +1,51 @@
__all__ = [
"benchmark_parse_simple_command",
"benchmark_command_with_few_flags",
"benchmark_command_with_flags_and_values",
"benchmark_command_with_mixed_prefixes",
"benchmark_command_with_long_values",
"benchmark_command_with_quoted_values",
"benchmark_extreme_many_flags"
]
from argenta.command.models import InputCommand
from .entity import benchmarks
@benchmarks.register(type_="input_command_parse", description="Simple command (no flags)")
def benchmark_parse_simple_command() -> None:
InputCommand.parse("start")
@benchmarks.register(type_="input_command_parse", description="Command with few flags (3 flags)")
def benchmark_command_with_few_flags() -> None:
InputCommand.parse("start -a -b -c")
@benchmarks.register(type_="input_command_parse", description="Command with flags and values (5 flags)")
def benchmark_command_with_flags_and_values() -> None:
InputCommand.parse("start --host localhost --port 8080 --debug --verbose -c config.json")
@benchmarks.register(type_="input_command_parse", description="Command with mixed prefixes (-, --, ---)")
def benchmark_command_with_mixed_prefixes() -> None:
InputCommand.parse("cmd -a --bb ---ccc -d value --ee value2 ---fff value3")
@benchmarks.register(type_="input_command_parse", description="Command with long values (10 flags)")
def benchmark_command_with_long_values() -> None:
long_value = "a" * 100
cmd = f"process --data {long_value} --config {long_value} --output {long_value}"
InputCommand.parse(cmd)
@benchmarks.register(type_="input_command_parse", description="Command with quoted values (5 flags)")
def benchmark_command_with_quoted_values() -> None:
InputCommand.parse("cmd --text 'hello world' --path '/usr/local/bin' --msg \"test message\"")
@benchmarks.register(type_="input_command_parse", description="Extreme (50 flags with values)")
def benchmark_extreme_many_flags() -> None:
flags = " ".join(f"--flag{i} value{i}" for i in range(50))
InputCommand.parse(f"command {flags}")
+60 -4
View File
@@ -1,6 +1,7 @@
from rich.console import Console
from argenta.command import Flag, PossibleValues
from argenta.command import Flag, PossibleValues, Flags
from argenta.command.flag import ValidationStatus
from argenta.command.models import Command
from argenta.response import Response
from argenta.router import Router
@@ -15,22 +16,77 @@ router = Router(title="Metrics commands:")
@router.command(
Command(
"all-print",
"run-all",
description="Print all benchmarks results",
flags=Flag('without-gc', possible_values=PossibleValues.NEITHER)
)
)
def all_print_handler(_: Response) -> None:
def all_print_handler(response: Response) -> None:
report_generator = ReportGenerator(get_system_info())
console.print(report_generator.generate_system_info_header())
console.print(report_generator.generate_system_info_table())
is_gc_disabled = _.input_flags.get_flag_by_name("without-gc")
is_gc_disabled = response.input_flags.get_flag_by_name("without-gc", with_status=ValidationStatus.VALID)
type_grouped_benchmarks: list[BenchmarkGroupResult] = registered_benchmarks.run_benchmarks_grouped_by_type(is_gc_disabled=is_gc_disabled)
for benchmark_group_result in type_grouped_benchmarks:
console.print(report_generator.generate_benchmark_table_header(benchmark_group_result))
console.print(report_generator.generate_benchmark_report_table(benchmark_group_result))
@router.command(Command("list-types", description="List all benchmark types"))
def list_types_handler(_: Response) -> None:
types = registered_benchmarks.get_types()
if not types:
console.print("[yellow]No benchmark types found[/yellow]")
return
console.print("[bold cyan]Available benchmark types:[/bold cyan]\n")
for type_ in types:
benchmarks_count = len(registered_benchmarks.get_benchmarks_by_type(type_))
console.print(f" [green]•[/green] [bold]{type_}[/bold] ({benchmarks_count} benchmarks)")
@router.command(
Command(
"run-type",
description="Run benchmarks by specific type",
flags=Flags([
Flag('type', possible_values=registered_benchmarks.get_types()),
Flag('without-gc', possible_values=PossibleValues.NEITHER)
])
)
)
def run_type_handler(response: Response) -> None:
type_flag = response.input_flags.get_flag_by_name("type")
if not type_flag:
console.print("[red]Error: --type flag is required[/red]")
console.print("[yellow]Usage: run-type --type <type_name>[/yellow]")
return
benchmark_type = type_flag.input_value
if not type_flag.status == ValidationStatus.VALID:
console.print(f"[red]Error: No benchmarks found for type '{benchmark_type}'[/red]")
console.print("\n[yellow]Available types:[/yellow]")
types = registered_benchmarks.get_types()
for t in types:
console.print(f"{t}")
return
report_generator = ReportGenerator(get_system_info())
console.print(report_generator.generate_system_info_header())
console.print(report_generator.generate_system_info_table())
is_gc_disabled = response.input_flags.get_flag_by_name("without-gc", with_status=ValidationStatus.VALID)
benchmark_group_result = registered_benchmarks.run_benchmarks_by_type(benchmark_type, is_gc_disabled=is_gc_disabled)
console.print(report_generator.generate_benchmark_table_header(benchmark_group_result))
console.print(report_generator.generate_benchmark_report_table(benchmark_group_result))
@router.command(Command("release-generate", description="Generate release report"))
def release_generate_handler(_: Response) -> None:
console.print("[yellow]Release report generation not implemented yet[/yellow]")