From ffab066cabe859bbb66677886530d0a94177a999 Mon Sep 17 00:00:00 2001 From: worldmozara Date: Wed, 15 Jul 2026 13:14:47 +0800 Subject: [PATCH] core/cli: drop Click --help from slash commands Slash commands use add_help_option=False and empty options_metavar so /help shows Usage: /history [N] without a fake Options/--help section. --- src/plyngent/cli/slash.py | 13 ++++++++++++- tests/test_cli/test_repl_commands.py | 17 +++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/plyngent/cli/slash.py b/src/plyngent/cli/slash.py index 4188eef..54aad4c 100644 --- a/src/plyngent/cli/slash.py +++ b/src/plyngent/cli/slash.py @@ -64,7 +64,17 @@ ON_OFF = OnOffParam() class SlashGroup(click.Group): - """Click group for REPL slash commands (no process-level ownership).""" + """Click group for REPL slash commands (no process-level ownership). + + Commands never expose Click's ``--help``; use ``/help`` / ``/help ``. + """ + + @override + def command(self, *args: Any, **kwargs: Any) -> Any: + # No auto --help; drop [OPTIONS] metavar when the command has no options. + kwargs.setdefault("add_help_option", False) + kwargs.setdefault("options_metavar", "") + return super().command(*args, **kwargs) @override def get_help(self, ctx: click.Context) -> str: @@ -83,6 +93,7 @@ class SlashGroup(click.Group): slash = SlashGroup( "slash", help="REPL slash commands", + add_help_option=False, context_settings={"help_option_names": [], "max_content_width": 100}, ) diff --git a/tests/test_cli/test_repl_commands.py b/tests/test_cli/test_repl_commands.py index e1fcabe..b4ae440 100644 --- a/tests/test_cli/test_repl_commands.py +++ b/tests/test_cli/test_repl_commands.py @@ -102,6 +102,23 @@ async def test_help_command_usage_line(state: ReplState, capsys: pytest.CaptureF assert "Usage: /compact" in out assert "help [COMMAND] compact" not in out assert "Soft-compact" in out + assert "--help" not in out + assert "Options:" not in out + + +async def test_help_history_no_fake_options(state: ReplState, capsys: pytest.CaptureFixture[str]) -> None: + assert await handle_slash(state, "/help history") is True + out = capsys.readouterr().out + assert "Usage: /history [N]" in out + assert "Options:" not in out + assert "--help" not in out + + +async def test_history_rejects_help_flag(state: ReplState, capsys: pytest.CaptureFixture[str]) -> None: + assert await handle_slash(state, "/history --help") is True + captured = capsys.readouterr() + combined = captured.out + captured.err + assert "No such option" in combined async def test_quit(state: ReplState) -> None: