Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions httpie/cli/argparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
26 changes: 25 additions & 1 deletion httpie/output/ui/rich_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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(
Expand Down
6 changes: 6 additions & 0 deletions tests/test_cli_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
Loading