from click import MultiCommand class ProxyCommand(MultiCommand): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.__proxy = None def _get_proxy(self): raise NotImplementedError("_get_proxy") def __load(self): if self.__proxy is None: self.__proxy = self._get_proxy() def list_commands(self,ctx): self.__load() return self.__proxy.list_commands(ctx) def get_command(self,ctx,name): self.__load() return self.__proxy.get_command(ctx,name) def make_context(self, *args, **kwargs): self.__load() return self.__proxy.make_context(*args, **kwargs)