2024-12-07 18:16:01 -05:00
|
|
|
# https://github.com/anishathalye/dotbot/issues/339
|
|
|
|
# plugins should be able to instantiate a Dispatcher with all the plugins
|
|
|
|
|
2024-12-28 01:01:05 -05:00
|
|
|
from typing import Any
|
|
|
|
|
2024-12-07 18:16:01 -05:00
|
|
|
import dotbot
|
|
|
|
from dotbot.dispatcher import Dispatcher
|
|
|
|
|
|
|
|
|
|
|
|
class Dispatch(dotbot.Plugin):
|
2024-12-28 01:01:05 -05:00
|
|
|
def can_handle(self, directive: str) -> bool:
|
2024-12-07 18:16:01 -05:00
|
|
|
return directive == "dispatch"
|
|
|
|
|
2024-12-28 01:01:05 -05:00
|
|
|
def handle(self, directive: str, data: Any) -> bool:
|
|
|
|
if directive != "dispatch":
|
|
|
|
msg = f"Dispatch cannot handle directive {directive}"
|
|
|
|
raise ValueError(msg)
|
2024-12-07 18:16:01 -05:00
|
|
|
dispatcher = Dispatcher(
|
|
|
|
base_directory=self._context.base_directory(),
|
|
|
|
options=self._context.options(),
|
|
|
|
plugins=self._context.plugins(),
|
|
|
|
)
|
|
|
|
return dispatcher.dispatch(data)
|