54 lines
1.2 KiB
Go
54 lines
1.2 KiB
Go
package cmd
|
|
|
|
import (
|
|
"database/sql"
|
|
"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 := sql.Open("sqlite3", getDbPath())
|
|
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)
|
|
}
|
|
}
|