foiaghost/src/beakers/cli.py

36 lines
671 B
Python
Raw Normal View History

2023-05-08 03:55:02 +00:00
import importlib
import typer
import sys
from typing_extensions import Annotated
app = typer.Typer()
def _load_recipe(dotted_path: str):
sys.path.append(".")
path, name = dotted_path.rsplit(".", 1)
mod = importlib.import_module(path)
return getattr(mod, name)
@app.command()
def reset(recipe: Annotated[str, typer.Option(...)]):
mod = _load_recipe(recipe)
mod.reset()
@app.command()
def show(recipe: Annotated[str, typer.Option(...)]):
mod = _load_recipe(recipe)
mod.show()
@app.command()
def run(recipe: Annotated[str, typer.Option(...)]):
mod = _load_recipe(recipe)
mod.run_once()
if __name__ == "__main__":
app()