mirror of
https://github.com/packwiz/packwiz.git
synced 2025-10-25 09:54:31 +02:00
github: use regexp2 for advanced regex
Signed-off-by: unilock <unilock@fennet.rentals>
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
|
||||
"github.com/dlclark/regexp2"
|
||||
"github.com/packwiz/packwiz/core"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
@@ -120,7 +121,7 @@ func getLatestRelease(slug string, branch string) (Release, error) {
|
||||
}
|
||||
|
||||
func installRelease(repo Repo, release Release, regex string, pack core.Pack) error {
|
||||
expr := regexp.MustCompile(regex)
|
||||
expr := regexp2.MustCompile(regex, 0)
|
||||
|
||||
if len(release.Assets) == 0 {
|
||||
return errors.New("release doesn't have any assets attached")
|
||||
@@ -129,7 +130,8 @@ func installRelease(repo Repo, release Release, regex string, pack core.Pack) er
|
||||
var files []Asset
|
||||
|
||||
for _, v := range release.Assets {
|
||||
if expr.MatchString(v.Name) {
|
||||
bl, _ := expr.MatchString(v.Name)
|
||||
if bl {
|
||||
files = append(files, v)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,9 +3,9 @@ package github
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/dlclark/regexp2"
|
||||
"github.com/mitchellh/mapstructure"
|
||||
"github.com/packwiz/packwiz/core"
|
||||
)
|
||||
@@ -53,7 +53,7 @@ func (u ghUpdater) CheckUpdate(mods []*core.Mod, pack core.Pack) ([]core.UpdateC
|
||||
continue
|
||||
}
|
||||
|
||||
expr := regexp.MustCompile(data.Regex)
|
||||
expr := regexp2.MustCompile(data.Regex, 0)
|
||||
|
||||
if len(newRelease.Assets) == 0 {
|
||||
results[i] = core.UpdateCheck{Error: errors.New("new release doesn't have any assets")}
|
||||
@@ -63,7 +63,8 @@ func (u ghUpdater) CheckUpdate(mods []*core.Mod, pack core.Pack) ([]core.UpdateC
|
||||
var newFiles []Asset
|
||||
|
||||
for _, v := range newRelease.Assets {
|
||||
if expr.MatchString(v.Name) {
|
||||
bl, _ := expr.MatchString(v.Name)
|
||||
if bl {
|
||||
newFiles = append(newFiles, v)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user