Skip to content

Commit

Permalink
chore: validate params #330
Browse files Browse the repository at this point in the history
  • Loading branch information
srinandan committed Jan 2, 2025
1 parent eefc15d commit 44956f0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 23 deletions.
27 changes: 15 additions & 12 deletions internal/cmd/integrations/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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")
Expand Down
27 changes: 16 additions & 11 deletions internal/cmd/integrations/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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)
}

Expand Down Expand Up @@ -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")

Expand Down

0 comments on commit 44956f0

Please sign in to comment.