aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteve Moyer <smoyer1@selesy.com>2022-08-18 08:26:04 -0400
committerGitHub <noreply@github.com>2022-08-18 08:26:04 -0400
commitec24de3f0d19ff1a56d0b12d389ec1535be43ea2 (patch)
tree57668f8cdede563747a23a16e19b6304683bf692
parent94e3bc85d4dea8eefa6c659e2f892b09dd7ddb41 (diff)
parent870fe69362f9225fa22de5ed3f0d8e2ecd02c3fb (diff)
downloadgit-bug-ec24de3f0d19ff1a56d0b12d389ec1535be43ea2.tar.gz
Merge pull request #851 from MichaelMure/feat-836-machine-parseable-ls-text
feat(836): updates default `ls` formatter for TSV output
-rw-r--r--commands/ls.go2
-rw-r--r--commands/ls_test.go58
2 files changed, 59 insertions, 1 deletions
diff --git a/commands/ls.go b/commands/ls.go
index 61724f2a..f5fc6681 100644
--- a/commands/ls.go
+++ b/commands/ls.go
@@ -279,7 +279,7 @@ func lsDefaultFormatter(env *Env, bugExcerpts []*cache.BugExcerpt) error {
comments = " ∞ 💬"
}
- env.out.Printf("%s %s\t%s\t%s\t%s\n",
+ env.out.Printf("%s\t%s\t%s\t%s\t%s\n",
colors.Cyan(b.Id.Human()),
colors.Yellow(b.Status),
titleFmt+labelsFmt,
diff --git a/commands/ls_test.go b/commands/ls_test.go
index aff94e03..6e31ed83 100644
--- a/commands/ls_test.go
+++ b/commands/ls_test.go
@@ -1,6 +1,8 @@
package commands
import (
+ "encoding/json"
+ "fmt"
"testing"
"github.com/stretchr/testify/require"
@@ -41,3 +43,59 @@ func Test_repairQuery(t *testing.T) {
require.Equal(t, tc.output, repairQuery(tc.args))
}
}
+
+func TestLs_Format(t *testing.T) {
+ const expOrgMode = `^#+TODO: OPEN | CLOSED
+[*] OPEN [0-9a-f]{7} \[\d\d\d\d-\d\d-\d\d [[:alpha:]]{3} \d\d:\d\d\] John Doe: this is a bug title ::
+[*]{2} Last Edited: \[\d\d\d\d-\d\d-\d\d [[:alpha:]]{3} \d\d:\d\d\]
+[*]{2} Actors:
+: [0-9a-f]{7} John Doe
+[*]{2} Participants:
+: [0-9a-f]{7} John Doe
+$`
+
+ cases := []struct {
+ format string
+ exp string
+ }{
+ {"default", "^[0-9a-f]{7}\topen\tthis is a bug title \tJohn Doe \t\n$"},
+ {"plain", "^[0-9a-f]{7} \\[open\\] this is a bug title\n$"},
+ {"compact", "^[0-9a-f]{7} open this is a bug title John Doe\n$"},
+ {"org-mode", expOrgMode},
+ }
+
+ for _, testcase := range cases {
+ opts := lsOptions{
+ sortDirection: "asc",
+ sortBy: "creation",
+ outputFormat: testcase.format,
+ }
+
+ name := fmt.Sprintf("with %s format", testcase.format)
+
+ t.Run(name, func(t *testing.T) {
+ env, _ := newTestEnvAndBug(t)
+
+ require.NoError(t, runLs(env.env, opts, []string{}))
+ t.Log(env.out.String())
+ require.Regexp(t, testcase.exp, env.out.String())
+ })
+ }
+
+ t.Run("with JSON format", func(t *testing.T) {
+ opts := lsOptions{
+ sortDirection: "asc",
+ sortBy: "creation",
+ outputFormat: "json",
+ }
+
+ env, _ := newTestEnvAndBug(t)
+
+ require.NoError(t, runLs(env.env, opts, []string{}))
+
+ bugs := []JSONBugExcerpt{}
+ require.NoError(t, json.Unmarshal(env.out.Bytes(), &bugs))
+
+ require.Len(t, bugs, 1)
+ })
+}