intake/cmd/itemDeactivate.go

52 lines
1.2 KiB
Go

package cmd
import (
"fmt"
"log"
"github.com/Jaculabilis/intake/core"
_ "github.com/mattn/go-sqlite3"
"github.com/spf13/cobra"
)
var itemDeactivateCmd = &cobra.Command{
Use: "deactivate --source source [--item item]",
Aliases: []string{"deac"},
Short: "Deactivate items",
Long: `Deactivate items, hiding them from feeds and marking them for deletion.
Deactivation is idempotent.`,
Run: func(cmd *cobra.Command, args []string) {
itemDeactivate(stringArg(cmd, "source"), stringArg(cmd, "item"))
},
DisableFlagsInUseLine: true,
}
func init() {
rootCmd.AddCommand(itemDeactivateCmd)
itemDeactivateCmd.Flags().StringP("source", "s", "", "Source of the item")
itemDeactivateCmd.MarkFlagRequired("source")
itemDeactivateCmd.Flags().StringP("item", "i", "", "Item id")
}
func itemDeactivate(source string, item string) {
if source == "" {
log.Fatal("error: --source is empty")
}
db := openAndMigrateDb()
if item == "" {
log.Fatal("source deactivation is not implemented")
} else {
active, err := core.DeactivateItem(db, source, item)
if err != nil {
log.Fatalf("Failed to deactivate item: %s", err)
}
if active {
fmt.Printf("Deactivated %s/%s\n", source, item)
}
}
}