Skip to content

Commit

Permalink
Add tab print to context manager
Browse files Browse the repository at this point in the history
  • Loading branch information
andscoop committed Sep 24, 2018
1 parent a898e0f commit b90035f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cluster/cluster.go
Expand Up @@ -90,6 +90,6 @@ func Switch(domain string) error {
if err != nil {
return err
}
config.PrintCurrentContext()

return nil
}
23 changes: 19 additions & 4 deletions config/context.go
Expand Up @@ -4,6 +4,15 @@ import (
"errors"
"fmt"
"strings"

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

var (
tab = printutil.Table{
Padding: []int{36, 36},
Header: []string{"CLUSTER", "WORKSPACE"},
}
)

// Contexts holds all available Context structs in a map
Expand Down Expand Up @@ -49,9 +58,8 @@ func (c Context) PrintContext() error {
workspace = "N/A"
}

r := "%-36s %-36s\n"
fmt.Printf(r, "CLUSTER", "WORKSPACE")
fmt.Printf(r, cluster, workspace)
tab.AddRow([]string{cluster, workspace}, false)
tab.Print()

return nil
}
Expand Down Expand Up @@ -158,11 +166,18 @@ func (c Context) SetContextKey(key, value string) error {

// SwitchContext sets the current config context to the one matching the provided Context struct
func (c Context) SwitchContext() error {
if c.ContextExists() {
co, err := c.GetContext()
if err != nil {
return err
} else {
viperHome.Set("context", c.Domain)
saveConfig(viperHome, HomeConfigFile)
}

tab.AddRow([]string{co.Domain, co.Workspace}, false)
tab.SuccessMsg = "\n Switched cluster"
tab.Print()

return nil
}

Expand Down

0 comments on commit b90035f

Please sign in to comment.