diff --git a/pkg/ctl/get/cluster.go b/pkg/ctl/get/cluster.go index 486f7ed553..bc7ba86591 100644 --- a/pkg/ctl/get/cluster.go +++ b/pkg/ctl/get/cluster.go @@ -3,6 +3,7 @@ package get import ( "fmt" "os" + "strings" "github.com/kubicorn/kubicorn/pkg/logger" "github.com/spf13/cobra" @@ -31,7 +32,7 @@ func getClusterCmd() *cobra.Command { fs := cmd.Flags() fs.StringVarP(&cfg.ClusterName, "name", "n", "", "EKS cluster name") - fs.BoolVarP(&listAllRegions, "all-regions", "a", false, "List clusters across all supported regions") + fs.BoolVarP(&listAllRegions, "all-regions", "A", false, "List clusters across all supported regions") fs.IntVar(&chunkSize, "chunk-size", defaultChunkSize, "Return large lists in chunks rather than all at once. Pass 0 to disable.") fs.StringVarP(&cfg.Region, "region", "r", "", "AWS region") @@ -42,10 +43,15 @@ func getClusterCmd() *cobra.Command { } func doGetCluster(cfg *api.ClusterConfig, name string) error { + regionGiven := cfg.Region != "" // eks.New resets this field, so we need to check if it was set in the fist place ctl := eks.New(cfg) - if err := ctl.CheckAuth(); err != nil { - return err + if !cfg.IsSupportedRegion() { + return fmt.Errorf("--region=%s is not supported - use one of: %s", cfg.Region, strings.Join(api.SupportedRegions(), ", ")) + } + + if regionGiven && listAllRegions { + logger.Warning("--region=%s is ignored, as --all-regions is given", cfg.Region) } if cfg.ClusterName != "" && name != "" { @@ -56,5 +62,13 @@ func doGetCluster(cfg *api.ClusterConfig, name string) error { cfg.ClusterName = name } + if cfg.ClusterName != "" && listAllRegions { + return fmt.Errorf("--all-regions is for listing all clusters, it must be used without cluster name flag/argument") + } + + if err := ctl.CheckAuth(); err != nil { + return err + } + return ctl.ListClusters(chunkSize, output, listAllRegions) }