47 lines
1.1 KiB
Go
47 lines
1.1 KiB
Go
package cmd
|
|
|
|
import (
|
|
"log"
|
|
|
|
"github.com/Jaculabilis/intake/core"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var channelDeleteCmd = &cobra.Command{
|
|
Use: "remove",
|
|
Aliases: []string{"rm"},
|
|
Short: "Remove a source from a channel",
|
|
Long: `Remove a source from a channel.
|
|
`,
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
channelRemove(stringArg(cmd, "channel"), stringArg(cmd, "source"))
|
|
},
|
|
}
|
|
|
|
func init() {
|
|
channelCmd.AddCommand(channelDeleteCmd)
|
|
|
|
channelDeleteCmd.Flags().StringP("channel", "c", "", "Channel name")
|
|
channelDeleteCmd.MarkFlagRequired("channel")
|
|
|
|
channelDeleteCmd.Flags().StringP("source", "s", "", "Source to add")
|
|
channelDeleteCmd.MarkFlagRequired("source")
|
|
}
|
|
|
|
func channelRemove(channel string, source string) {
|
|
if channel == "" {
|
|
log.Fatal("error: --channel is empty")
|
|
}
|
|
if source == "" {
|
|
log.Fatal("error: --source is empty")
|
|
}
|
|
|
|
db := openAndMigrateDb()
|
|
|
|
if err := core.DeleteSourceFromChannel(db, channel, source); err != nil {
|
|
log.Fatalf("error: failed to remove source from channel: %v", err)
|
|
}
|
|
|
|
log.Printf("Removed source %s from channel %s", source, channel)
|
|
}
|