Skip to content

cli: add flag metadata to --help-autocomplete output - #544

Open
JakeSCahill wants to merge 1 commit into
mainfrom
jake/plugin-autocomplete-flags
Open

JakeSCahill wants to merge 1 commit into
mainfrom
jake/plugin-autocomplete-flags

Conversation

@JakeSCahill

Copy link
Copy Markdown
Contributor

Each --help-autocomplete entry now carries a flags array: the command's own flags, in the shape rpk --print-tree uses for rpk's flags. With https://github.com/redpanda-data/streaming-enterprise/pull/1134, rpk includes them in --print-tree, so the docs no longer parse rpk connect ... --help text. Tracking: https://redpandadata.atlassian.net/browse/DOC-2689.

How urfave/cli v2 flags map:

  • type: urfave flag types map to pflag type names (StringFlag to string, StringSliceFlag to stringSlice, and so on). Unknown types become string.
  • shorthand: the first single-character alias.
  • description and required: DocGenerationFlag.GetUsage() and RequiredFlag.IsRequired().
  • default: typed the way rpk types pflag defaults. String flags use the flag's value directly, because GetDefaultText() wraps strings in quotes.
  • skipped: hidden flags, help and help-autocomplete.
  • deprecated: left empty, because urfave has no equivalent.

path, short, long and args don't change. args still lists hidden flags, which is out of scope here. There's no example, because no command sets UsageText.

Tested:

  • New help_autocomplete_test.go covers bool, string, slice (empty and set), duration, int and required flags, an alias becoming shorthand, hidden flags and commands skipped, and [] for a command with no flags. With flags emptied, the test fails.
  • go test ./internal/cli/ passes.
  • Live check: flags for the root, lint and blobl server match their --help.
  • End to end with https://github.com/redpanda-data/streaming-enterprise/pull/1134: this build installed as rpk's managed connect plugin puts blobl server's --host and --port (shorthand p) into rpk --print-tree.

Connect picks this up after a benthos release and a dependency bump in redpanda-data/connect.

Each entry now carries a flags array with the command's own visible flags, in the shape rpk prints for its own flags in --print-tree. Older rpk versions ignore the field.
@claude

claude Bot commented Oct 27, 2026

Copy link
Copy Markdown

Commits
LGTM

Review
Adds a flags array (name, shorthand, type, description, default, required) to each --help-autocomplete entry, matching the shape rpk prints for its own flags in --print-tree. Hidden flags, help and help-autocomplete are filtered out. args is unchanged. Table-style unit tests cover type and default mapping, and check that flags is always serialised as an array.

LGTM

@JakeSCahill
JakeSCahill marked this pull request as ready for review October 27, 2026 09:43
@JakeSCahill
JakeSCahill requested a review from Jeffail October 27, 2026 09:44
@claude

claude Bot commented Oct 27, 2026

Copy link
Copy Markdown

Commits
LGTM

Review
Adds a flags array to each --help-autocomplete entry, in the shape rpk uses for --print-tree. Each entry lists the command's visible flags with their pflag type names and defaults parsed to typed values. Hidden flags and help flags are left out. flags is always a JSON array, and unit tests cover type and default mapping, shorthand selection, required flags, hidden flags, and the empty case.

LGTM

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.

1 participant