From 103448c0c593990cb951d35e988f8d8d21cf44d4 Mon Sep 17 00:00:00 2001 From: Michelangelo Mori Date: Thu, 20 Jun 2024 10:16:05 +0200 Subject: [PATCH] Name flag is mandatory for minder provider update. The command minder provider update operates on a per-provider basis, which requires the name to be mandatory. --- cmd/cli/app/provider/provider_update.go | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/cmd/cli/app/provider/provider_update.go b/cmd/cli/app/provider/provider_update.go index 9f46892d74..ba5b409f3a 100644 --- a/cmd/cli/app/provider/provider_update.go +++ b/cmd/cli/app/provider/provider_update.go @@ -20,6 +20,7 @@ import ( "encoding/json" "errors" "fmt" + "os" "reflect" "strconv" "strings" @@ -129,14 +130,14 @@ func UpdateProviderCommand( providerName := viper.GetString("name") if providerName == "" { return cli.MessageAndError( - "missing mandatory flag", + "invalid option", errMissingProviderName, ) } project := viper.GetString("project") if project == "" { return cli.MessageAndError( - "missing mandatory flag", + "invalid option", errMissingProject, ) } @@ -156,6 +157,12 @@ func UpdateProviderCommand( if err != nil { return cli.MessageAndError("Failed to get provider", err) } + if resp.GetProvider() == nil { + return cli.MessageAndError( + "could not retrieve provider", + errors.New("provider was empty"), + ) + } provider := resp.GetProvider() bytes, err := provider.GetConfig().MarshalJSON() @@ -353,7 +360,7 @@ func recurConfigAttribute( } v, err := parserFunc(*attrValue) if err != nil { - return fmt.Errorf("expected bool, got %s", *attrValue) + return fmt.Errorf("expected %s, got %s", config.Kind(), *attrValue) } config.Set(*v) } else { @@ -504,6 +511,10 @@ func init() { ) updateCmd.Flags().StringSliceP( "unset-attribute", "u", []string{}, - "List of attributes to unset in the config in = format", + "List of attributes to unset in the config in format", ) + if err := updateCmd.MarkFlagRequired("name"); err != nil { + updateCmd.Printf("Error marking flag required: %s", err) + os.Exit(1) + } }