|
10 | 10 | from pulp_glue.common.i18n import get_translation |
11 | 11 |
|
12 | 12 | from pulp_cli.config import CONFIG_LOCATIONS, config, config_options, validate_config |
13 | | -from pulp_cli.generic import PulpCLIContext, pulp_group |
| 13 | +from pulp_cli.generic import PulpCLIContext, PulpGroup |
14 | 14 |
|
15 | 15 | if sys.version_info >= (3, 11): |
16 | 16 | import tomllib |
@@ -60,6 +60,23 @@ def load_plugins( |
60 | 60 | PROFILE_KEY = f"{__name__}.profile" |
61 | 61 |
|
62 | 62 |
|
| 63 | +class MainPulpGroup(PulpGroup): |
| 64 | + """PulpGroup subclass for the main CLI entry point. |
| 65 | +
|
| 66 | + Ensures plugins are loaded before help is displayed. This is needed because |
| 67 | + Click's ``iter_params_for_processing`` sorts eager parameters by invocation |
| 68 | + order, so ``--help`` (which is on the command line) gets processed before |
| 69 | + ``--config`` and ``--profile`` (which are not). This causes ``--help`` to |
| 70 | + exit before the plugin-loading callbacks ever fire, resulting in a help page |
| 71 | + that only shows directly-registered commands. |
| 72 | + """ |
| 73 | + |
| 74 | + def format_help(self, ctx: click.Context, formatter: click.HelpFormatter) -> None: |
| 75 | + if PLUGIN_KEY not in ctx.meta: |
| 76 | + ctx.meta[PLUGIN_KEY] = load_plugins() |
| 77 | + super().format_help(ctx, formatter) |
| 78 | + |
| 79 | + |
63 | 80 | # config and config-profile need to be combined in order to fetch the desired defaults. |
64 | 81 | # Click will call both these callbacks exactly once, but we cannot know the order. |
65 | 82 | # Therefore whichever one has seen the that the other deposited it's value will coninue with |
@@ -183,7 +200,7 @@ def _version_callback(ctx: click.Context, param: t.Any, value: bool) -> None: |
183 | 200 | ), |
184 | 201 | ) |
185 | 202 | @config_options |
186 | | -@pulp_group(no_args_is_help=False) |
| 203 | +@click.group(cls=MainPulpGroup, no_args_is_help=False) |
187 | 204 | @click.pass_context |
188 | 205 | def main( |
189 | 206 | ctx: click.Context, |
|
0 commit comments