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,19 +1,11 @@
|
||||
import shutil
|
||||
import sys
|
||||
import tempfile
|
||||
from argparse import ArgumentParser, Namespace, _SubParsersAction
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from falyx.__main__ import (
|
||||
bootstrap,
|
||||
find_falyx_config,
|
||||
get_parsers,
|
||||
init_callback,
|
||||
init_config,
|
||||
main,
|
||||
)
|
||||
from falyx.__main__ import bootstrap, find_falyx_config, init_config, main
|
||||
from falyx.parser import CommandArgumentParser
|
||||
|
||||
|
||||
@@ -94,38 +86,10 @@ async def test_init_config():
|
||||
assert args["name"] == "."
|
||||
|
||||
|
||||
def test_init_callback(tmp_path):
|
||||
"""Test if the init_callback function works correctly."""
|
||||
# Test project initialization
|
||||
args = Namespace(command="init", name=str(tmp_path))
|
||||
init_callback(args)
|
||||
assert (tmp_path / "falyx.yaml").exists()
|
||||
|
||||
|
||||
def test_init_global_callback():
|
||||
# Test global initialization
|
||||
args = Namespace(command="init_global")
|
||||
init_callback(args)
|
||||
assert (Path.home() / ".config" / "falyx" / "tasks.py").exists()
|
||||
assert (Path.home() / ".config" / "falyx" / "falyx.yaml").exists()
|
||||
|
||||
|
||||
def test_get_parsers():
|
||||
"""Test if the get_parsers function returns the correct parsers."""
|
||||
root_parser, subparsers = get_parsers()
|
||||
assert isinstance(root_parser, ArgumentParser)
|
||||
assert isinstance(subparsers, _SubParsersAction)
|
||||
|
||||
# Check if the 'init' command is available
|
||||
init_parser = subparsers.choices.get("init")
|
||||
assert init_parser is not None
|
||||
assert "name" == init_parser._get_positional_actions()[0].dest
|
||||
|
||||
|
||||
def test_main():
|
||||
"""Test if the main function runs with the correct arguments."""
|
||||
|
||||
sys.argv = ["falyx", "run", "?"]
|
||||
sys.argv = ["falyx", "?"]
|
||||
|
||||
with pytest.raises(SystemExit) as exc_info:
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user