Skip to content

Commit

Permalink
Update list commands to use printutil
Browse files Browse the repository at this point in the history
  • Loading branch information
andscoop committed Sep 24, 2018
1 parent 28b5490 commit b4a785e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 31 deletions.
26 changes: 13 additions & 13 deletions cluster/cluster.go
@@ -1,19 +1,21 @@
package cluster

import (
"fmt"
"strings"

"github.com/astronomerio/astro-cli/config"
"github.com/astronomerio/astro-cli/pkg/printutil"
)

// List all available clusters a user has previously
// authenticated to
// List all available clusters a user has previously authenticated to
// Returns error
func List() error {
r := " %-44s"
colorFmt := "\033[33;m"
colorTrm := "\033[0m"
tab := printutil.Table{
Padding: []int{44},
Header: []string{"NAME"},
ColorRowCode: [2]string{"\033[33;m", "\033[0m"},
}

var domain string

c, err := GetClusters()
Expand All @@ -26,24 +28,22 @@ func List() error {
return err
}

h := fmt.Sprintf(r, "NAME")
fmt.Println(h)
for k, v := range c.Contexts {
if v.Domain != "" {
domain = v.Domain
} else {
domain = strings.Replace(k, "_", ".", -1)
}

fullStr := fmt.Sprintf(r, domain)
if domain == ctx.Domain {
fullStr = colorFmt + fullStr + colorTrm
tab.AddRow([]string{domain}, true)
} else {
tab.AddRow([]string{domain}, false)
}

fmt.Println(fullStr)

}

tab.Print()

return nil
}

Expand Down
19 changes: 11 additions & 8 deletions deployment/deployment.go
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/astronomerio/astro-cli/messages"
"github.com/astronomerio/astro-cli/pkg/httputil"
"github.com/astronomerio/astro-cli/pkg/jsonstr"
"github.com/astronomerio/astro-cli/pkg/printutil"
)

var (
Expand Down Expand Up @@ -57,11 +58,6 @@ func List(ws string, all bool) error {
var deployments []houston.Deployment
var err error

r := " %-30s %-50s %-50s %-50s"
h := fmt.Sprintf(r, "NAME", "RELEASE NAME", "DEPLOYMENT ID", "WORKSPACE")
// colorFmt := "\033[33;m"
// colorTrm := "\033[0m"

if all {
deployments, err = api.GetAllDeployments()
if err != nil {
Expand All @@ -74,15 +70,22 @@ func List(ws string, all bool) error {
}
}

fmt.Println(h)
tab := printutil.Table{
Padding: []int{30, 50, 50, 50},
Header: []string{"NAME", "RELEASE NAME", "DEPLOYMENT ID", "WORKSPACE"},
}

// Build rows
for _, d := range deployments {
if all {
ws = d.Workspace.Uuid
}
fullStr := fmt.Sprintf(r, d.Label, d.ReleaseName, d.Id, ws)
fmt.Println(fullStr)

tab.AddRow([]string{d.Label, d.ReleaseName, d.Id, ws}, false)
}

tab.Print()

return nil
}

Expand Down
21 changes: 11 additions & 10 deletions workspace/workspace.go
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/astronomerio/astro-cli/messages"
"github.com/astronomerio/astro-cli/pkg/httputil"
"github.com/astronomerio/astro-cli/pkg/jsonstr"
"github.com/astronomerio/astro-cli/pkg/printutil"
)

var (
Expand All @@ -29,31 +30,31 @@ func Create(label, desc string) error {

// List all workspaces
func List() error {
r := " %-44s %-50s"
colorFmt := "\033[33;m"
colorTrm := "\033[0m"
tab := printutil.Table{
Padding: []int{44, 50},
Header: []string{"NAME", "UUID"},
ColorRowCode: [2]string{"\033[33;m", "\033[0m"},
}

ws, err := api.GetWorkspaceAll()
if err != nil {
return err
}

c, err := config.GetCurrentContext()

head := fmt.Sprintf(r, "NAME", "UUID")
fmt.Println(head)
for _, w := range ws {
name := w.Label
workspace := w.Uuid

fullStr := fmt.Sprintf(r, name, workspace)
if c.Workspace == w.Uuid {
fullStr = colorFmt + fullStr + colorTrm
tab.AddRow([]string{name, workspace}, true)
} else {
tab.AddRow([]string{name, workspace}, false)
}

fmt.Println(fullStr)
}

tab.Print()

return nil
}

Expand Down

0 comments on commit b4a785e

Please sign in to comment.