feat(core): centralize command execution and add standalone command runner
- add CommandExecutor to unify shared command execution lifecycle across Falyx and standalone command execution - add CommandRunner for running a single Command directly as a CLI or programmatic entrypoint - add Command.build() factory and rename parse_args() to resolve_args() to clarify the parsing-to-execution boundary - introduce ExecutionOption and wire execution-scoped flags into CommandArgumentParser and Command construction - refactor Falyx to use FalyxParser/ParseResult and CommandExecutor instead of the older argparse-based flow and run_key path - simplify __main__.py bootstrap by building a bootstrap Falyx instance directly and running flx.run() - improve completer support for preview commands and unique-prefix command resolution - default BottomBar toggle namespace to "default" - expand module/class docstrings to reflect the new execution architecture
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import pytest
|
||||
from rich.text import Text
|
||||
|
||||
from falyx import Falyx
|
||||
from falyx.console import console
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -8,7 +10,7 @@ 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.run_key("H")
|
||||
await flx.execute_command("H")
|
||||
|
||||
captured = capsys.readouterr()
|
||||
assert "Show this help menu" in captured.out
|
||||
@@ -28,7 +30,7 @@ async def test_help_command_with_new_command(capsys):
|
||||
aliases=["TEST"],
|
||||
help_text="This is a new command.",
|
||||
)
|
||||
await flx.run_key("H")
|
||||
await flx.execute_command("H")
|
||||
|
||||
captured = capsys.readouterr()
|
||||
assert "This is a new command." in captured.out
|
||||
@@ -70,12 +72,14 @@ async def test_help_command_by_tag(capsys):
|
||||
tags=["tag1"],
|
||||
help_text="This command is tagged.",
|
||||
)
|
||||
await flx.run_key("H", args=("tag1",))
|
||||
await flx.execute_command("H -t tag1")
|
||||
|
||||
captured = capsys.readouterr()
|
||||
assert "tag1" in captured.out
|
||||
assert "This command is tagged." in captured.out
|
||||
assert "HELP" not in captured.out
|
||||
print(captured.out)
|
||||
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
|
||||
@@ -88,9 +92,8 @@ async def test_help_command_empty_tags(capsys):
|
||||
flx.add_command(
|
||||
"U", "Untagged Command", untagged_command, help_text="This command has no tags."
|
||||
)
|
||||
await flx.run_key("H", args=("nonexistent_tag",))
|
||||
await flx.execute_command("H nonexistent_tag")
|
||||
|
||||
captured = capsys.readouterr()
|
||||
print(captured.out)
|
||||
assert "nonexistent_tag" in captured.out
|
||||
assert "Nothing to show here" in captured.out
|
||||
text = Text.from_ansi(captured.out)
|
||||
assert "Unexpected positional argument: nonexistent_tag" in text.plain
|
||||
|
||||
@@ -3,17 +3,14 @@ import sys
|
||||
import pytest
|
||||
|
||||
from falyx import Falyx
|
||||
from falyx.parser import get_arg_parsers
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_run_basic(capsys):
|
||||
sys.argv = ["falyx", "run", "-h"]
|
||||
falyx_parsers = get_arg_parsers()
|
||||
assert falyx_parsers is not None, "Falyx parsers should be initialized"
|
||||
sys.argv = ["falyx", "-h"]
|
||||
flx = Falyx()
|
||||
with pytest.raises(SystemExit):
|
||||
await flx.run(falyx_parsers)
|
||||
await flx.run()
|
||||
|
||||
captured = capsys.readouterr()
|
||||
assert "Run a command by its key or alias." in captured.out
|
||||
assert "Show this help menu." in captured.out
|
||||
|
||||
Reference in New Issue
Block a user