Skip to content

Commit 800c243

Browse files
committed
Update help command output
1 parent abb35c3 commit 800c243

File tree

1 file changed

+32
-3
lines changed

1 file changed

+32
-3
lines changed

localstack-core/localstack/cli/localstack.py

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,35 @@ def invoke(self, ctx: click.Context):
7474
# If we have a generic exception, we wrap it in a ClickException
7575
raise CLIError(str(e)) from e
7676

77+
def format_help(self, ctx: click.Context, formatter: click.HelpFormatter) -> None:
78+
"""Custom help formatter that makes all section headers bold and uppercase."""
79+
from localstack.constants import VERSION # Import at the top of the file if not already there
80+
81+
formatter.write_text(f"LocalStack CLI v{VERSION}") # Add version at the top
82+
self.format_help_text(ctx, formatter)
83+
formatter.write_text("") # Add blank line after help text
84+
self.format_usage(ctx, formatter)
85+
self.format_options(ctx, formatter)
86+
self.format_commands(ctx, formatter)
87+
88+
def format_usage(self, ctx: click.Context, formatter: click.HelpFormatter) -> None:
89+
"""Override usage formatting to make the header bold and uppercase."""
90+
formatter.write_text("\033[1mUSAGE\033[0m") # Write the header separately
91+
formatter.write_text("localstack [OPTIONS] COMMAND [ARGS]...")
92+
93+
def format_options(self, ctx: click.Context, formatter: click.HelpFormatter) -> None:
94+
"""Override options formatting to make the header bold and uppercase."""
95+
opts = []
96+
for param in ctx.command.get_params(ctx):
97+
rv = param.get_help_record(ctx)
98+
if rv is not None:
99+
opts.append(rv)
100+
101+
if opts:
102+
formatter.write_text("")
103+
formatter.write_text("\033[1mOPTIONS\033[0m")
104+
formatter.write_dl(opts)
105+
77106
def format_commands(self, ctx: click.Context, formatter: click.HelpFormatter) -> None:
78107
"""Extra format methods for multi methods that adds all the commands after the options. It also
79108
groups commands into command categories."""
@@ -100,8 +129,9 @@ def format_commands(self, ctx: click.Context, formatter: click.HelpFormatter) ->
100129

101130
for category, rows in categories.items():
102131
if rows:
103-
with formatter.section(category):
104-
formatter.write_dl(rows)
132+
formatter.write_text("")
133+
formatter.write_text(f"\033[1m{category.upper()}\033[0m")
134+
formatter.write_dl(rows)
105135

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

113143
return "Commands"
114144

115-
116145
def create_with_plugins() -> LocalstackCli:
117146
"""
118147
Creates a LocalstackCli instance with all cli plugins loaded.

0 commit comments

Comments
 (0)