diff options
author | Vincent Tiu <46623413+Invincibot@users.noreply.github.com> | 2020-11-17 21:35:31 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-17 21:35:31 +0800 |
commit | 466b5183c371b4ac7f905e33c4f8f36ddb7db9ff (patch) | |
tree | 1b477423060292af296b32971cda1ca0045e0c0d /commands | |
parent | 902997f53771babb2f9ea1bb6288c2ec295c4c9e (diff) | |
parent | ee3841155e5c58b85408f29a8d44630da5de63f7 (diff) | |
download | git-bug-466b5183c371b4ac7f905e33c4f8f36ddb7db9ff.tar.gz |
Merge pull request #446 from MichaelMure/bug-fts
bug full text search
Diffstat (limited to 'commands')
-rw-r--r-- | commands/ls.go | 78 |
1 files changed, 50 insertions, 28 deletions
diff --git a/commands/ls.go b/commands/ls.go index fa653378..f6d654b1 100644 --- a/commands/ls.go +++ b/commands/ls.go @@ -17,13 +17,16 @@ import ( ) type lsOptions struct { - query query.Query - - statusQuery []string - noQuery []string - sortBy string - sortDirection string - outputFormat string + statusQuery []string + authorQuery []string + participantQuery []string + actorQuery []string + labelQuery []string + titleQuery []string + noQuery []string + sortBy string + sortDirection string + outputFormat string } func newLsCommand() *cobra.Command { @@ -35,12 +38,18 @@ func newLsCommand() *cobra.Command { Short: "List bugs.", Long: `Display a summary of each bugs. -You can pass an additional query to filter and order the list. This query can be expressed either with a simple query language or with flags.`, +You can pass an additional query to filter and order the list. This query can be expressed either with a simple query language, flags, a natural language full text search, or a combination of the aforementioned.`, Example: `List open bugs sorted by last edition with a query: git bug ls status:open sort:edit-desc List closed bugs sorted by creation with flags: git bug ls --status closed --by creation + +Do a full text search of all bugs: +git bug ls "foo bar" baz + +Use queries, flags, and full text search: +git bug ls status:open --by creation "foo bar" baz `, PreRunE: loadBackend(env), PostRunE: closeBackend(env), @@ -54,15 +63,15 @@ git bug ls --status closed --by creation flags.StringSliceVarP(&options.statusQuery, "status", "s", nil, "Filter by status. Valid values are [open,closed]") - flags.StringSliceVarP(&options.query.Author, "author", "a", nil, + flags.StringSliceVarP(&options.authorQuery, "author", "a", nil, "Filter by author") - flags.StringSliceVarP(&options.query.Participant, "participant", "p", nil, + flags.StringSliceVarP(&options.participantQuery, "participant", "p", nil, "Filter by participant") - flags.StringSliceVarP(&options.query.Actor, "actor", "A", nil, + flags.StringSliceVarP(&options.actorQuery, "actor", "A", nil, "Filter by actor") - flags.StringSliceVarP(&options.query.Label, "label", "l", nil, + flags.StringSliceVarP(&options.labelQuery, "label", "l", nil, "Filter by label") - flags.StringSliceVarP(&options.query.Title, "title", "t", nil, + flags.StringSliceVarP(&options.titleQuery, "title", "t", nil, "Filter by title") flags.StringSliceVarP(&options.noQuery, "no", "n", nil, "Filter by absence of something. Valid values are [label]") @@ -81,17 +90,24 @@ func runLs(env *Env, opts lsOptions, args []string) error { var err error if len(args) >= 1 { - q, err = query.Parse(strings.Join(args, " ")) - - if err != nil { - return err + // either the shell or cobra remove the quotes, we need them back for the parsing + for i, arg := range args { + if strings.Contains(arg, " ") { + args[i] = fmt.Sprintf("\"%s\"", arg) + } } - } else { - err = completeQuery(&opts) + assembled := strings.Join(args, " ") + q, err = query.Parse(assembled) if err != nil { return err } - q = &opts.query + } else { + q = query.NewQuery() + } + + err = completeQuery(q, opts) + if err != nil { + return err } allIds := env.backend.QueryBugs(q) @@ -308,19 +324,25 @@ func lsOrgmodeFormatter(env *Env, bugExcerpts []*cache.BugExcerpt) error { } // Finish the command flags transformation into the query.Query -func completeQuery(opts *lsOptions) error { +func completeQuery(q *query.Query, opts lsOptions) error { for _, str := range opts.statusQuery { status, err := bug.StatusFromString(str) if err != nil { return err } - opts.query.Status = append(opts.query.Status, status) + q.Status = append(q.Status, status) } + q.Author = append(q.Author, opts.authorQuery...) + q.Participant = append(q.Participant, opts.participantQuery...) + q.Actor = append(q.Actor, opts.actorQuery...) + q.Label = append(q.Label, opts.labelQuery...) + q.Title = append(q.Title, opts.titleQuery...) + for _, no := range opts.noQuery { switch no { case "label": - opts.query.NoLabel = true + q.NoLabel = true default: return fmt.Errorf("unknown \"no\" filter %s", no) } @@ -328,20 +350,20 @@ func completeQuery(opts *lsOptions) error { switch opts.sortBy { case "id": - opts.query.OrderBy = query.OrderById + q.OrderBy = query.OrderById case "creation": - opts.query.OrderBy = query.OrderByCreation + q.OrderBy = query.OrderByCreation case "edit": - opts.query.OrderBy = query.OrderByEdit + q.OrderBy = query.OrderByEdit default: return fmt.Errorf("unknown sort flag %s", opts.sortBy) } switch opts.sortDirection { case "asc": - opts.query.OrderDirection = query.OrderAscending + q.OrderDirection = query.OrderAscending case "desc": - opts.query.OrderDirection = query.OrderDescending + q.OrderDirection = query.OrderDescending default: return fmt.Errorf("unknown sort direction %s", opts.sortDirection) } |