Skip to content

Commit

Permalink
Merge pull request #336 from GoogleCloudPlatform/issue330_2
Browse files Browse the repository at this point in the history
feat: add additional flags #330
  • Loading branch information
srinandan authored Jan 3, 2025
2 parents 3f78e28 + 44956f0 commit 83075f5
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 @@ -41,7 +41,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 @@ -63,20 +65,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 @@ -155,7 +158,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 @@ -39,8 +39,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 @@ -63,18 +68,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 @@ -129,7 +134,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 83075f5

Please sign in to comment.