diff --git a/swh/loader/cli.py b/swh/loader/cli.py --- a/swh/loader/cli.py +++ b/swh/loader/cli.py @@ -25,7 +25,7 @@ } -SUPPORTED_LOADERS = list(LOADERS) +SUPPORTED_LOADERS = sorted(list(LOADERS)) def get_loader(name: str, **kwargs) -> Any: diff --git a/swh/loader/tests/test_cli.py b/swh/loader/tests/test_cli.py --- a/swh/loader/tests/test_cli.py +++ b/swh/loader/tests/test_cli.py @@ -9,6 +9,7 @@ from swh.loader.cli import run, list, get_loader, SUPPORTED_LOADERS from swh.loader.package.loader import PackageLoader +from click.formatting import HelpFormatter from click.testing import CliRunner @@ -38,6 +39,12 @@ assert isinstance(loader, PackageLoader) +def _write_usage(command, args, max_width=80): + hf = HelpFormatter(width=max_width) + hf.write_usage(command, args) + return hf.getvalue()[:-1] + + def test_run_help(swh_config): """Help message should be ok @@ -46,15 +53,16 @@ result = runner.invoke(run, ["-h"]) assert result.exit_code == 0 - expected_help_msg = """Usage: run [OPTIONS] [archive|cran|debian|deposit|nixguix|npm|pypi] URL - [OPTIONS]... + usage_prefix = _write_usage( + "run", f"[OPTIONS] [{'|'.join(SUPPORTED_LOADERS)}] URL [OPTIONS]..." + ) + expected_help_msg = f"""{usage_prefix} Ingest with loader the origin located at Options: -h, --help Show this message and exit. -""" # noqa - +""" assert result.output.startswith(expected_help_msg) @@ -76,13 +84,16 @@ runner = CliRunner() result = runner.invoke(list, ["--help"]) assert result.exit_code == 0 - expected_help_msg = """Usage: list [OPTIONS] [[all|archive|cran|debian|deposit|nixguix|npm|pypi]] + usage_prefix = _write_usage( + "list", f"[OPTIONS] [[{'|'.join(['all'] + SUPPORTED_LOADERS)}]]" + ) + expected_help_msg = f"""{usage_prefix} List supported loaders and optionally their arguments Options: -h, --help Show this message and exit. -""" # noqa +""" assert result.output.startswith(expected_help_msg) @@ -93,7 +104,8 @@ runner = CliRunner() result = runner.invoke(list, ["npm"]) assert result.exit_code == 0 - expected_help_msg = """Loader: Load npm origin's artifact releases into swh archive. + expected_help_msg = """ +Loader: Load npm origin's artifact releases into swh archive. signature: (url: str) -""" # noqa - assert result.output.startswith(expected_help_msg) +""" + assert result.output.startswith(expected_help_msg[1:])