Skip to content

Commit

Permalink
Add cluster switch cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
andscoop committed Aug 1, 2018
1 parent b77c76b commit c4fbb1b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
21 changes: 15 additions & 6 deletions cluster/cluster.go
Expand Up @@ -8,21 +8,30 @@ import (
)

func ListClusters() error {
var domain string
c, err := config.GetClusters()
if err != nil {
return err
}

ctx, err := config.GetCurrentCluster()
if err != nil {
return err
}

for k, v := range c.Clusters {
var name string
if v.Domain != "" {
name = v.Domain
domain = v.Domain
} else {
name = strings.Replace(k, "_", ".", -1)
domain = strings.Replace(k, "_", ".", -1)
}
fmt.Println(name)
fmt.Printf("\t Workspace: %s", v.Workspace)
fmt.Println("\n")

if domain == ctx.Domain {
domain = domain + " (current)"
}

fmt.Println(domain)

}

return nil
Expand Down
17 changes: 16 additions & 1 deletion cmd/cluster.go
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"github.com/astronomerio/astro-cli/cluster"
"github.com/astronomerio/astro-cli/config"
"github.com/spf13/cobra"
)

Expand All @@ -20,18 +21,32 @@ var (
Long: "List known Astronomer Enterprise clusters",
RunE: clusterList,
}

clusterSwitchCmd = &cobra.Command{
Use: "switch",
Aliases: []string{"sw"},
Short: "Switch to a different cluster context",
Long: "Switch to a different cluster context",
RunE: clusterSwitch,
Args: cobra.ExactArgs(1),
}
)

func init() {
// deployment root
RootCmd.AddCommand(clusterRootCmd)

// deployment create
clusterRootCmd.AddCommand(clusterListCmd)
clusterRootCmd.AddCommand(clusterSwitchCmd)

}

func clusterList(cmd *cobra.Command, args []string) error {
cluster.ListClusters()
return nil
}

func clusterSwitch(cmd *cobra.Command, args []string) error {
c := config.Cluster{Domain: args[0]}
return c.SwitchCluster()
}

0 comments on commit c4fbb1b

Please sign in to comment.