github.com/fzfile/BaiduPCS-Go@v0.0.0-20200606205115-4408961cf336/internal/pcscommand/util.go (about) 1 package pcscommand 2 3 import ( 4 "errors" 5 "fmt" 6 ) 7 8 var ( 9 // ErrShellPatternMultiRes 多条通配符匹配结果 10 ErrShellPatternMultiRes = errors.New("多条通配符匹配结果") 11 // ErrShellPatternNoHit 未匹配到路径 12 ErrShellPatternNoHit = errors.New("未匹配到路径, 请检测通配符") 13 ) 14 15 // ListTask 队列状态 (基类) 16 type ListTask struct { 17 ID int // 任务id 18 MaxRetry int // 最大重试次数 19 retry int // 任务失败的重试次数 20 } 21 22 // RunTestShellPattern 执行测试通配符 23 func RunTestShellPattern(pattern string) { 24 pcs := GetBaiduPCS() 25 paths, err := pcs.MatchPathByShellPattern(GetActiveUser().PathJoin(pattern)) 26 if err != nil { 27 fmt.Println(err) 28 return 29 } 30 for k := range paths { 31 fmt.Printf("%s\n", paths[k]) 32 } 33 return 34 } 35 36 func matchPathByShellPatternOnce(pattern *string) error { 37 paths, err := GetBaiduPCS().MatchPathByShellPattern(GetActiveUser().PathJoin(*pattern)) 38 if err != nil { 39 return err 40 } 41 switch len(paths) { 42 case 0: 43 return ErrShellPatternNoHit 44 case 1: 45 *pattern = paths[0] 46 default: 47 return ErrShellPatternMultiRes 48 } 49 50 return nil 51 } 52 53 func matchPathByShellPattern(patterns ...string) (pcspaths []string, err error) { 54 acUser, pcs := GetActiveUser(), GetBaiduPCS() 55 for k := range patterns { 56 ps, err := pcs.MatchPathByShellPattern(acUser.PathJoin(patterns[k])) 57 if err != nil { 58 return nil, err 59 } 60 61 pcspaths = append(pcspaths, ps...) 62 } 63 return pcspaths, nil 64 }