mirror of
https://github.com/tickstep/aliyunpan.git
synced 2025-01-23 14:32:14 +08:00
cd command support wildcard patterns
This commit is contained in:
parent
4173889120
commit
a15f704672
@ -15,6 +15,7 @@ package command
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/tickstep/aliyunpan-api/aliyunpan"
|
||||
"github.com/tickstep/aliyunpan/cmder"
|
||||
"github.com/tickstep/aliyunpan/internal/config"
|
||||
"github.com/urfave/cli"
|
||||
@ -33,6 +34,9 @@ func CmdCd() cli.Command {
|
||||
切换 /我的资源 工作目录:
|
||||
aliyunpan cd /我的资源
|
||||
|
||||
切换 /我的资源 工作目录,使用通配符:
|
||||
aliyunpan cd /我的*
|
||||
|
||||
切换上级目录:
|
||||
aliyunpan cd ..
|
||||
|
||||
@ -90,24 +94,41 @@ func RunChangeDirectory(driveId, targetPath string) {
|
||||
user := config.Config.ActiveUser()
|
||||
targetPath = user.PathJoin(driveId, targetPath)
|
||||
|
||||
targetPathInfo, err := user.PanClient().FileInfoByPath(driveId, targetPath)
|
||||
//targetPathInfo, err := user.PanClient().FileInfoByPath(driveId, targetPath)
|
||||
files, err := matchPathByShellPattern(driveId, targetPath)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
var targetPathInfo *aliyunpan.FileEntity
|
||||
if len(files) == 1 {
|
||||
targetPathInfo = files[0]
|
||||
} else {
|
||||
for _, f := range files {
|
||||
if f.IsFolder() {
|
||||
targetPathInfo = f
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if targetPathInfo == nil {
|
||||
fmt.Println("路径不存在")
|
||||
return
|
||||
}
|
||||
|
||||
if !targetPathInfo.IsFolder() {
|
||||
fmt.Printf("错误: %s 不是一个目录 (文件夹)\n", targetPath)
|
||||
fmt.Printf("错误: %s 不是一个目录 (文件夹)\n", targetPathInfo.Path)
|
||||
return
|
||||
}
|
||||
|
||||
if user.IsFileDriveActive() {
|
||||
user.Workdir = targetPath
|
||||
user.Workdir = targetPathInfo.Path
|
||||
user.WorkdirFileEntity = *targetPathInfo
|
||||
} else if user.IsAlbumDriveActive() {
|
||||
user.AlbumWorkdir = targetPath
|
||||
user.AlbumWorkdir = targetPathInfo.Path
|
||||
user.AlbumWorkdirFileEntity = *targetPathInfo
|
||||
}
|
||||
|
||||
fmt.Printf("改变工作目录: %s\n", targetPath)
|
||||
fmt.Printf("改变工作目录: %s\n", targetPathInfo.Path)
|
||||
}
|
||||
|
@ -65,9 +65,9 @@ func RunTestShellPattern(driveId string, pattern string) {
|
||||
}
|
||||
|
||||
// matchPathByShellPatternOnce 通配符匹配唯一结果,如果有多条则报错
|
||||
func matchPathByShellPatternOnce(driveId string, pattern *string) (*aliyunpan.FileEntity, error) {
|
||||
func matchPathByShellPatternOnce(driveId string, pattern string) (*aliyunpan.FileEntity, error) {
|
||||
acUser := GetActiveUser()
|
||||
files, err := acUser.PanClient().MatchPathByShellPattern(driveId, GetActiveUser().PathJoin(driveId, *pattern))
|
||||
files, err := acUser.PanClient().MatchPathByShellPattern(driveId, GetActiveUser().PathJoin(driveId, pattern))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user