From bab1d69efac24bb03ae257deb72fb5701ce5002d Mon Sep 17 00:00:00 2001 From: iyear Date: Sun, 23 Jun 2024 17:10:48 +0800 Subject: [PATCH] chore(cmd): add groups for commands --- cmd/chat.go | 5 +++-- cmd/dl.go | 1 + cmd/forward.go | 5 +++-- cmd/login.go | 5 +++-- cmd/migrate.go | 15 +++++++++------ cmd/root.go | 14 ++++++++++++++ cmd/up.go | 1 + 7 files changed, 34 insertions(+), 12 deletions(-) diff --git a/cmd/chat.go b/cmd/chat.go index 9b11c4e..2cb7e8f 100644 --- a/cmd/chat.go +++ b/cmd/chat.go @@ -21,8 +21,9 @@ var limiter = ratelimit.New(rate.Every(500*time.Millisecond), 2) func NewChat() *cobra.Command { cmd := &cobra.Command{ - Use: "chat", - Short: "A set of chat tools", + Use: "chat", + Short: "A set of chat tools", + GroupID: groupTools.ID, } cmd.AddCommand(NewChatList(), NewChatExport(), NewChatUsers()) diff --git a/cmd/dl.go b/cmd/dl.go index 592180e..e34b40b 100644 --- a/cmd/dl.go +++ b/cmd/dl.go @@ -22,6 +22,7 @@ func NewDownload() *cobra.Command { Use: "download", Aliases: []string{"dl"}, Short: "Download anything from Telegram (protected) chat", + GroupID: groupTools.ID, RunE: func(cmd *cobra.Command, args []string) error { if len(opts.URLs) == 0 && len(opts.Files) == 0 { return fmt.Errorf("no urls or files provided") diff --git a/cmd/forward.go b/cmd/forward.go index cffbb37..e7025e7 100644 --- a/cmd/forward.go +++ b/cmd/forward.go @@ -18,8 +18,9 @@ func NewForward() *cobra.Command { var opts forward.Options cmd := &cobra.Command{ - Use: "forward", - Short: "Forward messages with automatic fallback and message routing", + Use: "forward", + Short: "Forward messages with automatic fallback and message routing", + GroupID: groupTools.ID, RunE: func(cmd *cobra.Command, args []string) error { return tRun(cmd.Context(), func(ctx context.Context, c *telegram.Client, kvd kv.KV) error { return forward.Run(logctx.Named(ctx, "forward"), c, kvd, opts) diff --git a/cmd/login.go b/cmd/login.go index 2ee5d46..b886278 100644 --- a/cmd/login.go +++ b/cmd/login.go @@ -18,8 +18,9 @@ func NewLogin() *cobra.Command { ) cmd := &cobra.Command{ - Use: "login", - Short: "Login to Telegram", + Use: "login", + Short: "Login to Telegram", + GroupID: groupAccount.ID, RunE: func(cmd *cobra.Command, args []string) error { color.Yellow("WARN: If data exists in the namespace, data will be overwritten") diff --git a/cmd/migrate.go b/cmd/migrate.go index 8841f8e..a946f59 100644 --- a/cmd/migrate.go +++ b/cmd/migrate.go @@ -15,8 +15,9 @@ func NewBackup() *cobra.Command { var dst string cmd := &cobra.Command{ - Use: "backup", - Short: "Backup your data", + Use: "backup", + Short: "Backup your data", + GroupID: groupAccount.ID, RunE: func(cmd *cobra.Command, args []string) error { if dst == "" { dst = fmt.Sprintf("%s.backup.tdl", time.Now().Format("2006-01-02-15_04_05")) @@ -35,8 +36,9 @@ func NewRecover() *cobra.Command { var file string cmd := &cobra.Command{ - Use: "recover", - Short: "Recover your data", + Use: "recover", + Short: "Recover your data", + GroupID: groupAccount.ID, RunE: func(cmd *cobra.Command, args []string) error { return migrate.Recover(cmd.Context(), file) }, @@ -57,8 +59,9 @@ func NewMigrate() *cobra.Command { var to map[string]string cmd := &cobra.Command{ - Use: "migrate", - Short: "Migrate your current data to another storage", + Use: "migrate", + Short: "Migrate your current data to another storage", + GroupID: groupAccount.ID, RunE: func(cmd *cobra.Command, args []string) error { return migrate.Migrate(cmd.Context(), to) }, diff --git a/cmd/root.go b/cmd/root.go index 49699ae..d8d7150 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -36,6 +36,18 @@ var ( } ) +// command groups +var ( + groupAccount = &cobra.Group{ + ID: "account", + Title: "Account related", + } + groupTools = &cobra.Group{ + ID: "tools", + Title: "Tools", + } +) + func New() *cobra.Command { cmd := &cobra.Command{ Use: "tdl", @@ -80,6 +92,8 @@ func New() *cobra.Command { }, } + cmd.AddGroup(groupAccount, groupTools) + cmd.AddCommand(NewVersion(), NewLogin(), NewDownload(), NewForward(), NewChat(), NewUpload(), NewBackup(), NewRecover(), NewMigrate(), NewGen()) diff --git a/cmd/up.go b/cmd/up.go index 2e3aa91..eb65be8 100644 --- a/cmd/up.go +++ b/cmd/up.go @@ -18,6 +18,7 @@ func NewUpload() *cobra.Command { Use: "upload", Aliases: []string{"up"}, Short: "Upload anything to Telegram", + GroupID: groupTools.ID, RunE: func(cmd *cobra.Command, args []string) error { return tRun(cmd.Context(), func(ctx context.Context, c *telegram.Client, kvd kv.KV) error { return up.Run(logctx.Named(ctx, "up"), c, kvd, opts)