Skip to content

Commit

Permalink
chore(cmd): add groups for commands
Browse files Browse the repository at this point in the history
  • Loading branch information
iyear committed Sep 8, 2024
1 parent c63abd1 commit bab1d69
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 12 deletions.
5 changes: 3 additions & 2 deletions cmd/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
1 change: 1 addition & 0 deletions cmd/dl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
5 changes: 3 additions & 2 deletions cmd/forward.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions cmd/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
15 changes: 9 additions & 6 deletions cmd/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand All @@ -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)
},
Expand All @@ -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)
},
Expand Down
14 changes: 14 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -80,6 +92,8 @@ func New() *cobra.Command {
},
}

cmd.AddGroup(groupAccount, groupTools)

cmd.AddCommand(NewVersion(), NewLogin(), NewDownload(), NewForward(),
NewChat(), NewUpload(), NewBackup(), NewRecover(), NewMigrate(), NewGen())

Expand Down
1 change: 1 addition & 0 deletions cmd/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit bab1d69

Please sign in to comment.