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 @@ -12,7 +12,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 @@ -21,7 +21,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", @@ -94,7 +94,7 @@ ) -@click.command(context_settings=CONTEXT_SETTINGS) +@db.command(context_settings=CONTEXT_SETTINGS) @click.argument("module", required=True) @click.option( "--db-name", diff --git a/swh/core/db/tests/test_cli.py b/swh/core/db/tests/test_cli.py --- a/swh/core/db/tests/test_cli.py +++ b/swh/core/db/tests/test_cli.py @@ -45,7 +45,9 @@ -h, --help Show this message and exit. Commands: - init Initialize the database for every Software Heritage module found in... + db-init Initialize a database for the Software Heritage . + init Initialize the database for every Software Heritage module found + in... """