Skip to content

Commit

Permalink
issue_list: Add flag for matching exact terms
Browse files Browse the repository at this point in the history
Gitlab support matching on the exact search terms by enclosing the
search strings in double quotes (as is common for web search engines
as well).

This requires careful quoting or escaping on the command line - for
example '"foo bar"' or "\"foo bar\"" - which is cumbersome; make
this more convenient by adding a dedicated command line flag that
takes care of the quoting.
  • Loading branch information
fmuellner committed Jan 21, 2021
1 parent 7c2c165 commit c59b143
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions cmd/issue_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"log"

"github.com/pkg/errors"
"github.com/rsteube/carapace"
"github.com/spf13/cobra"
gitlab "github.com/xanzy/go-gitlab"
Expand All @@ -12,12 +13,13 @@ import (
)

var (
issueLabels []string
issueMilestone string
issueState string
issueSearch string
issueNumRet int
issueAll bool
issueLabels []string
issueMilestone string
issueState string
issueSearch string
issueNumRet int
issueAll bool
issueExactMatch bool
)

var issueListCmd = &cobra.Command{
Expand Down Expand Up @@ -70,6 +72,13 @@ func issueList(args []string) ([]*gitlab.Issue, error) {
OrderBy: gitlab.String("updated_at"),
}

if issueExactMatch {
if issueSearch == "" {
return nil, errors.New("Exact match requested, but no search terms provided")
}
issueSearch = "\"" + issueSearch + "\""
}

if issueSearch != "" {
opts.Search = &issueSearch
}
Expand Down Expand Up @@ -97,6 +106,9 @@ func init() {
issueListCmd.Flags().StringVar(
&issueMilestone, "milestone", "",
"filter issues by milestone")
issueListCmd.Flags().BoolVarP(
&issueExactMatch, "exact-match", "x", false,
"match on the exact (case-insensitive) search terms")

issueCmd.AddCommand(issueListCmd)
carapace.Gen(issueListCmd).FlagCompletion(carapace.ActionMap{
Expand Down

0 comments on commit c59b143

Please sign in to comment.