feat: add cmds
This commit is contained in:
50
internal/cmd_channel_list.go
Normal file
50
internal/cmd_channel_list.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package internal
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
|
||||
"exporter/database/telegram_resource/public/model"
|
||||
"exporter/database/telegram_resource/public/table"
|
||||
|
||||
tablePrinter "github.com/jedib0t/go-pretty/v6/table"
|
||||
"github.com/spf13/cobra"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
func ChannelListCmd() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "list",
|
||||
Aliases: []string{"ls"},
|
||||
Short: "list all channels",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return channelListCmd(context.Background())
|
||||
},
|
||||
}
|
||||
return cmd
|
||||
}
|
||||
|
||||
func channelListCmd(ctx context.Context) error {
|
||||
var channels []model.Channels
|
||||
tbl := table.Channels
|
||||
if err := tbl.SELECT(tbl.AllColumns).ORDER_BY(tbl.ID.ASC()).QueryContext(ctx, db, &channels); err != nil {
|
||||
logger.Fatal("failed to get channels", zap.Error(err))
|
||||
}
|
||||
|
||||
t := tablePrinter.NewWriter()
|
||||
t.SetOutputMirror(os.Stdout)
|
||||
t.AppendHeader(tablePrinter.Row{"Channel ID", "Min ID", "Offset", "Export Media", "PK", "Title"})
|
||||
|
||||
for _, ch := range channels {
|
||||
t.AppendRow([]interface{}{
|
||||
ch.UUID,
|
||||
ch.MinID,
|
||||
ch.Offset,
|
||||
ch.ExportMedia,
|
||||
ch.ID,
|
||||
ch.Title,
|
||||
})
|
||||
}
|
||||
t.Render()
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user