Skip to content

rpk-k8s: report command flags in --help-autocomplete - #2021

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 from rpk-k8s now carries a flags array: the command's own flags (cmd.LocalFlags(), hidden flags and help skipped), in the shape rpk --print-tree uses for rpk's flags. With https://github.com/redpanda-data/streaming-enterprise/pull/1134, rpk includes these in --print-tree, so the docs no longer parse rpk k8s ... --help text. Tracking: https://redpandadata.atlassian.net/browse/DOC-2689.

Also fixes args. It was cmd.ValidArgs, which no rpk-k8s command sets, so rpk got no flag completion for rpk k8s. It now lists the command's flag names (local, then inherited), as rpai does.

The walk also skips cobra's help and completion commands by name. Today they can't appear, because cobra adds them inside Execute.

Tested:

  • New TestCollectHelpsFlags covers typed defaults (bool, int, duration, stringSlice, string), shorthand, required and deprecated, hidden flags and commands, a persistent flag listed only on its root, [] for a command with no flags, and the args fix.
  • GOLANG_PROTOBUF_REGISTRATION_CONFLICT=ignore go test ./cmd/rpk-k8s/ passes. With main's main.go the test fails.
  • Live check: multicluster status (5 flags) and multicluster bundle (14 flags) match their --help.
  • Includes a changie entry. I didn't run task lint. gofmt is clean.

rpk builds the reference docs for plugin commands from the
--help-autocomplete output, which carried no flag metadata. Each entry
now has a flags array in the shape rpk prints for its own flags in
--print-tree: local, non-hidden flags with typed defaults.

args now lists the command's flag names ("--name") for completion, as
rpk expects. It used to carry ValidArgs, which no rpk-k8s command sets,
so it was always null. Cobra's help and completion commands are skipped
if they are ever present in the walk.
@secpanda

secpanda commented Oct 27, 2026 •

Copy link
Copy Markdown

✅ Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
✅ Open Source Security 0 0 0 0 0 issues
✅ Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@JakeSCahill
JakeSCahill marked this pull request as ready for review October 27, 2026 09:43
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