Add dynamic resource autocompletion to Velero CLI

Register cobra completion callbacks for all commands that accept
existing Velero resource names. A centralized completeNames helper
uses apimachinery's meta.ExtractList/Accessor to list resources with
a 3-second timeout, filter by prefix, and deduplicate already-typed
arguments. Wires ValidArgsFunction on 20 commands and
RegisterFlagCompletionFunc on 9 flags across backup, restore,
schedule, backuplocation, snapshotlocation, repo, and debug.

Closes #9782

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Joseph <jvaikath@redhat.com>
This commit is contained in:
Joseph
2026-08-05 08:17:44 -07:00
co-authored by Claude Opus 4.6
parent f73888abbd
commit 3c49bbec75
28 changed files with 363 additions and 1 deletions
+1
View File
@@ -62,6 +62,7 @@ func NewDeleteCommand(f client.Factory, use string) *cobra.Command {
},
}
c.ValidArgsFunction = cli.CompleteBackupStorageLocationNames(f)
o.BindFlags(c.Flags())
return c
}
+2
View File
@@ -27,6 +27,7 @@ import (
velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
"github.com/vmware-tanzu/velero/pkg/client"
"github.com/vmware-tanzu/velero/pkg/cmd"
"github.com/vmware-tanzu/velero/pkg/cmd/cli"
"github.com/vmware-tanzu/velero/pkg/cmd/util/output"
)
@@ -89,6 +90,7 @@ func NewGetCommand(f client.Factory, use string) *cobra.Command {
},
}
c.ValidArgsFunction = cli.CompleteBackupStorageLocationNames(f)
c.Flags().BoolVar(&showDefaultOnly, "default", false, "Displays the current default backup storage location.")
c.Flags().StringVarP(&listOptions.LabelSelector, "selector", "l", listOptions.LabelSelector, "Only show items matching this label selector.")
+2
View File
@@ -33,6 +33,7 @@ import (
"github.com/vmware-tanzu/velero/pkg/builder"
"github.com/vmware-tanzu/velero/pkg/client"
"github.com/vmware-tanzu/velero/pkg/cmd"
"github.com/vmware-tanzu/velero/pkg/cmd/cli"
"github.com/vmware-tanzu/velero/pkg/cmd/util/flag"
"github.com/vmware-tanzu/velero/pkg/util/boolptr"
)
@@ -51,6 +52,7 @@ func NewSetCommand(f client.Factory, use string) *cobra.Command {
},
}
c.ValidArgsFunction = cli.CompleteBackupStorageLocationNames(f)
o.BindFlags(c.Flags())
return c