Skip to content

Update CLI help command output UX #12015

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
35 changes: 32 additions & 3 deletions localstack-core/localstack/cli/localstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,35 @@ def invoke(self, ctx: click.Context):
# If we have a generic exception, we wrap it in a ClickException
raise CLIError(str(e)) from e

def format_help(self, ctx: click.Context, formatter: click.HelpFormatter) -> None:
"""Custom help formatter that makes all section headers bold and uppercase."""
from localstack.constants import VERSION

formatter.write_text(f"LocalStack CLI v{VERSION}")
self.format_help_text(ctx, formatter)
formatter.write_text("")
self.format_usage(ctx, formatter)
self.format_options(ctx, formatter)
self.format_commands(ctx, formatter)

def format_usage(self, ctx: click.Context, formatter: click.HelpFormatter) -> None:
"""Override usage formatting to make the header bold and uppercase."""
formatter.write_text("\033[1mUSAGE\033[0m")
formatter.write_text("localstack [OPTIONS] COMMAND [ARGS]...")

def format_options(self, ctx: click.Context, formatter: click.HelpFormatter) -> None:
"""Override options formatting to make the header bold and uppercase."""
opts = []
for param in ctx.command.get_params(ctx):
rv = param.get_help_record(ctx)
if rv is not None:
opts.append(rv)

if opts:
formatter.write_text("")
formatter.write_text("\033[1mOPTIONS\033[0m")
formatter.write_dl(opts)

def format_commands(self, ctx: click.Context, formatter: click.HelpFormatter) -> None:
"""Extra format methods for multi methods that adds all the commands after the options. It also
groups commands into command categories."""
Expand All @@ -100,8 +129,9 @@ def format_commands(self, ctx: click.Context, formatter: click.HelpFormatter) ->

for category, rows in categories.items():
if rows:
with formatter.section(category):
formatter.write_dl(rows)
formatter.write_text("")
formatter.write_text(f"\033[1m{category.upper()}\033[0m")
formatter.write_dl(rows)

def _get_category(self, cmd) -> str:
if cmd.deprecated:
Expand All @@ -112,7 +142,6 @@ def _get_category(self, cmd) -> str:

return "Commands"


def create_with_plugins() -> LocalstackCli:
"""
Creates a LocalstackCli instance with all cli plugins loaded.
Expand Down
Loading