Skip to content

fix: prevent subcommands from showing root-level commands in help output#730

Merged
ffantl-ld merged 1 commit into
mainfrom
devin/1782843619-fix-subcommand-help
Jun 30, 2026
Merged

fix: prevent subcommands from showing root-level commands in help output#730
ffantl-ld merged 1 commit into
mainfrom
devin/1782843619-fix-subcommand-help

Conversation

@ffantl-ld

@ffantl-ld ffantl-ld commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Requirements

  • I have added test coverage for new or changed functionality
  • I have followed the repository's pull request submission guidelines
  • I have validated my changes against all supported platform versions

Related issues

Subcommands (config, login, signup, setup) display root-level commands in their --help output instead of their own subcommands/flags.

Describe the solution you've provided

The root usage template in getUsageTemplate() was hardcoded with all root-level commands and unconditionally inherited by child commands that didn't set their own SetUsageTemplate().

The fix adds a {{if not .HasParent}} conditional so the hardcoded root commands list only renders for the root command. Child commands now get a dynamic template that:

  • Shows actual subcommands via {{range .Commands}} (if any exist)
  • Shows local flags and inherited global flags correctly
  • Shows the Use "... [command] --help" footer only when subcommands exist

Before:

$ ldcli config --help
...
Commands:
  setup          Create your first feature flag...
  config         View and modify specific configuration values
  login          Log in to your LaunchDarkly account
  ...            (all root commands incorrectly shown)

After:

$ ldcli config --help
...
Usage:
  ldcli config [flags]

Flags:
  -h, --help           help for config
      --list           List configs
      --set            Set a config field to a value
      --unset string   Unset a config field

Global flags:
      --access-token string   LaunchDarkly access token...

Describe alternatives you've considered

Setting SubcommandUsageTemplate() explicitly on each affected command (config, login, signup, setup). This would work but is fragile — any new command added without its own template would have the same bug. The conditional approach in the root template is more robust.

Additional context

The pre-existing TestWhoAmI/without_configured_token_returns_helpful_error test failure (nil pointer dereference in whoami.go:93) is unrelated to this change — it reproduces on main.

Link to Devin session: https://app.devin.ai/sessions/f4752d6ac05c455ba24e7bfe270effb9
Requested by: @ffantl-ld


Note

Low Risk
Help text formatting only; no runtime behavior, auth, or API changes.

Overview
Subcommand --help no longer lists the root CLI’s hardcoded commands (setup, config, login, etc.) when you run help on children like ldcli config.

getUsageTemplate() now renders the curated root command list only when {{if not .HasParent}}. Child commands use a separate branch that shows Available Commands from Cobra’s .Commands, local flags, global inherited flags, and the standard “use … --help” hint only when subcommands exist.

Reviewed by Cursor Bugbot for commit f7c6d22. Bugbot is set up for automated code reviews on this repo. Configure here.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@ffantl-ld ffantl-ld self-assigned this Jun 30, 2026
@devin-ai-integration

Copy link
Copy Markdown
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

@ffantl-ld ffantl-ld requested review from LindseyB, cspath1 and nieblara and removed request for LindseyB, cspath1 and nieblara June 30, 2026 20:17
@ffantl-ld ffantl-ld merged commit ca49101 into main Jun 30, 2026
9 checks passed
@ffantl-ld ffantl-ld deleted the devin/1782843619-fix-subcommand-help branch June 30, 2026 22:00
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.

2 participants