- introduce namespace-aware routing with RootParseResult, RouteResult, and InvocationContext - register submenus as FalyxNamespace entries and resolve them through _entry_map - refactor FalyxParser to parse only root options and leave recursive routing to Falyx - add prepare_route, resolve_route, and route dispatch flow to Falyx - update validator and completer to understand namespace entries and route results - unify help/TLDR rendering APIs and add custom_tldr support on Command - tighten Command.resolve_args error handling and parser type validation - improve CommandRunner dependency validation and argv handling - add BottomBar.has_items and improve wrapped executor error messages - add tests for execution options, resolve_args, command runner, and route-aware validation
99 lines
2.3 KiB
Python
99 lines
2.3 KiB
Python
import pytest
|
|
from rich.text import Text
|
|
|
|
from falyx import Falyx
|
|
from falyx.console import console
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_help_command(capsys):
|
|
flx = Falyx()
|
|
assert flx.help_command.arg_parser.aliases[0] == "HELP"
|
|
assert flx.help_command.arg_parser.command_key == "H"
|
|
await flx.execute_command("H")
|
|
|
|
captured = capsys.readouterr()
|
|
assert "Show this help menu" in captured.out
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_help_command_with_new_command(capsys):
|
|
flx = Falyx()
|
|
|
|
async def new_command(falyx: Falyx):
|
|
pass
|
|
|
|
flx.add_command(
|
|
"N",
|
|
"New Command",
|
|
new_command,
|
|
aliases=["TEST"],
|
|
help_text="This is a new command.",
|
|
)
|
|
await flx.execute_command("H")
|
|
|
|
captured = capsys.readouterr()
|
|
assert "This is a new command." in captured.out
|
|
assert "TEST" in captured.out and "N" in captured.out
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_render_help(capsys):
|
|
flx = Falyx()
|
|
|
|
async def sample_command(falyx: Falyx):
|
|
pass
|
|
|
|
flx.add_command(
|
|
"S",
|
|
"Sample Command",
|
|
sample_command,
|
|
aliases=["SC"],
|
|
help_text="This is a sample command.",
|
|
)
|
|
await flx.render_help()
|
|
|
|
captured = capsys.readouterr()
|
|
assert "This is a sample command." in captured.out
|
|
assert "SC" in captured.out and "S" in captured.out
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_help_command_by_tag(capsys):
|
|
flx = Falyx()
|
|
|
|
async def tagged_command(falyx: Falyx):
|
|
pass
|
|
|
|
flx.add_command(
|
|
"T",
|
|
"Tagged Command",
|
|
tagged_command,
|
|
tags=["tag1"],
|
|
help_text="This command is tagged.",
|
|
)
|
|
await flx.execute_command("H -t tag1")
|
|
|
|
captured = capsys.readouterr()
|
|
text = Text.from_ansi(captured.out)
|
|
assert "tag1" in text.plain
|
|
assert "This command is tagged." in text.plain
|
|
assert "HELP" not in text.plain
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_help_command_empty_tags(capsys):
|
|
flx = Falyx()
|
|
|
|
async def untagged_command(falyx: Falyx):
|
|
pass
|
|
|
|
flx.add_command(
|
|
"U", "Untagged Command", untagged_command, help_text="This command has no tags."
|
|
)
|
|
await flx.execute_command("H nonexistent_tag")
|
|
|
|
captured = capsys.readouterr()
|
|
text = Text.from_ansi(captured.out)
|
|
assert "Unexpected positional argument: nonexistent_tag" in text.plain
|