Fix `kops get clusters` to support filtering by name

We were using it in the upgrade docs, but it wasn't actually
implemented.
This commit is contained in:
Justin Santa Barbara 2016-10-15 13:12:31 -04:00
parent 591a85056a
commit b614cbd130
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