Add file lua value
This commit is contained in:
5
main.go
5
main.go
@@ -107,6 +107,9 @@ func main() {
|
||||
startTime := time.Now()
|
||||
var fileMutex sync.Mutex
|
||||
|
||||
// This aggregation is great but what if one modification replaces the whole entire file?
|
||||
// Shit......
|
||||
// TODO: Add "Isolate" field to modifications which makes them run alone
|
||||
for file, commands := range associations {
|
||||
workers <- struct{}{}
|
||||
wg.Add(1)
|
||||
@@ -129,7 +132,7 @@ func main() {
|
||||
modifications := []utils.ReplaceCommand{}
|
||||
for _, command := range commands {
|
||||
logger.Info("Processing file %q with command %q", file, command.Regex)
|
||||
commands, err := processor.ProcessRegex(fileDataStr, command)
|
||||
commands, err := processor.ProcessRegex(fileDataStr, command, file)
|
||||
if err != nil {
|
||||
logger.Error("Failed to process file %q with command %q: %v", file, command.Regex, err)
|
||||
return
|
||||
|
@@ -21,7 +21,9 @@ type CaptureGroup struct {
|
||||
}
|
||||
|
||||
// ProcessContent applies regex replacement with Lua processing
|
||||
func ProcessRegex(content string, command utils.ModifyCommand) ([]utils.ReplaceCommand, error) {
|
||||
// The filename here exists ONLY so we can pass it to the lua environment
|
||||
// It's not used for anything else
|
||||
func ProcessRegex(content string, command utils.ModifyCommand, filename string) ([]utils.ReplaceCommand, error) {
|
||||
var commands []utils.ReplaceCommand
|
||||
logger.Trace("Processing regex: %q", command.Regex)
|
||||
|
||||
@@ -79,6 +81,7 @@ func ProcessRegex(content string, command utils.ModifyCommand) ([]utils.ReplaceC
|
||||
logger.Error("Error creating Lua state: %v", err)
|
||||
return commands, fmt.Errorf("error creating Lua state: %v", err)
|
||||
}
|
||||
L.SetGlobal("file", lua.LString(filename))
|
||||
// Hmm... Maybe we don't want to defer this..
|
||||
// Maybe we want to close them every iteration
|
||||
// We'll leave it as is for now
|
||||
@@ -205,7 +208,7 @@ func ProcessRegex(content string, command utils.ModifyCommand) ([]utils.ReplaceC
|
||||
|
||||
for _, capture := range captureGroups {
|
||||
if capture.Value == capture.Updated {
|
||||
logger.Info("Capture group unchanged: %s", capture.Value)
|
||||
logger.Info("Capture group unchanged: %s", LimitString(capture.Value, 50))
|
||||
continue
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user