Signed-off-by: Bryan Frimin <bryan@getprobo.com>
This commit is contained in:
Bryan Frimin
2026-03-16 16:54:48 +01:00
parent 5864719a3f
commit 842bbfbe97
5 changed files with 13 additions and 22 deletions

View File

@@ -16,6 +16,7 @@ package cmdutil
import (
"fmt"
"slices"
"strings"
"github.com/spf13/cobra"
@@ -61,10 +62,8 @@ func ValidateOutputFlag(value *string) error {
// ValidateEnum checks that value is one of the allowed values. It returns a
// user-friendly error mentioning the flag name and the valid choices.
func ValidateEnum(flag string, value string, allowed []string) error {
for _, v := range allowed {
if value == v {
return nil
}
if slices.Contains(allowed, value) {
return nil
}
return fmt.Errorf(
"invalid --%s value %q: valid values are %s",

View File

@@ -17,6 +17,7 @@ package create
import (
"encoding/json"
"fmt"
"slices"
"strings"
"github.com/spf13/cobra"
@@ -69,13 +70,7 @@ func NewCmdCreate(f *cmdutil.Factory) *cobra.Command {
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
for _, e := range flagEvents {
valid := false
for _, v := range shared.ValidEvents {
if e == v {
valid = true
break
}
}
valid := slices.Contains(shared.ValidEvents, e)
if !valid {
return fmt.Errorf("invalid --event value %q: valid values are %s", e, strings.Join(shared.ValidEvents, ", "))
}

View File

@@ -17,6 +17,7 @@ package update
import (
"encoding/json"
"fmt"
"slices"
"strings"
"github.com/spf13/cobra"
@@ -68,13 +69,7 @@ func NewCmdUpdate(f *cmdutil.Factory) *cobra.Command {
if cmd.Flags().Changed("event") {
for _, e := range flagEvents {
valid := false
for _, v := range shared.ValidEvents {
if e == v {
valid = true
break
}
}
valid := slices.Contains(shared.ValidEvents, e)
if !valid {
return fmt.Errorf("invalid --event value %q: valid values are %s", e, strings.Join(shared.ValidEvents, ", "))
}