61 lines
1.7 KiB
Python
61 lines
1.7 KiB
Python
#!/usr/bin/env python3
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
import tomllib
|
|
|
|
ORDER = ["vendor", "sync_templates", "sync_standards", "install_skills", "format_md"]
|
|
|
|
|
|
def usage() -> str:
|
|
return "Usage:\n python scripts/playbook.py -config <path>\n python scripts/playbook.py -h"
|
|
|
|
|
|
def load_config(path: Path) -> dict:
|
|
return tomllib.loads(path.read_text(encoding="utf-8"))
|
|
|
|
|
|
def run_action(name: str, config: dict, context: dict) -> int:
|
|
_ = config, context
|
|
print(f"[action] {name}")
|
|
return 0
|
|
|
|
|
|
def main(argv: list[str]) -> int:
|
|
if "-h" in argv or "-help" in argv:
|
|
print(usage())
|
|
return 0
|
|
if "-config" not in argv:
|
|
print("ERROR: -config is required.\n" + usage(), file=sys.stderr)
|
|
return 2
|
|
idx = argv.index("-config")
|
|
if idx + 1 >= len(argv) or not argv[idx + 1]:
|
|
print("ERROR: -config requires a path.\n" + usage(), file=sys.stderr)
|
|
return 2
|
|
|
|
config_path = Path(argv[idx + 1]).expanduser()
|
|
if not config_path.is_file():
|
|
print(f"ERROR: config not found: {config_path}", file=sys.stderr)
|
|
return 2
|
|
|
|
config = load_config(config_path)
|
|
playbook_config = config.get("playbook", {})
|
|
project_root = playbook_config.get("project_root")
|
|
if project_root:
|
|
root = Path(project_root).expanduser()
|
|
else:
|
|
root = config_path.parent
|
|
context = {"project_root": root.resolve(), "config_path": config_path.resolve()}
|
|
|
|
for name in ORDER:
|
|
if name in config:
|
|
result = run_action(name, config[name], context)
|
|
if result != 0:
|
|
return result
|
|
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main(sys.argv[1:]))
|