Skip to content

Commit

Permalink
修复文档错误; Angey40#5 #64 #113 #124, fix #136, fix #80, fix #41, 初步支持tab …
Browse files Browse the repository at this point in the history
…自动补全路径
  • Loading branch information
iikira committed Apr 28, 2018
1 parent 987b517 commit 7705782
Show file tree
Hide file tree
Showing 5 changed files with 143 additions and 15 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ This project was largely inspired by [GangZhuo/BaiduPCS](https://github.com/Gang
- [特色](#特色)
- [编译/交叉编译 说明](#编译交叉编译-说明)
- [下载/运行 说明](#下载运行-说明)
* [Windows](#Windows)
* [Windows](#windows)
* [Linux / macOS](#linux--macos)
* [Android / iOS](#android--ios)
- [命令列表及说明](#命令列表及说明)
Expand All @@ -29,11 +29,11 @@ This project was largely inspired by [GangZhuo/BaiduPCS](https://github.com/Gang
* [下载文件/目录](#下载文件目录)
* [上传文件/目录](#上传文件目录)
* [手动秒传文件](#手动秒传文件)
* [获取文件的秒传信息](#获取文件的秒传信息)
* [获取本地文件的秒传信息](#获取本地文件的秒传信息)
* [创建目录](#创建目录)
* [删除文件/目录](#删除文件目录)
* [拷贝文件/目录](#拷贝文件目录)
* [移动/重命名文件/目录](#移动/重命名文件目录)
* [移动/重命名文件/目录](#移动重命名文件目录)
* [离线下载](#离线下载)
+ [添加离线下载任务](#添加离线下载任务)
+ [精确查询离线下载任务](#精确查询离线下载任务)
Expand Down Expand Up @@ -92,13 +92,13 @@ cli交互模式下, 光标所在行的前缀应为 `BaiduPCS-Go >`, 如果登录

程序应在 命令提示符 (Command Prompt) 或 PowerShell 中运行, 在 mintty (例如: GitBash) 可能会有显示问题.

也可直接双击程序运行, 具体使用方法请参见 [命令列表及说明](#命令列表及说明)[例子](#举一些例子).
也可直接双击程序运行, 具体使用方法请参见 [命令列表及说明](#命令列表及说明)[初级使用教程](#初级使用教程).

## Linux / macOS

程序应在 终端 (Terminal) 运行.

具体使用方法请参见 [命令列表及说明](#命令列表及说明)[例子](#举一些例子).
具体使用方法请参见 [命令列表及说明](#命令列表及说明)[初级使用教程](#初级使用教程).

## Android / iOS

Expand All @@ -110,7 +110,7 @@ cli交互模式下, 光标所在行的前缀应为 `BaiduPCS-Go >`, 如果登录

苹果iOS, 需要越狱, 在 Cydia 搜索下载并安装 MobileTerminal, 或者其他提供终端环境的软件.

具体使用方法请参见 [命令列表及说明](#命令列表及说明)[例子](#举一些例子).
具体使用方法请参见 [命令列表及说明](#命令列表及说明)[初级使用教程](#初级使用教程).

# 命令列表及说明

Expand Down Expand Up @@ -347,13 +347,13 @@ BaiduPCS-Go rapidupload -length=56276137 -md5=fbe082d80e90f90f0fb1f94adbbcfa7f -
BaiduPCS-Go rapidupload -length=56276137 -md5=fbe082d80e90f90f0fb1f94adbbcfa7f /test
```

## 获取文件的秒传信息
## 获取本地文件的秒传信息
```
BaiduPCS-Go sumfile <本地文件的路径>
BaiduPCS-Go sf <本地文件的路径>
```

获取文件的大小, md5, 前256KB切片的 md5, crc32, 可用于秒传文件.
获取本地文件的大小, md5, 前256KB切片的 md5, crc32, 可用于秒传文件.

#### 例子:
```
Expand Down
2 changes: 1 addition & 1 deletion baidupcs/file_directory.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ func (fl FileDirectoryList) Count() (fileN, directoryN int64) {
// AllFilePaths 返回所有的网盘路径, 包括子目录
func (fl FileDirectoryList) AllFilePaths() (pcspaths []string) {
fN, dN := fl.Count()
pcspaths = make([]string, fN+dN)
pcspaths = make([]string, 0, fN+dN)
for k := range fl {
if fl[k] == nil {
continue
Expand Down
118 changes: 112 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,12 @@ func main() {
---------------------------------------------------
前往 https://github.com/iikira/BaiduPCS-Go 以获取更多帮助信息!
前往 https://github.com/iikira/BaiduPCS-Go/releases 以获取程序更新信息!
---------------------------------------------------`
---------------------------------------------------
交流反馈:
提交Issue: https://github.com/iikira/BaiduPCS-Go/issues
邮箱: [email protected]
QQ群: 178324706`

app.Flags = []cli.Flag{
cli.BoolFlag{
Expand Down Expand Up @@ -133,15 +138,116 @@ func main() {

// tab 自动补全命令
line.State.SetCompleter(func(line string) (s []string) {
cmds := cli.CommandsByName(app.Commands)
var (
lineArgs = args.GetArgs(line)
numArgs = len(lineArgs)
acceptCompleteFileCommands = []string{
"cd", "cp", "download", "ls", "meta", "mkdir", "mv", "rapidupload", "rm", "tree", "upload",
}
closed = strings.LastIndex(line, " ") == len(line)-1
)

for _, cmd := range app.Commands {
for _, name := range cmd.Names() {
if !strings.HasPrefix(name, line) {
continue
}

s = append(s, name+" ")
}
}

switch numArgs {
case 0:
return
case 1:
if !closed {
return
}
default:
thisCmd := app.Command(lineArgs[0])
if thisCmd == nil {
return
}

for k := range cmds {
if !strings.HasPrefix(cmds[k].FullName(), line) {
if !pcsutil.ContainsString(acceptCompleteFileCommands, thisCmd.FullName()) {
return
}
}

var (
activeUser = pcsconfig.Config.ActiveUser()
pcs = pcsconfig.Config.ActiveUserBaiduPCS()
targetPath string
)

if !closed {
targetPath = lineArgs[numArgs-1]
}

var (
targetDir string
isAbs = path.IsAbs(targetPath)
isDir = strings.LastIndex(targetPath, "/") == len(targetPath)-1
)

if isAbs {
targetDir = path.Dir(targetPath)
} else {
targetDir = path.Join(activeUser.Workdir, targetPath)
if !isDir {
targetDir = path.Dir(targetDir)
}
}
filesPtr := pcscache.DirCache.Get(targetDir)

if filesPtr == nil {
files, err := pcs.FilesDirectoriesList(targetDir)
if err != nil {
return
}
pcscache.DirCache.Set(targetDir, &files)
filesPtr = &files
}

for _, file := range *filesPtr {
if file == nil {
continue
}
s = append(s, cmds[k].FullName()+" ")

var (
cleanedPath string
appendLine string
)

if isAbs {
cleanedPath = file.Path
} else {
cleanedPath = strings.TrimPrefix(file.Path, path.Clean(activeUser.Workdir+"/"))
}

// 已经有的情况
if !closed {
if !strings.HasPrefix(cleanedPath, targetPath) {
continue
}
appendLine = strings.Join(append(lineArgs[:len(lineArgs)-1], cleanedPath), " ")
goto handle
}
// 没有的情况
appendLine = strings.Join(append(lineArgs, cleanedPath), " ")
goto handle

handle:
if file.Isdir {
s = append(s, appendLine+"/")
continue
}
s = append(s, appendLine+" ")
continue
}
return s

return
})

for {
Expand Down
10 changes: 10 additions & 0 deletions pcsutil/pcsutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ func init() {
PipeInput = (fileInfo.Mode() & os.ModeNamedPipe) == os.ModeNamedPipe
}

// ContainsString 检测字符串是否在字符串数组里
func ContainsString(ss []string, s string) bool {
for k := range ss {
if strings.Compare(ss[k], s) == 0 {
return true
}
}
return false
}

// GetURLCookieString 返回cookie字串
func GetURLCookieString(urlString string, jar *cookiejar.Jar) string {
url, _ := url.Parse(urlString)
Expand Down
12 changes: 12 additions & 0 deletions requester/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,18 @@ func (h *HTTPClient) Req(method string, urlStr string, post interface{}, header
query.Set(k, value[k])
}
obody = strings.NewReader(query.Encode())
case map[string]interface{}:
query := url.Values{}
for k := range value {
query.Set(k, fmt.Sprint(value[k]))
}
obody = strings.NewReader(query.Encode())
case map[interface{}]interface{}:
query := url.Values{}
for k := range value {
query.Set(fmt.Sprint(k), fmt.Sprint(value[k]))
}
obody = strings.NewReader(query.Encode())
case string:
obody = strings.NewReader(value)
case []byte:
Expand Down

0 comments on commit 7705782

Please sign in to comment.