diff options
-rw-r--r-- | commands/ls.go | 6 | ||||
-rw-r--r-- | commands/ls_test.go | 58 | ||||
-rw-r--r-- | doc/man/git-bug-ls.1 | 2 | ||||
-rw-r--r-- | doc/md/git-bug_ls.md | 2 |
4 files changed, 63 insertions, 5 deletions
diff --git a/commands/ls.go b/commands/ls.go index da5ea8ce..f5fc6681 100644 --- a/commands/ls.go +++ b/commands/ls.go @@ -91,9 +91,9 @@ git bug ls status:open --by creation "foo bar" baz "Select the sorting direction. Valid values are [asc,desc]") cmd.RegisterFlagCompletionFunc("direction", completeFrom([]string{"asc", "desc"})) flags.StringVarP(&options.outputFormat, "format", "f", "default", - "Select the output formatting style. Valid values are [default,plain,json,org-mode]") + "Select the output formatting style. Valid values are [default,plain,compact,json,org-mode]") cmd.RegisterFlagCompletionFunc("format", - completeFrom([]string{"default", "plain", "json", "org-mode"})) + completeFrom([]string{"default", "plain", "compact", "json", "org-mode"})) return cmd } @@ -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) + }) +} diff --git a/doc/man/git-bug-ls.1 b/doc/man/git-bug-ls.1 index 61a37610..873cf68c 100644 --- a/doc/man/git-bug-ls.1 +++ b/doc/man/git-bug-ls.1 @@ -62,7 +62,7 @@ You can pass an additional query to filter and order the list. This query can be .PP \fB-f\fP, \fB--format\fP="default" - Select the output formatting style. Valid values are [default,plain,json,org-mode] + Select the output formatting style. Valid values are [default,plain,compact,json,org-mode] .PP \fB-h\fP, \fB--help\fP[=false] diff --git a/doc/md/git-bug_ls.md b/doc/md/git-bug_ls.md index 7d1e490d..a40b3fd9 100644 --- a/doc/md/git-bug_ls.md +++ b/doc/md/git-bug_ls.md @@ -42,7 +42,7 @@ git bug ls status:open --by creation "foo bar" baz -n, --no strings Filter by absence of something. Valid values are [label] -b, --by string Sort the results by a characteristic. Valid values are [id,creation,edit] (default "creation") -d, --direction string Select the sorting direction. Valid values are [asc,desc] (default "asc") - -f, --format string Select the output formatting style. Valid values are [default,plain,json,org-mode] (default "default") + -f, --format string Select the output formatting style. Valid values are [default,plain,compact,json,org-mode] (default "default") -h, --help help for ls ``` |