intake/cmd/channelList.go

46 lines
863 B
Go
Raw Normal View History

2025-02-01 01:23:41 +00:00
package cmd
import (
"fmt"
"log"
"github.com/Jaculabilis/intake/core"
"github.com/spf13/cobra"
)
var channelListCmd = &cobra.Command{
Use: "list",
Aliases: []string{"ls"},
Short: "List channels",
Long: `List channels.
`,
Run: func(cmd *cobra.Command, args []string) {
channelList(stringArg(cmd, "channel"))
},
}
func init() {
channelCmd.AddCommand(channelListCmd)
channelListCmd.Flags().StringP("channel", "c", "", "List sources in a specific channel")
}
func channelList(channel string) {
db := openAndMigrateDb()
channelSources, err := core.GetSourcesInChannel(db)
if err != nil {
log.Fatalf("error: failed to get sources in channel: %v", err)
}
if channel == "" {
for channel := range channelSources {
fmt.Println(channel)
}
} else {
for _, source := range channelSources[channel] {
fmt.Println(source)
}
}
}