Skip to content

Commit 75debbd

Browse files
committed
Fix pulp --help not showing available commands
fixes: #1267 Assisted by: claude-sonnet4
1 parent 41d886a commit 75debbd

3 files changed

Lines changed: 30 additions & 0 deletions

File tree

CHANGES/1267.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed `pulp --help` not showing all available commands.

src/pulp_cli/__init__.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,27 @@ def _version_callback(ctx: click.Context, param: t.Any, value: bool) -> None:
144144
ctx.exit(0)
145145

146146

147+
def _help_callback(ctx: click.Context, param: click.Parameter, value: bool) -> None:
148+
if value and not ctx.resilient_parsing:
149+
# Ensure _load_config runs even if --config/--profile callbacks
150+
# haven't fired yet (they are eager but may be sorted after
151+
# --help when not explicitly provided on the command line).
152+
ctx.meta.setdefault(CONFIG_KEY, None)
153+
ctx.meta.setdefault(PROFILE_KEY, None)
154+
if PLUGIN_KEY not in ctx.meta:
155+
_load_config(ctx)
156+
click.echo(ctx.get_help(), color=ctx.color)
157+
ctx.exit()
158+
159+
160+
@click.option(
161+
"--help",
162+
is_flag=True,
163+
expose_value=False,
164+
is_eager=True,
165+
callback=_help_callback,
166+
help=_("Show this message and exit."),
167+
)
147168
@click.option(
148169
"--profile",
149170
"-p",

tests/test_help_pages.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,14 @@ def test_accessing_the_help_page_does_not_invoke_api(
6868
assert result.stdout.startswith("Usage:") or result.stdout.startswith("DeprecationWarning:")
6969

7070

71+
def test_help_shows_all_available_commands(no_api: None) -> None:
72+
runner = CliRunner()
73+
result = runner.invoke(main, ["--help"], catch_exceptions=False)
74+
assert result.exit_code == 0
75+
for command in main.commands.keys():
76+
assert command in result.stdout
77+
78+
7179
@pytest.mark.parametrize(
7280
"command,options",
7381
[

0 commit comments

Comments
 (0)