Merge pull request #655 from justinsb/kops_get_cluster_by_name

Fix `kops get clusters` to support filtering by name
This commit is contained in:
Chris Love 2016-10-15 17:14:04 -06:00 committed by GitHub
commit eb0f08f6cd
1 changed files with 20 additions and 2 deletions

View File

@ -48,9 +48,27 @@ func (c *GetClustersCmd) Run(args []string) error {
}
var clusters []*api.Cluster
if len(args) != 0 {
m := make(map[string]*api.Cluster)
for i := range clusterList.Items {
clusters = append(clusters, &clusterList.Items[i])
c := &clusterList.Items[i]
m[c.Name] = c
}
for _, arg := range args {
ig := m[arg]
if ig == nil {
return fmt.Errorf("cluster not found %q", arg)
}
clusters = append(clusters, ig)
}
} else {
for i := range clusterList.Items {
c := &clusterList.Items[i]
clusters = append(clusters, c)
}
}
if len(clusters) == 0 {
fmt.Fprintf(os.Stderr, "No clusters found\n")
return nil