diff --git a/CHANGES/1267.bugfix b/CHANGES/1267.bugfix new file mode 100644 index 00000000..77cf22c2 --- /dev/null +++ b/CHANGES/1267.bugfix @@ -0,0 +1 @@ +Fixed `pulp --help` not showing all available commands. diff --git a/src/pulp_cli/__init__.py b/src/pulp_cli/__init__.py index 46f90cfd..58852b6c 100644 --- a/src/pulp_cli/__init__.py +++ b/src/pulp_cli/__init__.py @@ -144,6 +144,27 @@ def _version_callback(ctx: click.Context, param: t.Any, value: bool) -> None: ctx.exit(0) +def _help_callback(ctx: click.Context, param: click.Parameter, value: bool) -> None: + if value and not ctx.resilient_parsing: + # Ensure _load_config runs even if --config/--profile callbacks + # haven't fired yet (they are eager but may be sorted after + # --help when not explicitly provided on the command line). + ctx.meta.setdefault(CONFIG_KEY, None) + ctx.meta.setdefault(PROFILE_KEY, None) + if PLUGIN_KEY not in ctx.meta: + _load_config(ctx) + click.echo(ctx.get_help(), color=ctx.color) + ctx.exit() + + +@click.option( + "--help", + is_flag=True, + expose_value=False, + is_eager=True, + callback=_help_callback, + help=_("Show this message and exit."), +) @click.option( "--profile", "-p", diff --git a/tests/test_help_pages.py b/tests/test_help_pages.py index 5be2a247..9ddc10c7 100644 --- a/tests/test_help_pages.py +++ b/tests/test_help_pages.py @@ -68,6 +68,14 @@ def test_accessing_the_help_page_does_not_invoke_api( assert result.stdout.startswith("Usage:") or result.stdout.startswith("DeprecationWarning:") +def test_help_shows_all_available_commands(no_api: None) -> None: + runner = CliRunner() + result = runner.invoke(main, ["--help"], catch_exceptions=False) + assert result.exit_code == 0 + for command in main.commands.keys(): + assert command in result.stdout + + @pytest.mark.parametrize( "command,options", [