Skip to content

Commit

Permalink
Added Marques's suggested changes to fix json output.
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Privitere <cprivite@users.noreply.github.com>
  • Loading branch information
Chris Privitere committed Jan 21, 2022
1 parent 7bc2f50 commit 01e5ac0
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions internal/capacity/retrieve.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,21 +75,26 @@ func (c *Client) Retrieve() *cobra.Command {
header := []string{locationField, "Plan", "Level"}
data := [][]string{}

filtered := map[string]map[string]map[string]string{}

for locCode, capacity := range *capacities {
// If the list of locations isn't empty and contains this location code
if !(len(locs) > 0 && !contains(locs, locCode)) {
for plan, bm := range capacity {
loc := []string{}
// If the list of plans isn't empty and contains this plan
if !(len(plans) > 0 && !contains(plans, plan)) {
loc = append(loc, locCode, plan, bm.Level)
data = append(data, loc)
}
if len(locs) > 0 && !contains(locs, locCode) {
continue
}
for plan, bm := range capacity {
if len(plans) > 0 && !contains(plans, plan) {
continue
}
loc := []string{locCode, plan, bm.Level}
data = append(data, loc)
if len(filtered[locCode]) == 0 {
filtered[locCode] = map[string]map[string]string{}
}
filtered[locCode][plan] = map[string]string{"levels": bm.Level}
}
}

return c.Out.Output(capacities, header, &data)
return c.Out.Output(filtered, header, &data)
},
}

Expand Down

0 comments on commit 01e5ac0

Please sign in to comment.