Skip to content

Commit

Permalink
releasve: v0.48.1
Browse files Browse the repository at this point in the history
  • Loading branch information
lucassabreu committed Feb 16, 2024
1 parent 74dbf63 commit abbf3bd
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 14 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [v0.48.1] - 2024-02-16

### Fixed

- match how strings are compared when using `allow-name-for-id` and filtering on interactive mode.

## [v0.48.0] - 2024-02-16

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

[Unreleased]: https://github.com/lucassabreu/clockify-cli/compare/v0.48.0...HEAD
[Unreleased]: https://github.com/lucassabreu/clockify-cli/compare/v0.48.1...HEAD
[v0.48.1]: https://github.com/lucassabreu/clockify-cli/releases/tag/v0.48.1
[v0.48.0]: https://github.com/lucassabreu/clockify-cli/releases/tag/v0.48.0
[v0.47.0]: https://github.com/lucassabreu/clockify-cli/releases/tag/v0.47.0
[v0.46.0]: https://github.com/lucassabreu/clockify-cli/releases/tag/v0.46.0
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/time-entry/in/in_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ func TestNewCmdIn_ShouldLookupProject_WithAndWithoutClient(t *testing.T) {
},
{
name: "project and client's name",
args: []string{"-s=08:00", "-p", "second me"},
args: []string{"-s=08:00", "-p", "sec me"},
param: api.CreateTimeEntryParam{
Workspace: w.ID,
Start: defaultStart,
Expand All @@ -241,7 +241,7 @@ func TestNewCmdIn_ShouldLookupProject_WithAndWithoutClient(t *testing.T) {
},
{
name: "project and client's name (other)",
args: []string{"-s=08:00", "-p=second clockify"},
args: []string{"-s=08:00", "-p", "sec cloc"},
param: api.CreateTimeEntryParam{
Workspace: w.ID,
Start: defaultStart,
Expand Down
3 changes: 2 additions & 1 deletion pkg/search/find.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ func findByName(
return r, err
}

isSimilar := strhlp.IsSimilar(name)
for _, e := range l {
if strings.ToLower(e.GetID()) == name {
return e.GetID(), nil
}

if strings.Contains(strhlp.Normalize(e.GetName()), name) {
if isSimilar(e.GetName()) {
return e.GetID(), nil
}
}
Expand Down
11 changes: 1 addition & 10 deletions pkg/ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ package ui
import (
"fmt"
"io"
"regexp"
"strconv"
"strings"
"time"

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

func selectFilter(filter, value string, _ int) bool {
// skipcq: GO-C4007
filter = regexp.MustCompile(`[\]\^\\\,\.\(\)\-]+`).
ReplaceAllString(strhlp.Normalize(filter), " ")
filter = regexp.MustCompile(`\s+`).ReplaceAllString(filter, " ")
filter = strings.ReplaceAll(filter, " ", ".*")
filter = strings.ReplaceAll(filter, "*", ".*")

return regexp.MustCompile(filter).MatchString(strhlp.Normalize(value))
return strhlp.IsSimilar(filter)(value)
}

func askString(p survey.Prompt, options ...survey.AskOpt) (string, error) {
Expand Down
21 changes: 21 additions & 0 deletions strhlp/strhlp.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package strhlp

import (
"regexp"
"strings"
"unicode"

Expand Down Expand Up @@ -97,3 +98,23 @@ func PadSpace(s string, size int) string {
}
return s
}

// IsSimilar will convert the string into a regex and return a function the
// checks if a second string is similar to it.
//
// Both strings will normalized before mathing and any space on the filter
// string will be taken as .* on a regex
func IsSimilar(filter string) func(string) bool {
// skipcq: GO-C4007
filter = regexp.MustCompile(`[\]\^\\\,\.\(\)\-]+`).
ReplaceAllString(Normalize(filter), " ")
filter = regexp.MustCompile(`\s+`).ReplaceAllString(filter, " ")
filter = strings.ReplaceAll(filter, " ", ".*")
filter = strings.ReplaceAll(filter, "*", ".*")

r := regexp.MustCompile(filter)

return func(s string) bool {
return r.MatchString(Normalize(s))
}
}

0 comments on commit abbf3bd

Please sign in to comment.