39 lines
1.2 KiB
Python
39 lines
1.2 KiB
Python
from __future__ import annotations
|
|
|
|
import os
|
|
import sys
|
|
from abc import ABC
|
|
|
|
from retrobuilder.context import BuildContext
|
|
|
|
|
|
class BaseEntry(ABC):
|
|
def pre_gen(self, ctx: BuildContext) -> None: return None
|
|
def post_gen(self, ctx: BuildContext) -> None: return None
|
|
def pre_feature(self, ctx: BuildContext) -> None: return None
|
|
def post_feature(self, ctx: BuildContext) -> None: return None
|
|
|
|
|
|
class FeatureEntry(ABC):
|
|
def pre_gen(self, ctx: BuildContext) -> None: return None
|
|
def post_gen(self, ctx: BuildContext) -> None: return None
|
|
def pre_inj(self, ctx: BuildContext) -> None: return None
|
|
def post_inj(self, ctx: BuildContext) -> None: return None
|
|
|
|
|
|
def cli_dispatch(spec, entry_cls) -> int:
|
|
if len(sys.argv) < 2:
|
|
print("Usage: entry.py <spec|phase>", file=sys.stderr)
|
|
return 2
|
|
command = sys.argv[1]
|
|
if command == "spec":
|
|
print(spec.to_dict())
|
|
return 0
|
|
entry = entry_cls()
|
|
method = getattr(entry, command.replace("-", "_"), None)
|
|
if method is None:
|
|
print(f"Unsupported phase: {command}", file=sys.stderr)
|
|
return 2
|
|
method(BuildContext.from_env(os.environ))
|
|
return 0
|