From cb61245078a0e8f14e359ed20e0582a695645a08 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Sun, 14 Feb 2021 16:03:51 +0100 Subject: Add ability to search by arbitrary metadata Example: ~/git/git-bug/git-bug ls --metadata github-url=https://github.com/author/myproject/issues/42 or ~/git/git-bug/git-bug ls metadata:github-url:\"https://github.com/author/myproject/issues/42\" Fixes the cmdline part of . --- query/parser.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'query/parser.go') diff --git a/query/parser.go b/query/parser.go index 762a47e5..e820c629 100644 --- a/query/parser.go +++ b/query/parser.go @@ -67,6 +67,21 @@ func Parse(query string) (*Query, error) { default: return nil, fmt.Errorf("unknown qualifier \"%s\"", t.qualifier) } + + case tokenKindKVV: + switch t.qualifier { + case "metadata": + if len(t.subQualifier) == 0 { + return nil, fmt.Errorf("empty value for sub-qualifier \"metadata:%s\"", t.subQualifier) + } + var pair StringPair + pair.Key = t.subQualifier + pair.Value = t.value + q.Metadata = append(q.Metadata, pair) + + default: + return nil, fmt.Errorf("unknown qualifier \"%s:%s\"", t.qualifier, t.subQualifier) + } } } return q, nil -- cgit From fab626a7a663a8fa6ef27848bb63e91af812ab8c Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Sat, 27 Feb 2021 20:31:10 +0100 Subject: query: refactor to reuse the split function for both query and token --- query/parser.go | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'query/parser.go') diff --git a/query/parser.go b/query/parser.go index e820c629..6fd5cd74 100644 --- a/query/parser.go +++ b/query/parser.go @@ -71,13 +71,7 @@ func Parse(query string) (*Query, error) { case tokenKindKVV: switch t.qualifier { case "metadata": - if len(t.subQualifier) == 0 { - return nil, fmt.Errorf("empty value for sub-qualifier \"metadata:%s\"", t.subQualifier) - } - var pair StringPair - pair.Key = t.subQualifier - pair.Value = t.value - q.Metadata = append(q.Metadata, pair) + q.Metadata = append(q.Metadata, StringPair{Key: t.subQualifier, Value: t.value}) default: return nil, fmt.Errorf("unknown qualifier \"%s:%s\"", t.qualifier, t.subQualifier) -- cgit