diff options
author | Christian Geier <geier@lostpackets.de> | 2023-10-29 17:18:44 +0100 |
---|---|---|
committer | Christian Geier <geier@lostpackets.de> | 2024-04-12 14:18:09 +0200 |
commit | d587ba3a5b626afb8f89aa76097158c06a86c212 (patch) | |
tree | b7853923a5d20e1bb3b3dc297847cdeafdf74728 | |
parent | bd62be84e0b49c0d807e278bf798f897a1d2db82 (diff) |
load plugins and remove dead code
-rw-r--r-- | khal/cli.py | 16 | ||||
-rw-r--r-- | khal/plugins.py | 6 |
2 files changed, 18 insertions, 4 deletions
diff --git a/khal/cli.py b/khal/cli.py index 41942a2b..b9b77b6a 100644 --- a/khal/cli.py +++ b/khal/cli.py @@ -35,6 +35,7 @@ from .exceptions import FatalError from .settings import InvalidSettingsError, NoConfigFile, get_config from .terminal import colored from .utils import human_formatter, json_formatter +from .plugins import COMMANDS try: from setproctitle import setproctitle @@ -59,10 +60,6 @@ def time_args(f): def multi_calendar_select(ctx, include_calendars, exclude_calendars): if include_calendars and exclude_calendars: raise click.UsageError('Can\'t use both -a and -d.') - # if not isinstance(include_calendars, tuple): - # include_calendars = (include_calendars,) - # if not isinstance(exclude_calendars, tuple): - # exclude_calendars = (exclude_calendars,) selection = set() @@ -240,6 +237,17 @@ def stringify_conf(conf): return '\n'.join(out) +class _KhalGroup(click.Group): + def list_commands(self, ctx): + return super().list_commands(ctx) + list(COMMANDS.keys()) + + def get_command(self, ctx, name): + if name in COMMANDS: + logger.debug(f'found command {name} as a plugin') + return COMMANDS[name] + return super().get_command(ctx, name) + + @click.group() @click_log.simple_verbosity_option('khal') @global_options diff --git a/khal/plugins.py b/khal/plugins.py index 07a67944..c9fe37b1 100644 --- a/khal/plugins.py +++ b/khal/plugins.py @@ -21,3 +21,9 @@ def _load_color_themes() -> Dict[str, List[Tuple[str, ...]]]: return {ep.name: ep.load() for ep in color_theme_entrypoints} THEMES: Dict[str, List[Tuple[str, ...]],] = _load_color_themes() + +def _load_commands() -> dict[str, Callable]: + command_entrypoints = importlib_metadata.entry_points(group="khal.commands") + return {ep.name: ep.load() for ep in command_entrypoints} + +COMMANDS: dict[str, Callable] = _load_commands() |