Skip to content

✨ feat(CLI): Add completion for the plugins flag#5596

Open
vitorfloriano wants to merge 1 commit intokubernetes-sigs:masterfrom
vitorfloriano:dynamic-completion-for-plugins-flag
Open

✨ feat(CLI): Add completion for the plugins flag#5596
vitorfloriano wants to merge 1 commit intokubernetes-sigs:masterfrom
vitorfloriano:dynamic-completion-for-plugins-flag

Conversation

@vitorfloriano
Copy link
Copy Markdown
Contributor

@vitorfloriano vitorfloriano commented Apr 9, 2026

This PR adds dynamic flag completion for the --plugins flag.

The --plugins flag now shows completion for all the available plugins (external ones too, including out-of-tree! 🎉), while hiding deprecated ones.

$ kubebuilder init --plugins 
autoupdate.kubebuilder.io/v1-alpha       (Proposes Kubebuilder scaffold updates via GitHub Actions)
base.go.kubebuilder.io/v4                (Default scaffold (go/v4 + kustomize/v2))
deploy-image.go.kubebuilder.io/v1-alpha  (Scaffolds a CRD+controller to deploy an image-based Operand)
foo.acme.io/v2                           (External or custom plugin)
go.kubebuilder.io/v4                     (Default scaffold (go/v4 + kustomize/v2))
grafana.kubebuilder.io/v1-alpha          (Generates Grafana Dashboards for metrics)
helm.kubebuilder.io/v2-alpha             (Generates a Helm chart for project distribution)
kustomize.common.kubebuilder.io/v2       (Scaffolds base Kustomize configuration)

This will improve plugin discoverability and usage, especially for the autoupdate plugin.

Relates to #5446 and #5291

Note

Completion does not work for comma-chained values, so users will either use another instance of --plugins to get completion or type everything (or copy-paste) the keys after a comma:

Works (multiple instances of the flag):

$ kubebuilder init --plugins=foo.acme.io/v2 --plugins autoupdate.kubebuilder.io/v1-alpha --plugins base.go.kubebuilder.io/v4 --plugins helm.kubebuilder.io/v2-alpha --plugins 
deploy-image.go.kubebuilder.io/v1-alpha  (Scaffolds a CRD+controller to deploy an image-based Operand)
go.kubebuilder.io/v4                     (Default scaffold (go/v4 + kustomize/v2))
grafana.kubebuilder.io/v1-alpha          (Generates Grafana Dashboards for metrics)
kustomize.common.kubebuilder.io/v2       (Scaffolds base Kustomize configuration)

Does not work (trailing comma):

$ kubebuilder init --plugins foo.acme.io/v2,<TAB><TAB><TAB furiously>
(nothing happens)
$ kubebuilder init --plugins=foo.acme.io/v2,<TAB><TAB><TAB furiously>
(nothing happens)

This is a known limitation in Cobra. There are workarounds but they look a bit of a kludge.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Apr 9, 2026
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: vitorfloriano
Once this PR has been reviewed and has the lgtm label, please assign varshaprasad96 for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Apr 9, 2026
@vitorfloriano vitorfloriano changed the title feat(cli): add completion for the plugins flag ✨ feat(CLI): Add completion for the plugins flag Apr 9, 2026
@vitorfloriano vitorfloriano force-pushed the dynamic-completion-for-plugins-flag branch 2 times, most recently from 1943e1a to c6c1805 Compare April 9, 2026 15:38
The --plugins flag now shows completion for
shows all the available plugins (external ones too!).
@vitorfloriano vitorfloriano force-pushed the dynamic-completion-for-plugins-flag branch from c6c1805 to d9b9d71 Compare April 9, 2026 18:00
> [!TIP]
> To take advantage of tab completion, pass one plugin key at a time to multiple instances of the plugins flag:
> ```
> kubebuilder init --plugins pluginA --plugins pluginB --plugins pluginC
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The completion should work as it works the plugins
So, it should work well with --plugins=pluginA,pluginB,pluginB

Could we ensure that?
Also, do we really need this note here?
If yes, could we add the default style note instead [!TIP]?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants