From 15bef9fcc38118dd1267928eab608bd5046f0a95 Mon Sep 17 00:00:00 2001 From: xiaoyaofenfen <1254525673@qq.com> Date: Sat, 20 Aug 2022 16:37:28 +0800 Subject: [PATCH] change index number of table starts as one --- internal/command/album.go | 2 +- internal/command/drive_list.go | 12 ++++++------ internal/command/ls_search.go | 12 ++++++------ internal/command/recycle.go | 8 ++++---- internal/command/rm.go | 8 ++++---- internal/command/share.go | 2 +- internal/command/user_info.go | 4 ++-- internal/config/utils.go | 6 +++--- main.go | 2 +- 9 files changed, 28 insertions(+), 28 deletions(-) diff --git a/internal/command/album.go b/internal/command/album.go index 2530b9b..e641ac4 100644 --- a/internal/command/album.go +++ b/internal/command/album.go @@ -240,7 +240,7 @@ func RunAlbumList() { tb.SetHeader([]string{"#", "ALBUM_ID", "名称", "文件数量", "创建日期", "修改日期"}) tb.SetColumnAlignment([]int{tablewriter.ALIGN_DEFAULT, tablewriter.ALIGN_DEFAULT, tablewriter.ALIGN_LEFT, tablewriter.ALIGN_CENTER, tablewriter.ALIGN_DEFAULT, tablewriter.ALIGN_DEFAULT}) for k, record := range records { - tb.Append([]string{strconv.Itoa(k), record.AlbumId, record.Name, strconv.Itoa(record.FileCount), + tb.Append([]string{strconv.Itoa(k + 1), record.AlbumId, record.Name, strconv.Itoa(record.FileCount), record.CreatedAtStr(), record.UpdatedAtStr()}) } tb.Render() diff --git a/internal/command/drive_list.go b/internal/command/drive_list.go index ae91fb9..cba76ad 100644 --- a/internal/command/drive_list.go +++ b/internal/command/drive_list.go @@ -49,10 +49,10 @@ func CmdDrive() cli.Command { } } -func RunSwitchDriveList(targetDriveId string) { +func RunSwitchDriveList(targetDriveId string) { currentDriveId := config.Config.ActiveUser().ActiveDriveId var activeDriveInfo *config.DriveInfo = nil - driveList,renderStr := getDriveOptionList() + driveList, renderStr := getDriveOptionList() if driveList == nil || len(driveList) == 0 { fmt.Println("切换网盘失败") @@ -71,15 +71,15 @@ func RunSwitchDriveList(targetDriveId string) { return } - if n, err := strconv.Atoi(index); err == nil && n >= 0 && n < len(driveList) { - activeDriveInfo = driveList[n] + if n, err1 := strconv.Atoi(index); err1 == nil && (n-1) >= 0 && (n-1) < len(driveList) { + activeDriveInfo = driveList[n-1] } else { fmt.Printf("切换网盘失败, 请检查 # 值是否正确\n") return } } else { // 直接切换 - for _,driveInfo := range driveList { + for _, driveInfo := range driveList { if driveInfo.DriveId == targetDriveId { activeDriveInfo = driveInfo break @@ -121,7 +121,7 @@ func getDriveOptionList() (config.DriveInfoList, string) { tb.SetHeader([]string{"#", "drive_id", "网盘名称"}) for k, info := range driveList { - tb.Append([]string{strconv.Itoa(k), info.DriveId, info.DriveName}) + tb.Append([]string{strconv.Itoa(k + 1), info.DriveId, info.DriveName}) } tb.Render() return driveList, builder.String() diff --git a/internal/command/ls_search.go b/internal/command/ls_search.go index d355cd3..165287d 100644 --- a/internal/command/ls_search.go +++ b/internal/command/ls_search.go @@ -186,15 +186,15 @@ func renderTable(op int, isTotal bool, path string, files aliyunpan.FileList) { tb.SetColumnAlignment([]int{tablewriter.ALIGN_DEFAULT, tablewriter.ALIGN_RIGHT, tablewriter.ALIGN_LEFT, tablewriter.ALIGN_LEFT, tablewriter.ALIGN_LEFT, tablewriter.ALIGN_LEFT, tablewriter.ALIGN_LEFT, tablewriter.ALIGN_LEFT}) for k, file := range files { if file.IsFolder() { - tb.Append([]string{strconv.Itoa(k), file.FileId, "-", "-", "-", file.CreatedAt, file.UpdatedAt, file.FileName + aliyunpan.PathSeparator}) + tb.Append([]string{strconv.Itoa(k + 1), file.FileId, "-", "-", "-", file.CreatedAt, file.UpdatedAt, file.FileName + aliyunpan.PathSeparator}) continue } switch op { case opLs: - tb.Append([]string{strconv.Itoa(k), file.FileId, converter.ConvertFileSize(file.FileSize, 2), file.ContentHash, strconv.FormatInt(file.FileSize, 10), file.CreatedAt, file.UpdatedAt, file.FileName}) + tb.Append([]string{strconv.Itoa(k + 1), file.FileId, converter.ConvertFileSize(file.FileSize, 2), file.ContentHash, strconv.FormatInt(file.FileSize, 10), file.CreatedAt, file.UpdatedAt, file.FileName}) case opSearch: - tb.Append([]string{strconv.Itoa(k), file.FileId, converter.ConvertFileSize(file.FileSize, 2), file.ContentHash, strconv.FormatInt(file.FileSize, 10), file.CreatedAt, file.UpdatedAt, file.Path}) + tb.Append([]string{strconv.Itoa(k + 1), file.FileId, converter.ConvertFileSize(file.FileSize, 2), file.ContentHash, strconv.FormatInt(file.FileSize, 10), file.CreatedAt, file.UpdatedAt, file.Path}) } } fN, dN = files.Count() @@ -204,15 +204,15 @@ func renderTable(op int, isTotal bool, path string, files aliyunpan.FileList) { tb.SetColumnAlignment([]int{tablewriter.ALIGN_DEFAULT, tablewriter.ALIGN_RIGHT, tablewriter.ALIGN_LEFT, tablewriter.ALIGN_LEFT}) for k, file := range files { if file.IsFolder() { - tb.Append([]string{strconv.Itoa(k), "-", file.UpdatedAt, file.FileName + aliyunpan.PathSeparator}) + tb.Append([]string{strconv.Itoa(k + 1), "-", file.UpdatedAt, file.FileName + aliyunpan.PathSeparator}) continue } switch op { case opLs: - tb.Append([]string{strconv.Itoa(k), converter.ConvertFileSize(file.FileSize, 2), file.UpdatedAt, file.FileName}) + tb.Append([]string{strconv.Itoa(k + 1), converter.ConvertFileSize(file.FileSize, 2), file.UpdatedAt, file.FileName}) case opSearch: - tb.Append([]string{strconv.Itoa(k), converter.ConvertFileSize(file.FileSize, 2), file.UpdatedAt, file.Path}) + tb.Append([]string{strconv.Itoa(k + 1), converter.ConvertFileSize(file.FileSize, 2), file.UpdatedAt, file.Path}) } } fN, dN = files.Count() diff --git a/internal/command/recycle.go b/internal/command/recycle.go index c9dff83..19377a1 100644 --- a/internal/command/recycle.go +++ b/internal/command/recycle.go @@ -150,7 +150,7 @@ func RunRecycleList(driveId string) { fn = fn + "/" fs = "-" } - tb.Append([]string{strconv.Itoa(k), file.FileId, fn, fs, file.CreatedAt, file.UpdatedAt}) + tb.Append([]string{strconv.Itoa(k + 1), file.FileId, fn, fs, file.CreatedAt, file.UpdatedAt}) } tb.Render() @@ -161,7 +161,7 @@ func RunRecycleRestore(driveId string, fidStrList ...string) { panClient := GetActivePanClient() restoreFileList := []*aliyunpan.FileBatchActionParam{} - for _,fid := range fidStrList { + for _, fid := range fidStrList { restoreFileList = append(restoreFileList, &aliyunpan.FileBatchActionParam{ DriveId: driveId, FileId: fid, @@ -190,7 +190,7 @@ func RunRecycleDelete(driveId string, fidStrList ...string) { panClient := GetActivePanClient() deleteFileList := []*aliyunpan.FileBatchActionParam{} - for _,fid := range fidStrList { + for _, fid := range fidStrList { deleteFileList = append(deleteFileList, &aliyunpan.FileBatchActionParam{ DriveId: driveId, FileId: fid, @@ -234,7 +234,7 @@ func RunRecycleClear(driveId string) { // delete deleteFileList := []*aliyunpan.FileBatchActionParam{} - for _,f := range fdl { + for _, f := range fdl { deleteFileList = append(deleteFileList, &aliyunpan.FileBatchActionParam{ DriveId: driveId, FileId: f.FileId, diff --git a/internal/command/rm.go b/internal/command/rm.go index 2bacff7..4e6cfed 100644 --- a/internal/command/rm.go +++ b/internal/command/rm.go @@ -87,8 +87,8 @@ func RunRemove(driveId string, paths ...string) { } fe.Path = absolutePath delFileInfos = append(delFileInfos, &aliyunpan.FileBatchActionParam{ - DriveId:driveId, - FileId:fe.FileId, + DriveId: driveId, + FileId: fe.FileId, }) fileId2FileEntity[fe.FileId] = fe cacheCleanDirs = append(cacheCleanDirs, path.Dir(fe.Path)) @@ -98,7 +98,7 @@ func RunRemove(driveId string, paths ...string) { successDelFileEntity := []*aliyunpan.FileEntity{} fdr, err := activeUser.PanClient().FileDelete(delFileInfos) if fdr != nil { - for _,item := range fdr { + for _, item := range fdr { if !item.Success { failedRmPaths = append(failedRmPaths, fileId2FileEntity[item.FileId].Path) } else { @@ -111,7 +111,7 @@ func RunRemove(driveId string, paths ...string) { tb := cmdtable.NewTable(os.Stdout) tb.SetHeader([]string{"#", "文件/目录"}) for k := range successDelFileEntity { - tb.Append([]string{strconv.Itoa(k), successDelFileEntity[k].Path}) + tb.Append([]string{strconv.Itoa(k + 1), successDelFileEntity[k].Path}) } tb.Render() } diff --git a/internal/command/share.go b/internal/command/share.go index 30c9444..7fdb22f 100644 --- a/internal/command/share.go +++ b/internal/command/share.go @@ -306,7 +306,7 @@ func RunShareList() { } } } - tb.Append([]string{strconv.Itoa(k), record.ShareId, record.ShareUrl, record.SharePwd, + tb.Append([]string{strconv.Itoa(k + 1), record.ShareId, record.ShareUrl, record.SharePwd, record.ShareName, //record.FileIdList[0], et, diff --git a/internal/command/user_info.go b/internal/command/user_info.go index ceecc5c..9a2585f 100644 --- a/internal/command/user_info.go +++ b/internal/command/user_info.go @@ -85,8 +85,8 @@ func CmdSu() cli.Command { return nil } - if n, err := strconv.Atoi(index); err == nil && n >= 0 && n < numLogins { - uid = config.Config.UserList[n].UserId + if n, err1 := strconv.Atoi(index); err1 == nil && (n-1) >= 0 && (n-1) < numLogins { + uid = config.Config.UserList[n-1].UserId } else { fmt.Printf("切换用户失败, 请检查 # 值是否正确\n") return nil diff --git a/internal/config/utils.go b/internal/config/utils.go index 08c3f77..77c58b1 100644 --- a/internal/config/utils.go +++ b/internal/config/utils.go @@ -34,7 +34,7 @@ func (pl *PanUserList) String() string { tb.SetHeader([]string{"#", "uid", "用户名", "昵称"}) for k, userInfo := range *pl { - tb.Append([]string{strconv.Itoa(k), userInfo.UserId, userInfo.AccountName, userInfo.Nickname}) + tb.Append([]string{strconv.Itoa(k + 1), userInfo.UserId, userInfo.AccountName, userInfo.Nickname}) } tb.Render() @@ -95,7 +95,7 @@ func DecryptString(text string) string { if text == "" { return "" } - d, _ := hex.DecodeString(text) + d, _ := hex.DecodeString(text) // use the machine unique id as the key // but in some OS, this key will be changed if you reinstall the OS @@ -120,4 +120,4 @@ func IsFolderExist(pathStr string) bool { return false } return fi.IsDir() -} \ No newline at end of file +} diff --git a/main.go b/main.go index 4710831..b4e8c3a 100644 --- a/main.go +++ b/main.go @@ -504,7 +504,7 @@ func main() { if line == "" { continue } - tb.Append([]string{strconv.Itoa(idx), line}) + tb.Append([]string{strconv.Itoa(idx + 1), line}) idx++ } tb.Render()