Skip to content

Commit

Permalink
feat: block salt with the line number
Browse files Browse the repository at this point in the history
  • Loading branch information
costaluu committed Sep 23, 2024
1 parent 81a85d9 commit 37904f5
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "github.com/charmbracelet/lipgloss"
var (
APP_NAME = "flag"
COMMAND = "flag"
VERSION = "v0.0.2"
VERSION = "v0.0.3"
MIN_FEATURE_CHARACTERS = 5
ID_LENGTH = 25
)
Expand Down
31 changes: 29 additions & 2 deletions src/core/blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,29 @@ import (
"github.com/costaluu/flag/utils"
)

func findFirstLineMatch(path string, matchContent string) int {
splitedMatchConent := strings.Split(matchContent, "\n")
data := filesystem.FileRead(path)
splitedData := strings.Split(data, "\n")

for i := 0; i < len(splitedData); i++ {
var found bool = true

for j := 0; j < len(splitedMatchConent) && i + j < len(splitedData); j++ {
if strings.TrimSpace(splitedData[i + j]) != strings.TrimSpace(splitedMatchConent[j]) {
found = false
break;
}
}

if found {
return i + 1
}
}

return -1
}

func ExtractMatchDataFromFile(path string) []types.Match {
delimeterStartRegex, delimeterEndRegex := GetDelimetersFromFileParsedRegex(path)
delimeterStart, delimeterEnd := GetDelimetersFromFile(path)
Expand All @@ -43,9 +66,13 @@ func ExtractMatchDataFromFile(path string) []types.Match {
foundId = true
id = match[3]
} else {
salt := utils.GetCurrentUnixTimestampInMs()
salt := findFirstLineMatch(path, matchContent)

if salt == -1 {
continue
}

id = utils.GenerateId(path, feature, salt)
id = utils.GenerateId(path, feature, fmt.Sprintf("%d", salt))
}

var featureContent string
Expand Down
6 changes: 5 additions & 1 deletion src/core/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,5 +249,9 @@ func Sync() {
}
}

components.FileIterator(arrayFile, runner)
for _, path := range arrayFile {
runner(path)

fmt.Printf("%s %s\n", constants.CheckMark.Render(), path.Path)
}
}

0 comments on commit 37904f5

Please sign in to comment.