diff --git a/setup.py b/setup.py --- a/setup.py +++ b/setup.py @@ -67,8 +67,7 @@ swh=swh.core.cli:main swh-db-init=swh.core.cli.db:db_init [swh.cli.subcommands] - db=swh.core.cli.db:db - db-init=swh.core.cli.db:db_init + db=swh.core.cli.db [pytest11] pytest_swh_core = swh.core.pytest_plugin """, diff --git a/swh/core/cli/__init__.py b/swh/core/cli/__init__.py --- a/swh/core/cli/__init__.py +++ b/swh/core/cli/__init__.py @@ -5,6 +5,7 @@ import logging import logging.config +import warnings import click import pkg_resources @@ -115,7 +116,17 @@ for entry_point in pkg_resources.iter_entry_points("swh.cli.subcommands"): try: cmd = entry_point.load() - swh.add_command(cmd, name=entry_point.name) + if isinstance(cmd, click.BaseCommand): + # for BW compat, auto add click commands + warnings.warn( + f"{entry_point.name}: automagic addition of click commands " + f"to the main swh group is deprecated", + DeprecationWarning, + ) + swh.add_command(cmd, name=entry_point.name) + # otherwise it's expected to be a module which has been loaded + # it's the responsibility of the click commands/groups in this + # module to transitively have the main swh group as parent. except Exception as e: logger.warning("Could not load subcommand %s: %s", entry_point.name, str(e)) diff --git a/swh/core/cli/db.py b/swh/core/cli/db.py --- a/swh/core/cli/db.py +++ b/swh/core/cli/db.py @@ -10,7 +10,7 @@ import click -from swh.core.cli import CONTEXT_SETTINGS +from swh.core.cli import CONTEXT_SETTINGS, swh as swh_cli_group warnings.filterwarnings("ignore") # noqa prevent psycopg from telling us sh*t @@ -19,7 +19,7 @@ logger = logging.getLogger(__name__) -@click.group(name="db", context_settings=CONTEXT_SETTINGS) +@swh_cli_group.group(name="db", context_settings=CONTEXT_SETTINGS) @click.option( "--config-file", "-C", @@ -101,7 +101,7 @@ ) -@click.command(context_settings=CONTEXT_SETTINGS) +@db.command(context_settings=CONTEXT_SETTINGS) @click.argument("module", nargs=-1, required=True) @click.option( "--db-name",