aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvince <vincetiu8@gmail.com>2020-06-17 08:34:36 +0800
committervince <vincetiu8@gmail.com>2020-06-18 20:12:26 +0800
commit87eeba413d6b482988f4ec176326c443334217d0 (patch)
tree1fd7b01cf5e7bac6bfdba69db5945b3d5fae8cde
parentde5565b5f9830556afa7bb5a95fa4e3f27a755c5 (diff)
downloadgit-bug-87eeba413d6b482988f4ec176326c443334217d0.tar.gz
Print JSON as a well-formed object
This prints all the bugs in a JSON array instead of one by one.
-rw-r--r--commands/ls.go10
1 files changed, 6 insertions, 4 deletions
diff --git a/commands/ls.go b/commands/ls.go
index fa3271e7..68cb0cfc 100644
--- a/commands/ls.go
+++ b/commands/ls.go
@@ -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(),
@@ -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
}
@@ -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)
}