dockge-cli/dockge_cli/commands/factory.py
Firq 537a0d8015
All checks were successful
/ backend-pylint (push) Successful in 11s
/ build-artifacts (push) Successful in 10s
/ publish-artifacts (push) Successful in 8s
Rewrote using command factory
2024-07-03 20:36:22 +02:00

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"]]
)
})