From c4fbb1b66e17077209f64ee2c5ad71fa552fade4 Mon Sep 17 00:00:00 2001 From: Andy Cooper Date: Wed, 1 Aug 2018 12:03:19 -0400 Subject: [PATCH] Add cluster switch cmd --- cluster/cluster.go | 21 +++++++++++++++------ cmd/cluster.go | 17 ++++++++++++++++- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/cluster/cluster.go b/cluster/cluster.go index fcc8dbe29..9523a398a 100644 --- a/cluster/cluster.go +++ b/cluster/cluster.go @@ -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 diff --git a/cmd/cluster.go b/cmd/cluster.go index 195434dcb..30cb71be4 100644 --- a/cmd/cluster.go +++ b/cmd/cluster.go @@ -2,6 +2,7 @@ package cmd import ( "github.com/astronomerio/astro-cli/cluster" + "github.com/astronomerio/astro-cli/config" "github.com/spf13/cobra" ) @@ -20,14 +21,23 @@ 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) } @@ -35,3 +45,8 @@ 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() +}