mirror of
https://github.com/tickstep/aliyunpan.git
synced 2025-01-23 14:32:14 +08:00
add wildchar path match method
This commit is contained in:
parent
077d18f471
commit
4173889120
@ -429,7 +429,7 @@ func RunAlbumAddFile(albumName string, filePathList []string, filterOption Album
|
||||
return
|
||||
}
|
||||
|
||||
paths, err := matchPathByShellPattern(activeUser.ActiveDriveId, filePathList...)
|
||||
paths, err := makePathAbsolute(activeUser.ActiveDriveId, filePathList...)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
|
@ -255,7 +255,7 @@ func RunDownload(paths []string, options *DownloadOptions) {
|
||||
}
|
||||
}
|
||||
|
||||
paths, err := matchPathByShellPattern(options.DriveId, paths...)
|
||||
paths, err := makePathAbsolute(options.DriveId, paths...)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
|
@ -81,7 +81,7 @@ func RunLocateUrl(driveId string, paths []string, saveFilePath string) {
|
||||
activeUser.PanClient().ClearCache()
|
||||
defer activeUser.PanClient().DisableCache()
|
||||
|
||||
paths, err := matchPathByShellPattern(driveId, paths...)
|
||||
paths, err := makePathAbsolute(driveId, paths...)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
|
@ -14,6 +14,7 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/tickstep/aliyunpan-api/aliyunpan"
|
||||
"github.com/tickstep/aliyunpan/internal/config"
|
||||
@ -49,7 +50,52 @@ func GetFileInfoByPaths(paths ...string) (fileInfoList []*aliyunpan.FileEntity,
|
||||
return
|
||||
}
|
||||
|
||||
func matchPathByShellPattern(driveId string, patterns ...string) (panpaths []string, err error) {
|
||||
// RunTestShellPattern 执行测试通配符
|
||||
func RunTestShellPattern(driveId string, pattern string) {
|
||||
acUser := GetActiveUser()
|
||||
files, err := acUser.PanClient().MatchPathByShellPattern(driveId, GetActiveUser().PathJoin(driveId, pattern))
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
for _, f := range *files {
|
||||
fmt.Printf("%s\n", f.Path)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// matchPathByShellPatternOnce 通配符匹配唯一结果,如果有多条则报错
|
||||
func matchPathByShellPatternOnce(driveId string, pattern *string) (*aliyunpan.FileEntity, error) {
|
||||
acUser := GetActiveUser()
|
||||
files, err := acUser.PanClient().MatchPathByShellPattern(driveId, GetActiveUser().PathJoin(driveId, *pattern))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
switch files.ItemCount() {
|
||||
case 0:
|
||||
return nil, errors.New("未匹配到路径, 请检测通配符")
|
||||
case 1:
|
||||
return files.Item(0), nil
|
||||
default:
|
||||
return nil, errors.New("多条通配符匹配结果")
|
||||
}
|
||||
}
|
||||
|
||||
// matchPathByShellPattern 通配符匹配路径,允许返回多个匹配结果
|
||||
func matchPathByShellPattern(driveId string, patterns ...string) (files []*aliyunpan.FileEntity, e error) {
|
||||
acUser := GetActiveUser()
|
||||
for k := range patterns {
|
||||
ps, err := acUser.PanClient().MatchPathByShellPattern(driveId, acUser.PathJoin(driveId, patterns[k]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
files = append(files, *ps...)
|
||||
}
|
||||
return files, nil
|
||||
}
|
||||
|
||||
// makePathAbsolute 拼接路径,确定返回路径为绝对路径
|
||||
func makePathAbsolute(driveId string, patterns ...string) (panpaths []string, err error) {
|
||||
acUser := GetActiveUser()
|
||||
for k := range patterns {
|
||||
ps := acUser.PathJoin(driveId, patterns[k])
|
||||
|
Loading…
Reference in New Issue
Block a user