Skip to content

Improve help command layout#52

Merged
gtsiolis merged 4 commits intomainfrom
george/des-145
Feb 27, 2026
Merged

Improve help command layout#52
gtsiolis merged 4 commits intomainfrom
george/des-145

Conversation

@gtsiolis
Copy link
Member

@gtsiolis gtsiolis commented Feb 25, 2026

This will improves help command output readability and design.

What changed?

  1. Updated root help usage to a single line (Usage: lstk [options] [command])
  2. Added a concise descriptor line under usage (LSTK - LocalStack command-line interace)
  3. Renamed section headers in help output (Commands, Options)
  4. Updated root flag descriptions (Show help, Show version)
  5. Removed default Cobra footer
  6. Updated version command short text
BEFORE AFTER
Frame 514780677 Frame 514780677-1

@coderabbitai
Copy link

coderabbitai bot commented Feb 25, 2026

Warning

Rate limit exceeded

@gtsiolis has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 16 minutes and 56 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between d1f2fdd and 55b2658.

📒 Files selected for processing (1)
  • cmd/help_test.go
📝 Walkthrough

Walkthrough

Adds custom Cobra help templates and configures default help/version flags; updates short/long help texts across multiple CLI commands; adds tests for help output.

Changes

Cohort / File(s) Summary
Help & root init
cmd/help.go, cmd/root.go
Adds custom usage/help templates and configureHelp(cmd *cobra.Command); enables default --help and --version flags and sets their usage text; wires configureHelp into root init.
Help tests
cmd/help_test.go
Adds tests capturing CLI help output: verifies root and subcommand help formatting and presence/absence of specific sections.
Version command
cmd/version.go
Updates version command short description from "Print the lstk version" to "Show version".
Config command
cmd/config.go
Short description changed from "Manage lstk configuration" to "Manage configuration".
Auth commands
cmd/login.go, cmd/logout.go
Login short/long changed to "Manage login..." and logout short changed to "Remove stored authentication credentials" (help text only).
Logs command
cmd/logs.go
Short/long updated to reference "emulator" and adjust wording for --follow usage (help text only).
Lifecycle commands
cmd/start.go, cmd/stop.go
Short/long descriptions changed from "Start/Stop LocalStack" to "Start/Stop emulator" and adjusted long descriptions (help text only).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • carole-lavillonniere
🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Improve help command layout' directly summarizes the main change: improving the help command output's readability and design through layout and text updates.
Description check ✅ Passed The description is well-related to the changeset, providing a detailed explanation of what changed with specific examples and a before/after visual comparison.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch george/des-145

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
cmd/root.go (1)

49-64: Template customization via string replacement is fragile against Cobra upgrades

strings.Replace on UsageTemplate() silently no-ops if Cobra ever changes its default template wording (e.g., changes "Available Commands:" or reorders sections). There's no error or warning if a replacement finds nothing, so a future Cobra bump could silently revert the help output to the un-customized form.

A note on line 51: "Flags:" is replaced with count 1, which works correctly today because Cobra places the local flags section (Flags:) before the inherited section (Global Flags:) in its template — so the first substring hit is the intended one. This ordering is a Cobra implementation detail, not a contract.

Consider defining the usage template as a complete string literal rather than patching the default, which makes the intent explicit and immune to upstream template changes.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cmd/root.go` around lines 49 - 64, The current approach mutates Cobra's
default UsageTemplate via multiple strings.Replace calls (usageTemplate variable
and the block that patches Usage: / Available Commands: / Flags:), which is
fragile; replace this patching by defining a complete, explicit usage template
string and pass it to rootCmd.SetUsageTemplate instead of performing
replacements on rootCmd.UsageTemplate(), keeping the same customized sections
(Commands:, Options:, the special lstk Usage header and the removed "Use ...
--help" line) so the behavior no longer depends on Cobra's upstream template
wording or ordering.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@cmd/root.go`:
- Line 59: Update the user-facing help string that contains the typo "interace"
to "interface" — locate the string literal containing "LSTK - LocalStack
command-line interace{{end}}`" in cmd/root.go (e.g., the root command's
description/long help) and correct the spelling to "LSTK - LocalStack
command-line interface{{end}}`" so the CLI help displays the proper word.

---

Nitpick comments:
In `@cmd/root.go`:
- Around line 49-64: The current approach mutates Cobra's default UsageTemplate
via multiple strings.Replace calls (usageTemplate variable and the block that
patches Usage: / Available Commands: / Flags:), which is fragile; replace this
patching by defining a complete, explicit usage template string and pass it to
rootCmd.SetUsageTemplate instead of performing replacements on
rootCmd.UsageTemplate(), keeping the same customized sections (Commands:,
Options:, the special lstk Usage header and the removed "Use ... --help" line)
so the behavior no longer depends on Cobra's upstream template wording or
ordering.

ℹ️ Review info

Configuration used: Repository UI (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3200ba4 and 597f760.

📒 Files selected for processing (2)
  • cmd/root.go
  • cmd/version.go

@gtsiolis gtsiolis self-assigned this Feb 25, 2026
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
cmd/root.go (1)

49-64: String-replacement on Cobra's internal default template is fragile.

The five chained strings.Replace/ReplaceAll/TrimRight calls mutate the text of Cobra's built-in UsageTemplate(). Any change to that template in a future Cobra release (including patch versions) would cause one or more replacements to silently no-op, producing a malformed or partially-branded help output with no compile-time or runtime error.

Consider defining the full usage template as a single, self-contained string literal instead of patching the default one. This removes the coupling to Cobra internals entirely and makes the intended layout explicit and auditable.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cmd/root.go` around lines 49 - 64, The current approach mutates Cobra's
default UsageTemplate by applying multiple strings.Replace/ReplaceAll/TrimRight
calls on usageTemplate returned from rootCmd.UsageTemplate(), which is fragile;
instead replace this whole mutation sequence by constructing a single explicit
usage template string literal (containing the desired "Usage",
"Commands"/"Options" labels and the LSTK branding/conditional logic) and call
rootCmd.SetUsageTemplate(...) with that literal; update or remove references to
the intermediate usageTemplate variable and ensure the new template uses the
same template variables (e.g., .UseLine, .CommandPath, .HasAvailableSubCommands)
so behavior of rootCmd remains identical.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@cmd/root.go`:
- Around line 52-61: The usage/help templates currently check for a hardcoded
binary name via `{{if eq .CommandPath "lstk"}}` which breaks when the binary is
renamed; update the template logic in the `usageTemplate` and the help template
to use Cobra's root detection by replacing those instances with `{{if not
.HasParent}}` so the branded header renders for the root command regardless of
the executable name (update occurrences in the `usageTemplate` and the help
template where `CommandPath` is compared to "lstk").

---

Nitpick comments:
In `@cmd/root.go`:
- Around line 49-64: The current approach mutates Cobra's default UsageTemplate
by applying multiple strings.Replace/ReplaceAll/TrimRight calls on usageTemplate
returned from rootCmd.UsageTemplate(), which is fragile; instead replace this
whole mutation sequence by constructing a single explicit usage template string
literal (containing the desired "Usage", "Commands"/"Options" labels and the
LSTK branding/conditional logic) and call rootCmd.SetUsageTemplate(...) with
that literal; update or remove references to the intermediate usageTemplate
variable and ensure the new template uses the same template variables (e.g.,
.UseLine, .CommandPath, .HasAvailableSubCommands) so behavior of rootCmd remains
identical.

ℹ️ Review info

Configuration used: Repository UI (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 597f760 and ffb8144.

📒 Files selected for processing (2)
  • cmd/root.go
  • cmd/version.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • cmd/version.go

@gtsiolis gtsiolis force-pushed the george/des-145 branch 2 times, most recently from f7221fe to 4c01111 Compare February 25, 2026 21:33
cmd/root.go Outdated

LSTK - LocalStack command-line interface{{end}}`,
1,
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: it's a bit fragile to replace certain strings in the help template (if we upgrade cobra, it could change and break). However I see why it makes sense: if we were instead writing the template from scratch, new commands would not be automatically added and we could forget to add them.
So I would suggest to add a unit test to make sure the help output is what we expect.
Also I would move the code to cmd/help.go

Copy link
Member

@silv-io silv-io Feb 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, there is a range over the commands in the original template which we also could just do.

I think writing our own template might actually be a better solution in this case

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The templating is using the built-in https://pkg.go.dev/text/template, so we're quite free in what we can do there.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, both! Whoa I didn't even notice that template in the file.

Moved in d1f2fdd. Let me know if this looks better now. 🏓 🏓

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
cmd/help_test.go (1)

31-57: Consider adding one integration-level help-output test.

These unit checks are good, but one CLI integration test for lstk --help would reduce regressions in the real binary output path.

As per coding guidelines "**/*_test.go: Prefer integration tests to cover most cases. Use unit tests when integration tests are not practical."

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cmd/help_test.go` around lines 31 - 57, Add an integration test that runs the
real CLI binary for the root help output rather than the unit helper used by
TestRootHelpOutputTemplate; create a new test (e.g., TestRootHelpIntegration)
that uses os/exec to run the compiled `lstk --help` (or runs the built test
binary's main via exec) and assert the same key strings ("Usage:", "lstk
[options] [command]", "LSTK - LocalStack command-line interface", "Commands:",
"Options:") are present and that deprecated templates are not present, mirroring
the assertions in
TestRootHelpOutputTemplate/TestSubcommandHelpUsesSubcommandUsageLine so
regressions in the real binary output path are caught.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@cmd/help_test.go`:
- Around line 10-29: executeWithArgs currently mutates the global rootCmd
causing flag/parse state to leak between tests; change it to create and use a
fresh command instance per call (e.g., call the constructor/factory that builds
the CLI such as NewRootCmd()/newRootCmd() or a Clone of rootCmd), set
args/out/err on that new instance, call ExecuteContext on it, and return its
output/error so the global rootCmd is no longer mutated by SetArgs/SetOut/SetErr
(if no constructor exists, instead fully reset all flag state on rootCmd before
executing by clearing args and resetting all flags via PersistentFlags()/Flags()
traversal).

---

Nitpick comments:
In `@cmd/help_test.go`:
- Around line 31-57: Add an integration test that runs the real CLI binary for
the root help output rather than the unit helper used by
TestRootHelpOutputTemplate; create a new test (e.g., TestRootHelpIntegration)
that uses os/exec to run the compiled `lstk --help` (or runs the built test
binary's main via exec) and assert the same key strings ("Usage:", "lstk
[options] [command]", "LSTK - LocalStack command-line interface", "Commands:",
"Options:") are present and that deprecated templates are not present, mirroring
the assertions in
TestRootHelpOutputTemplate/TestSubcommandHelpUsesSubcommandUsageLine so
regressions in the real binary output path are caught.

ℹ️ Review info

Configuration used: Repository UI (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 60254b2 and d1f2fdd.

📒 Files selected for processing (3)
  • cmd/help.go
  • cmd/help_test.go
  • cmd/root.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • cmd/root.go

Comment on lines -14 to +15
Short: "Show container logs",
Long: "Show logs from the LocalStack container. Use --follow to stream in real-time.",
Short: "Show emulator logs",
Long: "Show logs from the emulator. Use --follow to stream in real-time.",
Copy link
Member Author

@gtsiolis gtsiolis Feb 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated also the terminology from #51.

lstk/cmd/logs.go

Lines 14 to 15 in a90fc63

Short: "Show container logs",
Long: "Show logs from the LocalStack container. Use --follow to stream in real-time.",

Cc @anisaoshafi @silv-io @carole-lavillonniere for visibility and because of relevant discussion.

flag.Changed = false
})
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thought: it's a little strange we have to do that. ATM rootCmd is a package-level singleton and I wonder if we could construct a fresh one for each test. Anyways that would be a refactoring outside the scope of this PR.
cc @silv-io

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @carole-lavillonniere! Merging this one. Opened PRO-226 to keep track of this comment.

@gtsiolis gtsiolis merged commit 1a8e165 into main Feb 27, 2026
8 checks passed
@gtsiolis gtsiolis deleted the george/des-145 branch February 27, 2026 09:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants