Add init init-global
This commit is contained in:
parent
f9cb9ebaef
commit
a90c447d5c
|
@ -16,8 +16,6 @@ from .hook_manager import HookType
|
|||
|
||||
logger = logging.getLogger("falyx")
|
||||
|
||||
__version__ = "0.1.0"
|
||||
|
||||
__all__ = [
|
||||
"Action",
|
||||
"ChainedAction",
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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")
|
|
@ -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,
|
||||
|
|
|
@ -1 +1 @@
|
|||
__version__ = "0.1.11"
|
||||
__version__ = "0.1.12"
|
||||
|
|
|
@ -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 <roland@rtj.dev>"]
|
||||
license = "MIT"
|
||||
|
|
Loading…
Reference in New Issue