Skip to content

Commit

Permalink
Support for multiple replaces jacobtomlinson#15
Browse files Browse the repository at this point in the history
  • Loading branch information
pedem committed Aug 27, 2021
1 parent 0dfd077 commit b6eea7a
Showing 1 changed file with 35 additions and 5 deletions.
40 changes: 35 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"io/ioutil"
"log"
"os"
"sort"
"strings"
"path/filepath"
"regexp"
)
Expand Down Expand Up @@ -59,17 +61,45 @@ func main() {
find := os.Getenv("INPUT_FIND")
replace := os.Getenv("INPUT_REPLACE")

reserved := []string{"INCLUDE","EXCLUDE","FIND","REPLACE"}

//INPUT_PREFIX := "INPUT_"

files, filesErr := listFiles(include, exclude)
check(filesErr)

modifiedCount := 0

for _, path := range files {
modified, findAndReplaceErr := findAndReplace(path, find, replace)
check(findAndReplaceErr)
if find!="" && replace!="" {
for _, path := range files {
modified, findAndReplaceErr := findAndReplace(path, find, replace)
check(findAndReplaceErr)

if modified {
modifiedCount++
}
}
}

for _, pair := range os.Environ() {
if strings.Contains(pair,"INPUT_") {
keyValue := strings.SplitN(pair,"=",2)
find := keyValue[0]
replace := keyValue[1]

i := sort.Search(len(reserved), func(i int) bool { return reserved[i] == find })

if modified {
modifiedCount++
if i == len(reserved) {
for _, path := range files {
modified, findAndReplaceErr := findAndReplace(path, find, replace)
check(findAndReplaceErr)

if modified {
modifiedCount++
}
}
}

}
}

Expand Down

0 comments on commit b6eea7a

Please sign in to comment.