chore(cmd): add groups for commands

This commit is contained in:
iyear 2024-06-23 17:10:48 +08:00
parent c63abd1b2f
commit bab1d69efa
7 changed files with 34 additions and 12 deletions

View File

@ -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())

View File

@ -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")

View File

@ -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)

View File

@ -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")

View File

@ -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)
},

View File

@ -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())

View File

@ -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)