51 lines
1.1 KiB
Go
51 lines
1.1 KiB
Go
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
|
|
}
|