From f687e7dda9c9df13473fdc1bf43def5326c8afb0 Mon Sep 17 00:00:00 2001 From: kerwin612 Date: Wed, 12 Jul 2023 01:07:24 +0000 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E9=80=9A=E8=BF=87=E7=A9=BA?= =?UTF-8?q?=E6=A0=BC=E6=8B=86=E5=88=86=E5=A4=9A=E6=96=87=E4=BB=B6=EF=BC=88?= =?UTF-8?q?shell=E6=95=B0=E7=BB=84=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 支持files参数的值为在shell中得到的多文件列表(空格拼接) --- main.go | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/main.go b/main.go index e2acaaa..26ac8e7 100644 --- a/main.go +++ b/main.go @@ -8,6 +8,7 @@ import ( "path/filepath" "strconv" "strings" + "regexp" "code.gitea.io/sdk/gitea" gha "github.com/sethvargo/go-githubactions" @@ -107,24 +108,31 @@ func getDirFiles(dir string) ([]string, error) { func getFiles(parentDir, files string) ([]string, error) { var fileList []string - lines := strings.Split(files, "\n") - for _, line := range lines { - line = strings.Trim(line, "'") - line = strings.Trim(line, `"`) - if filepath.IsAbs(line) { - return nil, fmt.Errorf("file path %s is absolute", line) - } - line = filepath.Join(parentDir, line) - matches, err := filepath.Glob(line) - if err != nil { - return nil, err - } - for _, match := range matches { - files, err := getDirFiles(match) + fmt.Printf("the value of the files is: %s\n", files) + reg := regexp.MustCompile(`[^\s"']+|"([^"]*)"|'([^']*)'`) + arr := reg.FindAllString(files, -1) + fmt.Printf("the value after splitting by spaces is: %s\n", strings.Join(arr, ", ")) + for _, str := range arr { + lines := strings.Split(str, "\n") + fmt.Printf("the value after splitting %s by \\n is: %s\n", str, strings.Join(lines, ", ")) + for _, line := range lines { + line = strings.Trim(line, "'") + line = strings.Trim(line, `"`) + if filepath.IsAbs(line) { + return nil, fmt.Errorf("file path %s is absolute", line) + } + line = filepath.Join(parentDir, line) + matches, err := filepath.Glob(line) if err != nil { return nil, err } - fileList = append(fileList, files...) + for _, match := range matches { + files, err := getDirFiles(match) + if err != nil { + return nil, err + } + fileList = append(fileList, files...) + } } } return fileList, nil