diff --git a/falyx/__init__.py b/falyx/__init__.py index 10b5003..8c0c713 100644 --- a/falyx/__init__.py +++ b/falyx/__init__.py @@ -16,8 +16,6 @@ from .hook_manager import HookType logger = logging.getLogger("falyx") -__version__ = "0.1.0" - __all__ = [ "Action", "ChainedAction", diff --git a/falyx/__main__.py b/falyx/__main__.py index 367a901..7832d45 100644 --- a/falyx/__main__.py +++ b/falyx/__main__.py @@ -7,11 +7,12 @@ Licensed under the MIT License. See LICENSE file for details. import asyncio import sys +from argparse import Namespace from pathlib import Path from falyx.config import loader from falyx.falyx import Falyx -from falyx.parsers import get_arg_parsers +from falyx.parsers import FalyxParsers, get_arg_parsers def find_falyx_config() -> Path | None: @@ -32,12 +33,39 @@ def bootstrap() -> Path | None: return config_path +def parse_args() -> Namespace: + falyx_parsers: FalyxParsers = get_arg_parsers() + init_parser = falyx_parsers.subparsers.add_parser( + "init", help="Create a new Falyx CLI project" + ) + init_parser.add_argument("name", nargs="?", default=".", help="Project directory") + falyx_parsers.subparsers.add_parser( + "init-global", help="Set up ~/.config/falyx with example tasks" + ) + + return falyx_parsers.parse_args() + + def main() -> None: + args = parse_args() + + if args.command == "init": + from falyx.init import init_project + + init_project(args.name) + return + + if args.command == "init-global": + from falyx.init import init_global + + init_global() + return + bootstrap_path = bootstrap() if not bootstrap_path: print("No Falyx config file found. Exiting.") return None - args = get_arg_parsers().parse_args() + flx = Falyx( title="๐Ÿ› ๏ธ Config-Driven CLI", cli_args=args, diff --git a/falyx/init.py b/falyx/init.py new file mode 100644 index 0000000..caa4725 --- /dev/null +++ b/falyx/init.py @@ -0,0 +1,75 @@ +# Falyx CLI Framework โ€” (c) 2025 rtj.dev LLC โ€” MIT Licensed +from pathlib import Path + +from rich.console import Console + +TEMPLATE_TASKS = """\ +async def build(): + print("๐Ÿ”จ Building project...") + +async def test(): + print("๐Ÿงช Running tests...") +""" + +TEMPLATE_CONFIG = """\ +- key: B + description: Build the project + action: tasks.build + aliases: [build] + spinner: true + +- key: T + description: Run tests + action: tasks.test + aliases: [test] + spinner: true +""" + +console = Console(color_system="auto") + + +def init_project(name: str = "."): + target = Path(name).resolve() + target.mkdir(parents=True, exist_ok=True) + + tasks_path = target / "tasks.py" + config_path = target / "falyx.yaml" + + if tasks_path.exists() or config_path.exists(): + console.print(f"โš ๏ธ Project already initialized at {target}") + return + + tasks_path.write_text(TEMPLATE_TASKS) + config_path.write_text(TEMPLATE_CONFIG) + + print(f"โœ… Initialized Falyx project in {target}") + + +def init_global(): + config_dir = Path.home() / ".config" / "falyx" + config_dir.mkdir(parents=True, exist_ok=True) + + tasks_path = config_dir / "tasks.py" + config_path = config_dir / "falyx.yaml" + + if tasks_path.exists() or config_path.exists(): + console.print("โš ๏ธ Global Falyx config already exists at ~/.config/falyx") + return + + tasks_path.write_text( + """\ +async def cleanup(): + print("๐Ÿงน Cleaning temp files...") +""" + ) + + config_path.write_text( + """\ +- key: C + description: Cleanup temp files + action: tasks.cleanup + aliases: [clean, cleanup] +""" + ) + + console.print("โœ… Initialized global Falyx config at ~/.config/falyx") diff --git a/falyx/parsers.py b/falyx/parsers.py index 49fa327..88979f0 100644 --- a/falyx/parsers.py +++ b/falyx/parsers.py @@ -2,7 +2,7 @@ """parsers.py This module contains the argument parsers used for the Falyx CLI. """ -from argparse import ArgumentParser, HelpFormatter, Namespace +from argparse import ArgumentParser, Namespace, _SubParsersAction from dataclasses import asdict, dataclass from typing import Any, Sequence @@ -12,6 +12,7 @@ class FalyxParsers: """Defines the argument parsers for the Falyx CLI.""" root: ArgumentParser + subparsers: _SubParsersAction run: ArgumentParser run_all: ArgumentParser preview: ArgumentParser @@ -151,6 +152,7 @@ def get_arg_parsers( return FalyxParsers( root=parser, + subparsers=subparsers, run=run_parser, run_all=run_all_parser, preview=preview_parser, diff --git a/falyx/version.py b/falyx/version.py index 0c5c300..74acd0e 100644 --- a/falyx/version.py +++ b/falyx/version.py @@ -1 +1 @@ -__version__ = "0.1.11" +__version__ = "0.1.12" diff --git a/pyproject.toml b/pyproject.toml index 4efe864..83869b3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "falyx" -version = "0.1.11" +version = "0.1.12" description = "Reliable and introspectable async CLI action framework." authors = ["Roland Thomas Jr "] license = "MIT"