Skip to content

Commit

Permalink
Merge pull request #345 from GoogleCloudPlatform/issue330_3
Browse files Browse the repository at this point in the history
bug: disables print during search
  • Loading branch information
srinandan authored Jan 10, 2025
2 parents 1656ada + 322e492 commit 78a137c
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 45 deletions.
6 changes: 6 additions & 0 deletions internal/cmd/integrations/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ var ArchiveVerCmd = &cobra.Command{
if err != nil {
return fmt.Errorf("unable to list versions: %v", err)
}
if string(respBody) == "{}" {
if respBody, err = integrations.ListVersions(name, 1, "", "state=DRAFT",
"snapshot_number", false, false, true); err != nil {
return fmt.Errorf("unable to list versions: %v", err)
}
}
version, err = getIntegrationVersion(respBody)
if err != nil {
return err
Expand Down
6 changes: 6 additions & 0 deletions internal/cmd/integrations/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ var DownloadVerCmd = &cobra.Command{
if err != nil {
return fmt.Errorf("unable to list versions: %v", err)
}
if string(respBody) == "{}" {
if respBody, err = integrations.ListVersions(name, 1, "", "state=DRAFT",
"snapshot_number", false, false, true); err != nil {
return fmt.Errorf("unable to list versions: %v", err)
}
}
version, err = getIntegrationVersion(respBody)
if err != nil {
return err
Expand Down
27 changes: 4 additions & 23 deletions internal/cmd/integrations/getversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package integrations

import (
"errors"
"fmt"
"internal/apiclient"
"internal/client/integrations"
"internal/clilog"
Expand Down Expand Up @@ -65,7 +64,7 @@ var GetVerCmd = &cobra.Command{
RunE: func(cmd *cobra.Command, args []string) (err error) {
cmd.SilenceUsage = true

var integrationBody, respBody, listBody []byte
var integrationBody, respBody []byte
version := utils.GetStringParam(cmd.Flag("ver"))
name := utils.GetStringParam(cmd.Flag("name"))
minimal, _ := strconv.ParseBool(utils.GetStringParam(cmd.Flag("minimal")))
Expand All @@ -81,26 +80,8 @@ var GetVerCmd = &cobra.Command{

latest := ignoreLatest(version, userLabel, snapshot)
if latest {
// list integration versions, order by state=ACTIVE, page size = 1 and return basic info
if listBody, err = integrations.ListVersions(name, 1, "", "state=ACTIVE",
"snapshot_number", false, false, true); err != nil {
return fmt.Errorf("unable to list versions: %v", err)
}
if string(listBody) != "{}" {
if version, err = getIntegrationVersion(listBody); err != nil {
return err
}
} else {
// list integration versions, order by state=SNAPSHOT, page size = 1 and return basic info
if listBody, err = integrations.ListVersions(name, 1, "", "state=SNAPSHOT",
"snapshot_number", false, false, true); err != nil {
return fmt.Errorf("unable to list versions: %v", err)
}
if string(listBody) != "{}" {
if version, err = getIntegrationVersion(listBody); err != nil {
return err
}
}
if version, err = getLatestVersion(name); err != nil {
return err
}
}

Expand Down Expand Up @@ -155,7 +136,7 @@ func init() {
GetVerCmd.Flags().BoolVarP(&configVar, "config-vars", "",
false, "Returns config variables for the integration")
GetVerCmd.Flags().BoolVarP(&latest, "latest", "",
true, "Get the integeration version in ACTIVE state, if not found the highest snapshot in SNAPSHOT state; default is true")
true, "Get the version with the highest snapshot number in SNAPSHOT state. If none found, selects the highest snapshot in DRAFT state; default is true")

_ = GetVerCmd.MarkFlagRequired("name")
}
44 changes: 44 additions & 0 deletions internal/cmd/integrations/integrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
package integrations

import (
"fmt"
"internal/apiclient"
"internal/client/integrations"

"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -73,3 +77,43 @@ func init() {
func GetExample(i int) string {
return examples[i]
}

func getLatestVersion(name string) (version string, err error) {
var listBody []byte

apiclient.DisableCmdPrintHttpResponse()
defer apiclient.EnableCmdPrintHttpResponse()

// list integration versions, order by state=ACTIVE, page size = 1 and return basic info
if listBody, err = integrations.ListVersions(name, 1, "", "state=ACTIVE",
"snapshot_number", false, false, true); err != nil {
return "", fmt.Errorf("unable to list versions: %v", err)
}
if string(listBody) != "{}" {
if version, err = getIntegrationVersion(listBody); err != nil {
return "", err
}
} else {
// list integration versions, order by state=SNAPSHOT, page size = 1 and return basic info
if listBody, err = integrations.ListVersions(name, 1, "", "state=SNAPSHOT",
"snapshot_number", false, false, true); err != nil {
return "", fmt.Errorf("unable to list versions: %v", err)
}
if string(listBody) != "{}" {
if version, err = getIntegrationVersion(listBody); err != nil {
return "", err
}
} else {
if listBody, err = integrations.ListVersions(name, 1, "", "state=DRAFT",
"snapshot_number", false, false, true); err != nil {
return "", fmt.Errorf("unable to list versions: %v", err)
}
if string(listBody) != "{}" {
if version, err = getIntegrationVersion(listBody); err != nil {
return "", err
}
}
}
}
return version, nil
}
6 changes: 6 additions & 0 deletions internal/cmd/integrations/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ var PublishVerCmd = &cobra.Command{
if err != nil {
return fmt.Errorf("unable to list versions: %v", err)
}
if string(respBody) == "{}" {
if respBody, err = integrations.ListVersions(name, 1, "", "state=DRAFT",
"snapshot_number", false, false, true); err != nil {
return fmt.Errorf("unable to list versions: %v", err)
}
}
version, err = getIntegrationVersion(respBody)
if err != nil {
return err
Expand Down
26 changes: 4 additions & 22 deletions internal/cmd/integrations/scaffold.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ var ScaffoldCmd = &cobra.Command{

const jsonExt = ".json"
var fileSplitter string
var integrationBody, overridesBody, listBody []byte
var integrationBody, overridesBody []byte
version := utils.GetStringParam(cmd.Flag("ver"))
userLabel := utils.GetStringParam(cmd.Flag("user-label"))
snapshot := utils.GetStringParam(cmd.Flag("snapshot"))
Expand Down Expand Up @@ -97,26 +97,8 @@ var ScaffoldCmd = &cobra.Command{
latest := ignoreLatest(version, userLabel, snapshot)

if latest {
// list integration versions, order by state=ACTIVE, page size = 1 and return basic info
if listBody, err = integrations.ListVersions(name, 1, "", "state=ACTIVE",
"snapshot_number", false, false, true); err != nil {
return fmt.Errorf("unable to list versions: %v", err)
}
if string(listBody) != "{}" {
if version, err = getIntegrationVersion(listBody); err != nil {
return err
}
} else {
// list integration versions, order by state=SNAPSHOT, page size = 1 and return basic info
if listBody, err = integrations.ListVersions(name, 1, "", "state=SNAPSHOT",
"snapshot_number", false, false, true); err != nil {
return fmt.Errorf("unable to list versions: %v", err)
}
if string(listBody) != "{}" {
if version, err = getIntegrationVersion(listBody); err != nil {
return err
}
}
if version, err = getLatestVersion(name); err != nil {
return err
}
}

Expand Down Expand Up @@ -455,7 +437,7 @@ func init() {
ScaffoldCmd.Flags().BoolVarP(&extractCode, "extract-code", "x",
false, "Extract JavaScript and Jsonnet code as separate files; default is false")
ScaffoldCmd.Flags().BoolVarP(&latest, "latest", "",
true, "Scaffolds the integeration version in ACTIVE state, if not found the highest snapshot in SNAPSHOT state; default is true")
true, "Scaffolds the version with the highest snapshot number in SNAPSHOT state. If none found, selects the highest snapshot in DRAFT state; default is true")

_ = ScaffoldCmd.MarkFlagRequired("name")
}
Expand Down
6 changes: 6 additions & 0 deletions internal/cmd/integrations/unpublish.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ var UnPublishVerCmd = &cobra.Command{
if err != nil {
return fmt.Errorf("unable to list versions: %v", err)
}
if string(respBody) == "{}" {
if respBody, err = integrations.ListVersions(name, 1, "", "state=DRAFT",
"snapshot_number", false, false, true); err != nil {
return fmt.Errorf("unable to list versions: %v", err)
}
}
version, err = getIntegrationVersion(respBody)
if err != nil {
return err
Expand Down

0 comments on commit 78a137c

Please sign in to comment.