intake/cmd/deactivate.go

53 lines
1.1 KiB
Go
Raw Normal View History

2025-01-17 06:02:03 +00:00
package cmd
import (
"fmt"
"log"
"github.com/Jaculabilis/intake/core"
_ "github.com/mattn/go-sqlite3"
"github.com/spf13/cobra"
)
var deactivateCmd = &cobra.Command{
Use: "deactivate",
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) {
deactivate()
},
}
var deacSource string
var deacItem string
func init() {
rootCmd.AddCommand(deactivateCmd)
deactivateCmd.Flags().StringVarP(&deacSource, "source", "s", "", "Source of the item")
deactivateCmd.MarkFlagRequired("source")
deactivateCmd.Flags().StringVarP(&deacItem, "item", "i", "", "Item id")
deactivateCmd.MarkFlagRequired("item")
}
func deactivate() {
db, err := core.OpenDb(getDbPath())
2025-01-17 06:02:03 +00:00
if err != nil {
log.Fatalf("Failed to open %s", dbPath)
}
core.InitDatabase(db)
core.MigrateDatabase(db)
active, err := core.DeactivateItem(db, deacSource, deacItem)
if err != nil {
log.Fatalf("Failed to deactivate item: %s", err)
}
if active {
fmt.Printf("Deactivated %s/%s\n", deacSource, deacItem)
}
}