Skip to content

Commit abbf3bd

Browse files
committed
releasve: v0.48.1
1 parent 74dbf63 commit abbf3bd

File tree

5 files changed

+34
-14
lines changed

5 files changed

+34
-14
lines changed

CHANGELOG.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
## [Unreleased]
1313

14+
## [v0.48.1] - 2024-02-16
15+
16+
### Fixed
17+
18+
- match how strings are compared when using `allow-name-for-id` and filtering on interactive mode.
19+
1420
## [v0.48.0] - 2024-02-16
1521

1622
### Added
@@ -1142,7 +1148,8 @@ time entry.
11421148
- Golang CLI using [cobra](https://github.com/spf13/cobra)
11431149
- Makefile to help setup actions
11441150

1145-
[Unreleased]: https://github.com/lucassabreu/clockify-cli/compare/v0.48.0...HEAD
1151+
[Unreleased]: https://github.com/lucassabreu/clockify-cli/compare/v0.48.1...HEAD
1152+
[v0.48.1]: https://github.com/lucassabreu/clockify-cli/releases/tag/v0.48.1
11461153
[v0.48.0]: https://github.com/lucassabreu/clockify-cli/releases/tag/v0.48.0
11471154
[v0.47.0]: https://github.com/lucassabreu/clockify-cli/releases/tag/v0.47.0
11481155
[v0.46.0]: https://github.com/lucassabreu/clockify-cli/releases/tag/v0.46.0

pkg/cmd/time-entry/in/in_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ func TestNewCmdIn_ShouldLookupProject_WithAndWithoutClient(t *testing.T) {
232232
},
233233
{
234234
name: "project and client's name",
235-
args: []string{"-s=08:00", "-p", "second me"},
235+
args: []string{"-s=08:00", "-p", "sec me"},
236236
param: api.CreateTimeEntryParam{
237237
Workspace: w.ID,
238238
Start: defaultStart,
@@ -241,7 +241,7 @@ func TestNewCmdIn_ShouldLookupProject_WithAndWithoutClient(t *testing.T) {
241241
},
242242
{
243243
name: "project and client's name (other)",
244-
args: []string{"-s=08:00", "-p=second clockify"},
244+
args: []string{"-s=08:00", "-p", "sec cloc"},
245245
param: api.CreateTimeEntryParam{
246246
Workspace: w.ID,
247247
Start: defaultStart,

pkg/search/find.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,13 @@ func findByName(
2626
return r, err
2727
}
2828

29+
isSimilar := strhlp.IsSimilar(name)
2930
for _, e := range l {
3031
if strings.ToLower(e.GetID()) == name {
3132
return e.GetID(), nil
3233
}
3334

34-
if strings.Contains(strhlp.Normalize(e.GetName()), name) {
35+
if isSimilar(e.GetName()) {
3536
return e.GetID(), nil
3637
}
3738
}

pkg/ui/ui.go

+1-10
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ package ui
33
import (
44
"fmt"
55
"io"
6-
"regexp"
76
"strconv"
8-
"strings"
97
"time"
108

119
"github.com/AlecAivazis/survey/v2"
@@ -78,14 +76,7 @@ func (u *ui) SetPageSize(p uint) UI {
7876
}
7977

8078
func selectFilter(filter, value string, _ int) bool {
81-
// skipcq: GO-C4007
82-
filter = regexp.MustCompile(`[\]\^\\\,\.\(\)\-]+`).
83-
ReplaceAllString(strhlp.Normalize(filter), " ")
84-
filter = regexp.MustCompile(`\s+`).ReplaceAllString(filter, " ")
85-
filter = strings.ReplaceAll(filter, " ", ".*")
86-
filter = strings.ReplaceAll(filter, "*", ".*")
87-
88-
return regexp.MustCompile(filter).MatchString(strhlp.Normalize(value))
79+
return strhlp.IsSimilar(filter)(value)
8980
}
9081

9182
func askString(p survey.Prompt, options ...survey.AskOpt) (string, error) {

strhlp/strhlp.go

+21
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package strhlp
22

33
import (
4+
"regexp"
45
"strings"
56
"unicode"
67

@@ -97,3 +98,23 @@ func PadSpace(s string, size int) string {
9798
}
9899
return s
99100
}
101+
102+
// IsSimilar will convert the string into a regex and return a function the
103+
// checks if a second string is similar to it.
104+
//
105+
// Both strings will normalized before mathing and any space on the filter
106+
// string will be taken as .* on a regex
107+
func IsSimilar(filter string) func(string) bool {
108+
// skipcq: GO-C4007
109+
filter = regexp.MustCompile(`[\]\^\\\,\.\(\)\-]+`).
110+
ReplaceAllString(Normalize(filter), " ")
111+
filter = regexp.MustCompile(`\s+`).ReplaceAllString(filter, " ")
112+
filter = strings.ReplaceAll(filter, " ", ".*")
113+
filter = strings.ReplaceAll(filter, "*", ".*")
114+
115+
r := regexp.MustCompile(filter)
116+
117+
return func(s string) bool {
118+
return r.MatchString(Normalize(s))
119+
}
120+
}

0 commit comments

Comments
 (0)