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
+5
View File
@@ -38,6 +38,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"
)
//go:embed cshd-scripts/velero.cshd
@@ -171,6 +172,10 @@ specs of resources created by velero server, and optionally the logs of backup a
},
}
o.bindFlags(c.Flags())
_ = c.RegisterFlagCompletionFunc("backup", cli.CompleteBackupNames(f))
_ = c.RegisterFlagCompletionFunc("restore", cli.CompleteRestoreNames(f))
return c
}