Skip to content

Commit

Permalink
fix: 修复windows平台通配符匹配问题
Browse files Browse the repository at this point in the history
  • Loading branch information
arrebole committed Jul 26, 2023
1 parent c98b441 commit fd4fb04
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
6 changes: 5 additions & 1 deletion commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
19 changes: 19 additions & 0 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"fmt"
"io"
"os"
"path/filepath"
"runtime"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -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"
}

0 comments on commit fd4fb04

Please sign in to comment.