Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions cmd/deploy/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -665,8 +665,17 @@ func TestDeployVersions(t *testing.T) {
t.Fatalf("failed to write file: %v", err)
}

var hidden strings.Builder
if err := runDeployVersions(tmpDir, &hidden, false); err != nil {
t.Fatalf("runDeployVersions failed: %v", err)
}

if strings.Contains(hidden.String(), "cluster-b") || !strings.Contains(hidden.String(), "cluster-a") {
t.Errorf("unknown environments should be hidden by default, got: %q", hidden.String())
}

var out strings.Builder
if err := runDeployVersions(tmpDir, &out); err != nil {
if err := runDeployVersions(tmpDir, &out, true); err != nil {
t.Fatalf("runDeployVersions failed: %v", err)
}

Expand Down Expand Up @@ -701,7 +710,7 @@ func TestDeployVersionsNoEnvironments(t *testing.T) {
tmpDir := t.TempDir()

var out strings.Builder
if err := runDeployVersions(tmpDir, &out); err == nil {
if err := runDeployVersions(tmpDir, &out, false); err == nil {
t.Fatal("expected error when no environments exist")
}
}
Expand Down
20 changes: 15 additions & 5 deletions cmd/deploy/versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,25 @@ import (
)

func newCmdDeployVersions() *cobra.Command {
var showUnknowns bool

cmd := &cobra.Command{
Use: "versions",
Short: "Show the UnderStack version deployed in each environment",
Long: `List every environment in the deployment repo along with its understack_ref and deploy_ref from deploy.yaml.`,
Args: cobra.NoArgs,
Long: `List every environment in the deployment repo along with its understack_ref and deploy_ref from deploy.yaml.
Environments where either ref is unknown are hidden unless --show-unknowns is passed.`,
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
return runDeployVersions(".", cmd.OutOrStdout())
return runDeployVersions(".", cmd.OutOrStdout(), showUnknowns)
},
}

cmd.Flags().BoolVar(&showUnknowns, "show-unknowns", false, "include environments whose understack_ref or deploy_ref is unknown")

return cmd
}

func runDeployVersions(repoDir string, out io.Writer) error {
func runDeployVersions(repoDir string, out io.Writer, showUnknowns bool) error {
entries, err := os.ReadDir(repoDir)
if err != nil {
return fmt.Errorf("failed to read deployment repo: %w", err)
Expand Down Expand Up @@ -60,8 +65,13 @@ func runDeployVersions(repoDir string, out io.Writer) error {
deployRef = "unknown"
}

_, _ = fmt.Fprintf(w, "%s\t%s\t%s\n", entry.Name(), understackRef, deployRef)
found = true

if !showUnknowns && (understackRef == "unknown" || deployRef == "unknown") {
continue
}

_, _ = fmt.Fprintf(w, "%s\t%s\t%s\n", entry.Name(), understackRef, deployRef)
}

if !found {
Expand Down
Loading