File tree 5 files changed +34
-14
lines changed
5 files changed +34
-14
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
11
11
12
12
## [ Unreleased]
13
13
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
+
14
20
## [ v0.48.0] - 2024-02-16
15
21
16
22
### Added
@@ -1142,7 +1148,8 @@ time entry.
1142
1148
- Golang CLI using [ cobra] ( https://github.com/spf13/cobra )
1143
1149
- Makefile to help setup actions
1144
1150
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
1146
1153
[ v0.48.0 ] : https://github.com/lucassabreu/clockify-cli/releases/tag/v0.48.0
1147
1154
[ v0.47.0 ] : https://github.com/lucassabreu/clockify-cli/releases/tag/v0.47.0
1148
1155
[ v0.46.0 ] : https://github.com/lucassabreu/clockify-cli/releases/tag/v0.46.0
Original file line number Diff line number Diff line change @@ -232,7 +232,7 @@ func TestNewCmdIn_ShouldLookupProject_WithAndWithoutClient(t *testing.T) {
232
232
},
233
233
{
234
234
name : "project and client's name" ,
235
- args : []string {"-s=08:00" , "-p" , "second me" },
235
+ args : []string {"-s=08:00" , "-p" , "sec me" },
236
236
param : api.CreateTimeEntryParam {
237
237
Workspace : w .ID ,
238
238
Start : defaultStart ,
@@ -241,7 +241,7 @@ func TestNewCmdIn_ShouldLookupProject_WithAndWithoutClient(t *testing.T) {
241
241
},
242
242
{
243
243
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 " },
245
245
param : api.CreateTimeEntryParam {
246
246
Workspace : w .ID ,
247
247
Start : defaultStart ,
Original file line number Diff line number Diff line change @@ -26,12 +26,13 @@ func findByName(
26
26
return r , err
27
27
}
28
28
29
+ isSimilar := strhlp .IsSimilar (name )
29
30
for _ , e := range l {
30
31
if strings .ToLower (e .GetID ()) == name {
31
32
return e .GetID (), nil
32
33
}
33
34
34
- if strings . Contains ( strhlp . Normalize ( e .GetName ()), name ) {
35
+ if isSimilar ( e .GetName ()) {
35
36
return e .GetID (), nil
36
37
}
37
38
}
Original file line number Diff line number Diff line change @@ -3,9 +3,7 @@ package ui
3
3
import (
4
4
"fmt"
5
5
"io"
6
- "regexp"
7
6
"strconv"
8
- "strings"
9
7
"time"
10
8
11
9
"github.com/AlecAivazis/survey/v2"
@@ -78,14 +76,7 @@ func (u *ui) SetPageSize(p uint) UI {
78
76
}
79
77
80
78
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 )
89
80
}
90
81
91
82
func askString (p survey.Prompt , options ... survey.AskOpt ) (string , error ) {
Original file line number Diff line number Diff line change 1
1
package strhlp
2
2
3
3
import (
4
+ "regexp"
4
5
"strings"
5
6
"unicode"
6
7
@@ -97,3 +98,23 @@ func PadSpace(s string, size int) string {
97
98
}
98
99
return s
99
100
}
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
+ }
You can’t perform that action at this time.
0 commit comments