Skip to content

Commit

Permalink
feat: moved
Browse files Browse the repository at this point in the history
  • Loading branch information
kevincobain2000 committed Dec 10, 2024
1 parent 4c79ae8 commit 0ebc717
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 30 deletions.
31 changes: 1 addition & 30 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"log/slog"
"os"
"regexp"
"sync"

"github.com/jasonlvhit/gocron"
Expand All @@ -29,7 +28,7 @@ func main() {
validate()

if f.Test {
testIt()
pkg.TestIt(f.FilePath, f.Match)
return
}

Expand Down Expand Up @@ -221,34 +220,6 @@ func notify(result *pkg.ScanResult) {
}
}

func testIt() {
fps, err := pkg.FilesByPattern(f.FilePath)
if err != nil {
slog.Error("Error finding files", "error", err.Error())
}
slog.Info("Files found", "count", len(fps))
for _, filePath := range fps {
slog.Info("Found file", "filePath", filePath)
}
str := pkg.ReadFromPipeInput()
if str == "" {
slog.Error("No input found")
slog.Info("Usage echo 'test123' | go-watch-logs --match=123 -test")
return
}
str = str[:len(str)-1] // strip new line
re, err := regexp.Compile(f.Match)
if err != nil {
slog.Error("Error compiling regex", "error", err.Error())
return
}
if re.Match([]byte(str)) {
slog.Info("Matched", "Match Regex", f.Match, "input", str, "Match Found", re.FindString(str))
} else {
slog.Warn("Not matched", "Match", f.Match, "str", str)
}
}

func flags() {
flag.StringVar(&f.FilePath, "file-path", "", "full path to the log file")
flag.StringVar(&f.FilePath, "f", "", "(short for --file-path) full path to the log file")
Expand Down
33 changes: 33 additions & 0 deletions pkg/testit.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package pkg

import (
"log/slog"
"regexp"
)

func TestIt(filepath string, match string) {
fps, err := FilesByPattern(filepath)
if err != nil {
slog.Error("Error finding files", "error", err.Error())
}
slog.Info("Files found", "count", len(fps))
for _, filePath := range fps {
slog.Info("Found file", "filePath", filePath)
}
str := ReadFromPipeInput()
if str == "" {
slog.Error("No input found, see --help for usage")
return
}
str = str[:len(str)-1] // strip new line
re, err := regexp.Compile(match)
if err != nil {
slog.Error("Error compiling regex", "error", err.Error())
return
}
if re.Match([]byte(str)) {
slog.Info("Matched", "Match Regex", match, "input", str, "Match Found", re.FindString(str))
} else {
slog.Warn("Not matched", "Match", match, "str", str)
}
}

0 comments on commit 0ebc717

Please sign in to comment.