Extract normalizeLabels to internal/util/strings.go
- Created internal/util/strings.go with NormalizeLabels function - Added comprehensive tests in internal/util/strings_test.go - Updated internal/rpc/server_issues_epics.go to use util.NormalizeLabels - Updated cmd/bd/list.go and cmd/bd/ready.go to use util.NormalizeLabels - Updated cmd/bd/list_test.go to use util.NormalizeLabels - Removed duplicate implementations - All tests pass Fixes bd-fb95094c.6 Amp-Thread-ID: https://ampcode.com/threads/T-edb3c286-cd60-4231-94cd-edaf75d84a3d Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
@@ -14,26 +14,9 @@ import (
|
||||
"github.com/steveyegge/beads/internal/rpc"
|
||||
"github.com/steveyegge/beads/internal/storage"
|
||||
"github.com/steveyegge/beads/internal/types"
|
||||
"github.com/steveyegge/beads/internal/util"
|
||||
)
|
||||
|
||||
// normalizeLabels trims whitespace, removes empty strings, and deduplicates labels
|
||||
func normalizeLabels(ss []string) []string {
|
||||
seen := make(map[string]struct{})
|
||||
out := make([]string, 0, len(ss))
|
||||
for _, s := range ss {
|
||||
s = strings.TrimSpace(s)
|
||||
if s == "" {
|
||||
continue
|
||||
}
|
||||
if _, ok := seen[s]; ok {
|
||||
continue
|
||||
}
|
||||
seen[s] = struct{}{}
|
||||
out = append(out, s)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// parseTimeFlag parses time strings in multiple formats
|
||||
func parseTimeFlag(s string) (time.Time, error) {
|
||||
formats := []string{
|
||||
@@ -91,8 +74,8 @@ var listCmd = &cobra.Command{
|
||||
// Use global jsonOutput set by PersistentPreRun
|
||||
|
||||
// Normalize labels: trim, dedupe, remove empty
|
||||
labels = normalizeLabels(labels)
|
||||
labelsAny = normalizeLabels(labelsAny)
|
||||
labels = util.NormalizeLabels(labels)
|
||||
labelsAny = util.NormalizeLabels(labelsAny)
|
||||
|
||||
filter := types.IssueFilter{
|
||||
Limit: limit,
|
||||
@@ -123,7 +106,7 @@ var listCmd = &cobra.Command{
|
||||
filter.TitleSearch = titleSearch
|
||||
}
|
||||
if idFilter != "" {
|
||||
ids := normalizeLabels(strings.Split(idFilter, ","))
|
||||
ids := util.NormalizeLabels(strings.Split(idFilter, ","))
|
||||
if len(ids) > 0 {
|
||||
filter.IDs = ids
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user