From 4ae962847b94501a6771379a9dfbcda005d1397d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=B3=96=E9=9C=B2=E6=98=9F=E9=9C=9C=E2=80=A2=E6=9A=96?= =?UTF-8?q?=E9=9C=9E=E6=8B=BE=E5=85=89?= <2468001320@qq.com> Date: Fri, 11 Sep 2026 05:08:36 +0000 Subject: [PATCH] feat: show request items separators in naked invocation usage --- httpie/cli/argparser.py | 13 +++++++++++++ httpie/output/ui/rich_help.py | 26 +++++++++++++++++++++++++- tests/test_cli_ui.py | 6 ++++++ 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/httpie/cli/argparser.py b/httpie/cli/argparser.py index 9bf09b3b73..912a0e7046 100644 --- a/httpie/cli/argparser.py +++ b/httpie/cli/argparser.py @@ -595,6 +595,19 @@ def print_usage(self, file): usage_text.append(rich_help.to_usage(self.spec, whitelist=whitelist)) self.env.rich_error_console.print(usage_text) + from rich.console import Group + cheatsheet_heading = Text('request items', style='bold') + cheatsheet_heading.append( + " (common separators, run 'http --help' for all options):", + style='default', + ) + self.env.rich_error_console.print( + Group( + cheatsheet_heading, + rich_help.to_request_items_cheatsheet(), + ) + ) + def error(self, message): """Prints a usage message incorporating the message to stderr and exits.""" diff --git a/httpie/output/ui/rich_help.py b/httpie/output/ui/rich_help.py index 2b19f3e33a..e770fae3bc 100644 --- a/httpie/output/ui/rich_help.py +++ b/httpie/output/ui/rich_help.py @@ -8,7 +8,14 @@ from rich.table import Table from rich.text import Text -from httpie.cli.constants import SEPARATOR_GROUP_ALL_ITEMS +from httpie.cli.constants import ( + SEPARATOR_DATA_RAW_JSON, + SEPARATOR_DATA_STRING, + SEPARATOR_FILE_UPLOAD, + SEPARATOR_GROUP_ALL_ITEMS, + SEPARATOR_HEADER, + SEPARATOR_QUERY_PARAM, +) from httpie.cli.options import Argument, ParserSpec, Qualifiers from httpie.output.ui.palette import GenericColor @@ -123,6 +130,23 @@ def to_usage( return text +REQUEST_ITEMS_CHEATSHEET = [ + (SEPARATOR_QUERY_PARAM, 'Query params'), + (SEPARATOR_DATA_STRING, 'Data fields (string)'), + (SEPARATOR_DATA_RAW_JSON, 'Data fields (raw JSON)'), + (SEPARATOR_FILE_UPLOAD, 'File upload'), + (SEPARATOR_HEADER, 'HTTP headers'), +] + + +def to_request_items_cheatsheet() -> RenderableType: + text = Text() + for separator, description in REQUEST_ITEMS_CHEATSHEET: + text.append(f' {separator:<6}{description}\n', style=STYLE_METAVAR) + text.rstrip() + return text + + # This part is loosely based on the rich-click's help message # generation. def to_help_message( diff --git a/tests/test_cli_ui.py b/tests/test_cli_ui.py index bb744cdc4e..4dfb25bf18 100644 --- a/tests/test_cli_ui.py +++ b/tests/test_cli_ui.py @@ -6,6 +6,12 @@ NAKED_BASE_TEMPLATE = """\ usage: http {extra_args}[METHOD] URL [REQUEST_ITEM ...] +request items (common separators, run 'http --help' for all options): + == Query params + = Data fields (string) + := Data fields (raw JSON) + @ File upload + : HTTP headers error: {error_msg}