dockge-cli/dockge_cli/commands/factory.py

31 lines
736 B
Python
Raw Normal View History

2024-07-03 18:36:22 +00:00
import pathlib
import json
from typing import List, Callable
from pydantic import BaseModel
from ..components.bindings import binds
class Descriptor(BaseModel):
command: str
description: str
args: int
optional: bool
class Command(Descriptor):
binding: Callable
_descriptor_file = pathlib.Path(__file__).parent / "descriptors.json"
commands: dict[str, Command] = {}
with open(_descriptor_file, "r", encoding="utf-8") as file:
descriptors: List[Descriptor] = json.load(file)
for descriptor in descriptors:
commands.update({
descriptor["command"]:
Command(
**descriptor,
binding=binds[descriptor["command"]]
)
})