From dd71331ac5d0c207b44163ec20e42c589cea0352 Mon Sep 17 00:00:00 2001 From: iyear Date: Wed, 29 Mar 2023 18:20:23 +0800 Subject: [PATCH] refactor(cmd): create cmd in functions --- cmd/archive.go | 44 +++++++++++++++++ cmd/archive/backup.go | 26 ---------- cmd/archive/recover.go | 20 -------- cmd/chat.go | 87 +++++++++++++++++++++++++++++++++ cmd/chat/chat.go | 14 ------ cmd/chat/export.go | 62 ----------------------- cmd/chat/ls.go | 15 ------ cmd/dl.go | 67 +++++++++++++++++++++++++ cmd/dl/dl.go | 65 ------------------------ cmd/login.go | 36 ++++++++++++++ cmd/login/login.go | 34 ------------- cmd/root.go | 77 +++++++++++++---------------- cmd/up.go | 27 ++++++++++ cmd/up/up.go | 25 ---------- cmd/version.go | 36 ++++++++++++++ cmd/{version => }/version.tmpl | 0 cmd/version/version.go | 31 ------------ docs/command/tdl.md | 4 +- docs/command/tdl_chat_export.md | 11 +++-- docs/command/tdl_download.md | 42 ++++++++++++++++ docs/command/tdl_upload.md | 33 +++++++++++++ main.go | 8 ++- 22 files changed, 421 insertions(+), 343 deletions(-) create mode 100644 cmd/archive.go delete mode 100644 cmd/archive/backup.go delete mode 100644 cmd/archive/recover.go create mode 100644 cmd/chat.go delete mode 100644 cmd/chat/chat.go delete mode 100644 cmd/chat/export.go delete mode 100644 cmd/chat/ls.go create mode 100644 cmd/dl.go delete mode 100644 cmd/dl/dl.go create mode 100644 cmd/login.go delete mode 100644 cmd/login/login.go create mode 100644 cmd/up.go delete mode 100644 cmd/up/up.go create mode 100644 cmd/version.go rename cmd/{version => }/version.tmpl (100%) delete mode 100644 cmd/version/version.go create mode 100644 docs/command/tdl_download.md create mode 100644 docs/command/tdl_upload.md diff --git a/cmd/archive.go b/cmd/archive.go new file mode 100644 index 0000000..1b57fa6 --- /dev/null +++ b/cmd/archive.go @@ -0,0 +1,44 @@ +package cmd + +import ( + "fmt" + "github.com/iyear/tdl/app/archive" + "github.com/spf13/cobra" + "time" +) + +func NewBackup() *cobra.Command { + var dst string + + cmd := &cobra.Command{ + Use: "backup", + Short: "Backup your data", + RunE: func(cmd *cobra.Command, args []string) error { + if dst == "" { + dst = fmt.Sprintf("tdl-backup-%s.zip", time.Now().Format("2006-01-02-15_04_05")) + } + + return archive.Backup(cmd.Context(), dst) + }, + } + + cmd.Flags().StringVarP(&dst, "dst", "d", "", "destination file path. Default: tdl-backup-