Skip to content

Commit

Permalink
Print JSON as a well-formed object
Browse files Browse the repository at this point in the history
This prints all the bugs in a JSON array instead of one by one.
  • Loading branch information
vincetiu8 committed Jun 18, 2020
1 parent de5565b commit 87eeba4
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions commands/ls.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ type JSONIdentity struct {
}

func lsJsonFormatter(backend *cache.RepoCache, bugExcerpts []*cache.BugExcerpt) error {
for _, b := range bugExcerpts {
jsonBugs := make([]JSONBug, len(bugExcerpts))
for i, b := range bugExcerpts {
jsonBug := JSONBug{
b.Id.String(),
b.Id.Human(),
Expand Down Expand Up @@ -155,9 +156,10 @@ func lsJsonFormatter(backend *cache.RepoCache, bugExcerpts []*cache.BugExcerpt)
})
}

jsonObject, _ := json.MarshalIndent(jsonBug, "", " ")
fmt.Printf("%s\n", jsonObject)
jsonBugs[i] = jsonBug
}
jsonObject, _ := json.MarshalIndent(jsonBugs, "", " ")
fmt.Printf("%s\n", jsonObject)
return nil
}

Expand Down Expand Up @@ -203,7 +205,7 @@ func lsDefaultFormatter(backend *cache.RepoCache, bugExcerpts []*cache.BugExcerp
return nil
}

func lsPlainFormatter(backend *cache.RepoCache, bugExcerpts []*cache.BugExcerpt) error {
func lsPlainFormatter(_ *cache.RepoCache, bugExcerpts []*cache.BugExcerpt) error {
for _, b := range bugExcerpts {
fmt.Printf("[%s] %s\n", b.Status, b.Title)
}
Expand Down

0 comments on commit 87eeba4

Please sign in to comment.