diff options
Diffstat (limited to 'commands/bug')
-rw-r--r-- | commands/bug/bug.go | 33 | ||||
-rw-r--r-- | commands/bug/bug_comment.go | 2 | ||||
-rw-r--r-- | commands/bug/bug_comment_add.go | 2 | ||||
-rw-r--r-- | commands/bug/bug_comment_test.go | 1 | ||||
-rw-r--r-- | commands/bug/bug_label.go | 2 | ||||
-rw-r--r-- | commands/bug/bug_label_new.go | 4 | ||||
-rw-r--r-- | commands/bug/bug_label_rm.go | 4 | ||||
-rw-r--r-- | commands/bug/bug_select.go | 2 | ||||
-rw-r--r-- | commands/bug/bug_show.go | 4 | ||||
-rw-r--r-- | commands/bug/bug_status.go | 2 | ||||
-rw-r--r-- | commands/bug/bug_status_close.go | 2 | ||||
-rw-r--r-- | commands/bug/bug_status_open.go | 2 | ||||
-rw-r--r-- | commands/bug/bug_test.go | 89 | ||||
-rw-r--r-- | commands/bug/bug_title.go | 2 | ||||
-rw-r--r-- | commands/bug/bug_title_edit.go | 2 | ||||
-rw-r--r-- | commands/bug/completion.go | 4 |
16 files changed, 98 insertions, 59 deletions
diff --git a/commands/bug/bug.go b/commands/bug/bug.go index 4c83ffa5..55a1fa59 100644 --- a/commands/bug/bug.go +++ b/commands/bug/bug.go @@ -21,17 +21,18 @@ import ( ) type bugOptions struct { - statusQuery []string - authorQuery []string - metadataQuery []string - participantQuery []string - actorQuery []string - labelQuery []string - titleQuery []string - noQuery []string - sortBy string - sortDirection string - outputFormat string + statusQuery []string + authorQuery []string + metadataQuery []string + participantQuery []string + actorQuery []string + labelQuery []string + titleQuery []string + noQuery []string + sortBy string + sortDirection string + outputFormat string + outputFormatChanged bool } func NewBugCommand(env *execenv.Env) *cobra.Command { @@ -57,6 +58,7 @@ git bug status:open --by creation "foo bar" baz `, PreRunE: execenv.LoadBackend(env), RunE: execenv.CloseBackend(env, func(cmd *cobra.Command, args []string) error { + options.outputFormatChanged = cmd.Flags().Changed("format") return runBug(env, options, args) }), ValidArgsFunction: completion.Ls(env), @@ -93,7 +95,7 @@ git bug status:open --by creation "foo bar" baz flags.StringVarP(&options.sortDirection, "direction", "d", "asc", "Select the sorting direction. Valid values are [asc,desc]") cmd.RegisterFlagCompletionFunc("direction", completion.From([]string{"asc", "desc"})) - flags.StringVarP(&options.outputFormat, "format", "f", "", + flags.StringVarP(&options.outputFormat, "format", "f", "default", "Select the output formatting style. Valid values are [default,plain,id,json,org-mode]") cmd.RegisterFlagCompletionFunc("format", completion.From([]string{"default", "plain", "id", "json", "org-mode"})) @@ -156,14 +158,15 @@ func runBug(env *execenv.Env, opts bugOptions, args []string) error { } switch opts.outputFormat { - case "": + case "default": + if opts.outputFormatChanged { + return bugsDefaultFormatter(env, excerpts) + } if env.Out.IsTerminal() { return bugsDefaultFormatter(env, excerpts) } else { return bugsPlainFormatter(env, excerpts) } - case "default": - return bugsDefaultFormatter(env, excerpts) case "id": return bugsIDFormatter(env, excerpts) case "plain": diff --git a/commands/bug/bug_comment.go b/commands/bug/bug_comment.go index 5cb8ff17..b037f688 100644 --- a/commands/bug/bug_comment.go +++ b/commands/bug/bug_comment.go @@ -26,7 +26,7 @@ func newBugCommentCommand(env *execenv.Env) *cobra.Command { } func runBugComment(env *execenv.Env, args []string) error { - b, args, err := ResolveSelected(env.Backend, args) + b, _, err := ResolveSelected(env.Backend, args) if err != nil { return err } diff --git a/commands/bug/bug_comment_add.go b/commands/bug/bug_comment_add.go index 152a1893..132de233 100644 --- a/commands/bug/bug_comment_add.go +++ b/commands/bug/bug_comment_add.go @@ -41,7 +41,7 @@ func newBugCommentNewCommand(env *execenv.Env) *cobra.Command { } func runBugCommentNew(env *execenv.Env, opts bugCommentNewOptions, args []string) error { - b, args, err := ResolveSelected(env.Backend, args) + b, _, err := ResolveSelected(env.Backend, args) if err != nil { return err } diff --git a/commands/bug/bug_comment_test.go b/commands/bug/bug_comment_test.go index ecc1c5f6..add48b21 100644 --- a/commands/bug/bug_comment_test.go +++ b/commands/bug/bug_comment_test.go @@ -140,7 +140,6 @@ func requireCommentsEqual(t *testing.T, golden string, env *execenv.Env) { comments = normalizeParsedComments(t, comments) if *cmdtest.Update { - t.Log("Got here") for i, comment := range comments { fileName := fmt.Sprintf(goldenFilePattern, golden, i) require.NoError(t, os.WriteFile(fileName, []byte(comment.message), 0644)) diff --git a/commands/bug/bug_label.go b/commands/bug/bug_label.go index 554496e3..ec076922 100644 --- a/commands/bug/bug_label.go +++ b/commands/bug/bug_label.go @@ -24,7 +24,7 @@ func newBugLabelCommand(env *execenv.Env) *cobra.Command { } func runBugLabel(env *execenv.Env, args []string) error { - b, args, err := ResolveSelected(env.Backend, args) + b, _, err := ResolveSelected(env.Backend, args) if err != nil { return err } diff --git a/commands/bug/bug_label_new.go b/commands/bug/bug_label_new.go index 1e1f2d4f..9fff851c 100644 --- a/commands/bug/bug_label_new.go +++ b/commands/bug/bug_label_new.go @@ -22,12 +22,12 @@ func newBugLabelNewCommand(env *execenv.Env) *cobra.Command { } func runBugLabelNew(env *execenv.Env, args []string) error { - b, args, err := ResolveSelected(env.Backend, args) + b, cleanArgs, err := ResolveSelected(env.Backend, args) if err != nil { return err } - added := args + added := cleanArgs changes, _, err := b.ChangeLabels(text.CleanupOneLineArray(added), nil) diff --git a/commands/bug/bug_label_rm.go b/commands/bug/bug_label_rm.go index 6dda007c..d389830f 100644 --- a/commands/bug/bug_label_rm.go +++ b/commands/bug/bug_label_rm.go @@ -22,12 +22,12 @@ func newBugLabelRmCommand(env *execenv.Env) *cobra.Command { } func runBugLabelRm(env *execenv.Env, args []string) error { - b, args, err := ResolveSelected(env.Backend, args) + b, cleanArgs, err := ResolveSelected(env.Backend, args) if err != nil { return err } - removed := args + removed := cleanArgs changes, _, err := b.ChangeLabels(nil, text.CleanupOneLineArray(removed)) diff --git a/commands/bug/bug_select.go b/commands/bug/bug_select.go index 652c61ea..c93cd7b1 100644 --- a/commands/bug/bug_select.go +++ b/commands/bug/bug_select.go @@ -44,7 +44,7 @@ The complementary command is "git bug deselect" performing the opposite operatio func runBugSelect(env *execenv.Env, args []string) error { if len(args) == 0 { - return errors.New("You must provide a bug id") + return errors.New("a bug id must be provided") } prefix := args[0] diff --git a/commands/bug/bug_show.go b/commands/bug/bug_show.go index 9a03c9a3..ef20df2a 100644 --- a/commands/bug/bug_show.go +++ b/commands/bug/bug_show.go @@ -47,7 +47,7 @@ func newBugShowCommand(env *execenv.Env) *cobra.Command { } func runBugShow(env *execenv.Env, opts bugShowOptions, args []string) error { - b, args, err := ResolveSelected(env.Backend, args) + b, _, err := ResolveSelected(env.Backend, args) if err != nil { return err } @@ -91,7 +91,7 @@ func runBugShow(env *execenv.Env, opts bugShowOptions, args []string) error { case "title": env.Out.Printf("%s\n", snap.Title) default: - return fmt.Errorf("\nUnsupported field: %s\n", opts.fields) + return fmt.Errorf("unsupported field: %s", opts.fields) } return nil diff --git a/commands/bug/bug_status.go b/commands/bug/bug_status.go index 59bef3fd..c8542240 100644 --- a/commands/bug/bug_status.go +++ b/commands/bug/bug_status.go @@ -24,7 +24,7 @@ func newBugStatusCommand(env *execenv.Env) *cobra.Command { } func runBugStatus(env *execenv.Env, args []string) error { - b, args, err := ResolveSelected(env.Backend, args) + b, _, err := ResolveSelected(env.Backend, args) if err != nil { return err } diff --git a/commands/bug/bug_status_close.go b/commands/bug/bug_status_close.go index 1d06007b..7a8ae4de 100644 --- a/commands/bug/bug_status_close.go +++ b/commands/bug/bug_status_close.go @@ -21,7 +21,7 @@ func newBugStatusCloseCommand(env *execenv.Env) *cobra.Command { } func runBugStatusClose(env *execenv.Env, args []string) error { - b, args, err := ResolveSelected(env.Backend, args) + b, _, err := ResolveSelected(env.Backend, args) if err != nil { return err } diff --git a/commands/bug/bug_status_open.go b/commands/bug/bug_status_open.go index e99d2db0..0c0c02f0 100644 --- a/commands/bug/bug_status_open.go +++ b/commands/bug/bug_status_open.go @@ -21,7 +21,7 @@ func newBugStatusOpenCommand(env *execenv.Env) *cobra.Command { } func runBugStatusOpen(env *execenv.Env, args []string) error { - b, args, err := ResolveSelected(env.Backend, args) + b, _, err := ResolveSelected(env.Backend, args) if err != nil { return err } diff --git a/commands/bug/bug_test.go b/commands/bug/bug_test.go index e6fadd6f..c13e8db7 100644 --- a/commands/bug/bug_test.go +++ b/commands/bug/bug_test.go @@ -1,13 +1,12 @@ package bugcmd import ( - "encoding/json" "testing" "github.com/stretchr/testify/require" "github.com/MichaelMure/git-bug/commands/bug/testenv" - "github.com/MichaelMure/git-bug/commands/cmdjson" + . "github.com/MichaelMure/git-bug/commands/cmdtest" ) func Test_repairQuery(t *testing.T) { @@ -47,24 +46,69 @@ func Test_repairQuery(t *testing.T) { } func TestBug_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 -$` + const expOrgMode = `#+TODO: OPEN | CLOSED +* OPEN ` + ExpHumanId + ` [` + ExpOrgModeDate + `] John Doe: this is a bug title :: +** Last Edited: [` + ExpOrgModeDate + `] +** Actors: +: ` + ExpHumanId + ` John Doe +** Participants: +: ` + ExpHumanId + ` John Doe +` + + const expJson = `[ + { + "id": "` + ExpId + `", + "human_id": "` + ExpHumanId + `", + "create_time": { + "timestamp": ` + ExpTimestamp + `, + "time": "` + ExpISO8601 + `", + "lamport": 2 + }, + "edit_time": { + "timestamp": ` + ExpTimestamp + `, + "time": "` + ExpISO8601 + `", + "lamport": 2 + }, + "status": "open", + "labels": null, + "title": "this is a bug title", + "actors": [ + { + "id": "` + ExpId + `", + "human_id": "` + ExpHumanId + `", + "name": "John Doe", + "login": "" + } + ], + "participants": [ + { + "id": "` + ExpId + `", + "human_id": "` + ExpHumanId + `", + "name": "John Doe", + "login": "" + } + ], + "author": { + "id": "` + ExpId + `", + "human_id": "` + ExpHumanId + `", + "name": "John Doe", + "login": "" + }, + "comments": 1, + "metadata": {} + } +] +` cases := []struct { format string exp string }{ - {"default", "^[0-9a-f]{7}\topen\tthis is a bug title John Doe \n$"}, - {"plain", "^[0-9a-f]{7}\topen\tthis is a bug title\n$"}, - {"id", "^[0-9a-f]{64}\n$"}, + {"default", ExpHumanId + "\topen\tthis is a bug title John Doe \n"}, + {"plain", ExpHumanId + "\topen\tthis is a bug title\n"}, + {"id", ExpId + "\n"}, {"org-mode", expOrgMode}, - {"json", ".*"}, + {"json", expJson}, } for _, testcase := range cases { @@ -72,21 +116,14 @@ $` env, _ := testenv.NewTestEnvAndBug(t) opts := bugOptions{ - sortDirection: "asc", - sortBy: "creation", - outputFormat: testcase.format, + sortDirection: "asc", + sortBy: "creation", + outputFormat: testcase.format, + outputFormatChanged: true, // disable auto-detect } require.NoError(t, runBug(env, opts, []string{})) - - switch testcase.format { - case "json": - var bugs []cmdjson.BugExcerpt - require.NoError(t, json.Unmarshal(env.Out.Bytes(), &bugs)) - require.Len(t, bugs, 1) - default: - require.Regexp(t, testcase.exp, env.Out.String()) - } + require.Regexp(t, MakeExpectedRegex(testcase.exp), env.Out.String()) }) } } diff --git a/commands/bug/bug_title.go b/commands/bug/bug_title.go index 47603410..af959fb7 100644 --- a/commands/bug/bug_title.go +++ b/commands/bug/bug_title.go @@ -23,7 +23,7 @@ func newBugTitleCommand(env *execenv.Env) *cobra.Command { } func runBugTitle(env *execenv.Env, args []string) error { - b, args, err := ResolveSelected(env.Backend, args) + b, _, err := ResolveSelected(env.Backend, args) if err != nil { return err } diff --git a/commands/bug/bug_title_edit.go b/commands/bug/bug_title_edit.go index fc60824f..2d6bafca 100644 --- a/commands/bug/bug_title_edit.go +++ b/commands/bug/bug_title_edit.go @@ -38,7 +38,7 @@ func newBugTitleEditCommand(env *execenv.Env) *cobra.Command { } func runBugTitleEdit(env *execenv.Env, opts bugTitleEditOptions, args []string) error { - b, args, err := ResolveSelected(env.Backend, args) + b, _, err := ResolveSelected(env.Backend, args) if err != nil { return err } diff --git a/commands/bug/completion.go b/commands/bug/completion.go index 4754f97d..62bf658a 100644 --- a/commands/bug/completion.go +++ b/commands/bug/completion.go @@ -50,7 +50,7 @@ func BugAndLabelsCompletion(env *execenv.Env, addOrRemove bool) completion.Valid _ = env.Backend.Close() }() - b, args, err := ResolveSelected(env.Backend, args) + b, cleanArgs, err := ResolveSelected(env.Backend, args) if _select.IsErrNoValidId(err) { // we need a bug first to complete labels return bugWithBackend(env.Backend, toComplete) @@ -62,7 +62,7 @@ func BugAndLabelsCompletion(env *execenv.Env, addOrRemove bool) completion.Valid snap := b.Snapshot() seenLabels := map[bug.Label]bool{} - for _, label := range args { + for _, label := range cleanArgs { seenLabels[bug.Label(label)] = addOrRemove } |