From 6d4faef79c468ec99c847d883e9ff8c603dfd5ac Mon Sep 17 00:00:00 2001 From: phm07 <22707808+phm07@users.noreply.github.com> Date: Thu, 30 Jan 2025 11:02:20 +0100 Subject: [PATCH] make base.LabelCmds generic --- internal/cmd/base/labels.go | 18 +++++++++--------- internal/cmd/certificate/labels.go | 13 +++++-------- internal/cmd/firewall/labels.go | 13 +++++-------- internal/cmd/floatingip/labels.go | 13 +++++-------- internal/cmd/image/labels.go | 13 +++++-------- internal/cmd/loadbalancer/labels.go | 13 +++++-------- internal/cmd/network/labels.go | 13 +++++-------- internal/cmd/placementgroup/labels.go | 13 +++++-------- internal/cmd/primaryip/labels.go | 13 +++++-------- internal/cmd/server/labels.go | 13 +++++-------- internal/cmd/sshkey/labels.go | 13 +++++-------- internal/cmd/volume/labels.go | 13 +++++-------- 12 files changed, 64 insertions(+), 97 deletions(-) diff --git a/internal/cmd/base/labels.go b/internal/cmd/base/labels.go index 3b487690..78094e54 100644 --- a/internal/cmd/base/labels.go +++ b/internal/cmd/base/labels.go @@ -14,20 +14,20 @@ import ( ) // LabelCmds allows defining commands for adding labels to resources. -type LabelCmds struct { +type LabelCmds[T any] struct { ResourceNameSingular string ShortDescriptionAdd string ShortDescriptionRemove string NameSuggestions func(client hcapi2.Client) func() []string LabelKeySuggestions func(client hcapi2.Client) func(idOrName string) []string - Fetch func(s state.State, idOrName string) (any, error) - SetLabels func(s state.State, resource any, labels map[string]string) error - GetLabels func(resource any) map[string]string - GetIDOrName func(resource any) string + Fetch func(s state.State, idOrName string) (T, error) + SetLabels func(s state.State, resource T, labels map[string]string) error + GetLabels func(resource T) map[string]string + GetIDOrName func(resource T) string } // AddCobraCommand creates a command that can be registered with cobra. -func (lc *LabelCmds) AddCobraCommand(s state.State) *cobra.Command { +func (lc *LabelCmds[T]) AddCobraCommand(s state.State) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("add-label [--overwrite] <%s>