From 44956f04666b35533673d41711565c7db748dcb6 Mon Sep 17 00:00:00 2001 From: srinandan Date: Thu, 2 Jan 2025 22:47:17 +0000 Subject: [PATCH] chore: validate params #330 --- internal/cmd/integrations/create.go | 27 +++++++++++++++------------ internal/cmd/integrations/publish.go | 27 ++++++++++++++++----------- 2 files changed, 31 insertions(+), 23 deletions(-) diff --git a/internal/cmd/integrations/create.go b/internal/cmd/integrations/create.go index e3a9b3a..bc30b85 100644 --- a/internal/cmd/integrations/create.go +++ b/internal/cmd/integrations/create.go @@ -39,7 +39,9 @@ var CreateCmd = &cobra.Command{ if basic && publish { return fmt.Errorf("cannot combine basic and publish flags") } - + if configVarsFile != "" && configVarsJson != "" { + return fmt.Errorf("cannot use config-vars and config-vars-json flags together") + } if !publish && (configVarsFile != "" || configVarsJson != "") { return fmt.Errorf("cannot use config-vars and config-vars-json flags when publish is false") } @@ -58,20 +60,21 @@ var CreateCmd = &cobra.Command{ configVarsJson := cmd.Flag("config-vars-json").Value.String() configVarsFile := cmd.Flag("config-vars").Value.String() - if configVarsJson == "" { - if configVarsFile != "" { - if _, err := os.Stat(configVarsFile); os.IsNotExist(err) { - return err - } + if configVarsFile != "" { + if _, err := os.Stat(configVarsFile); os.IsNotExist(err) { + return err + } - contents, err = os.ReadFile(configVarsFile) - if err != nil { - return err - } + contents, err = os.ReadFile(configVarsFile) + if err != nil { + return err } - } else { + } + + if configVarsJson != "" { contents = []byte(configVarsJson) } + if _, err := os.Stat(integrationFile); os.IsNotExist(err) { return err } @@ -150,7 +153,7 @@ func init() { CreateCmd.Flags().StringVarP(&configVars, "config-vars", "", "", "Path to file containing config variables") CreateCmd.Flags().StringVarP(&configVarsJson, "config-vars-json", "", - "", "Json string containing the config variables if both Json string and file is present Json string will only be used.") + "", "JSON string containing the config variables") _ = CreateCmd.MarkFlagRequired("name") _ = CreateCmd.MarkFlagRequired("file") diff --git a/internal/cmd/integrations/publish.go b/internal/cmd/integrations/publish.go index 1aee52e..6b5a600 100644 --- a/internal/cmd/integrations/publish.go +++ b/internal/cmd/integrations/publish.go @@ -38,8 +38,13 @@ var PublishVerCmd = &cobra.Command{ version := cmd.Flag("ver").Value.String() userLabel := cmd.Flag("user-label").Value.String() snapshot := cmd.Flag("snapshot").Value.String() + configVarsJson := cmd.Flag("config-vars-json").Value.String() + configVarsFile := cmd.Flag("config-vars").Value.String() latest, _ := strconv.ParseBool(cmd.Flag("latest").Value.String()) + if configVarsFile != "" && configVarsJson != "" { + return fmt.Errorf("cannot use config-vars and config-vars-json flags together") + } if err = apiclient.SetRegion(cmdRegion.Value.String()); err != nil { return err } @@ -59,18 +64,18 @@ var PublishVerCmd = &cobra.Command{ var contents []byte var info string - if configVarsJson == "" { - if configVarsFile != "" { - if _, err := os.Stat(configVarsFile); os.IsNotExist(err) { - return err - } + if configVarsFile != "" { + if _, err := os.Stat(configVarsFile); os.IsNotExist(err) { + return err + } - contents, err = os.ReadFile(configVarsFile) - if err != nil { - return err - } + contents, err = os.ReadFile(configVarsFile) + if err != nil { + return err } - } else { + } + + if configVarsJson != "" { contents = []byte(configVarsJson) } @@ -125,7 +130,7 @@ func init() { PublishVerCmd.Flags().StringVarP(&configVars, "config-vars", "", "", "Path to file containing config variables") PublishVerCmd.Flags().StringVarP(&configVarsJson, "config-vars-json", "", - "", "Json string containing the config variables if both Json string and file is present Json string will only be used.") + "", "JSON string containing the config variables.") PublishVerCmd.Flags().BoolVarP(&latest, "latest", "", true, "Publishes the integeration version with the highest snapshot number in SNAPSHOT state; default is true")