From fd4fb045c9312b6a7cc03cd10f97c9bf000e1739 Mon Sep 17 00:00:00 2001 From: arrebole Date: Wed, 26 Jul 2023 14:14:53 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8Dwindows=E5=B9=B3?= =?UTF-8?q?=E5=8F=B0=E9=80=9A=E9=85=8D=E7=AC=A6=E5=8C=B9=E9=85=8D=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- commands.go | 6 +++++- utils.go | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/commands.go b/commands.go index 819eb00..d5340bd 100644 --- a/commands.go +++ b/commands.go @@ -370,8 +370,12 @@ func NewUploadCommand() cli.Command { if c.Int("w") > 10 || c.Int("w") < 1 { PrintErrorAndExit("max concurrent threads must between (1 - 10)") } + filenames := c.Args() + if isWindowsGOOS() { + filenames = globFiles(filenames) + } session.Upload( - c.Args(), + filenames, c.String("remote"), c.Int("w"), c.Bool("all"), diff --git a/utils.go b/utils.go index 28d9906..3ead06a 100644 --- a/utils.go +++ b/utils.go @@ -5,6 +5,8 @@ import ( "fmt" "io" "os" + "path/filepath" + "runtime" "strconv" "strings" "time" @@ -140,3 +142,20 @@ func contains(slice []string, item string) bool { } return false } + +func globFiles(patterns []string) []string { + filenames := make([]string, 0) + for _, filename := range patterns { + if strings.Contains(filename, "*") { + matches, err := filepath.Glob(filename) + if err == nil { + filenames = append(filenames, matches...) + } + } + } + return filenames +} + +func isWindowsGOOS() bool { + return runtime.GOOS == "windows" +}