31 lines
736 B
Python
31 lines
736 B
Python
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"]]
|
|
)
|
|
})
|