Skip to content

Commit

Permalink
Add flag validation, use -A as alias for --all-regions
Browse files Browse the repository at this point in the history
As `-a` will be more appropritate for `--all`, that would be for
including clusters with non-active status (i.e. creating & deleting).
  • Loading branch information
errordeveloper committed Nov 5, 2018
1 parent 6a68025 commit ae6c894
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions pkg/ctl/get/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package get
import (
"fmt"
"os"
"strings"

"github.com/kubicorn/kubicorn/pkg/logger"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -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")
Expand All @@ -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 != "" {
Expand All @@ -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)
}

0 comments on commit ae6c894

Please sign in to comment.