intake/cmd/itemDeactivate.go

47 lines
1.0 KiB
Go
Raw Permalink 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"
)
2025-01-21 16:42:59 +00:00
var itemDeactivateCmd = &cobra.Command{
2025-01-17 06:02:03 +00:00
Use: "deactivate",
Aliases: []string{"deac"},
2025-01-21 16:42:59 +00:00
Short: "Deactivate an item",
2025-01-17 06:02:03 +00:00
Long: `Deactivate items, hiding them from feeds and marking them for deletion.
Deactivation is idempotent.`,
Run: func(cmd *cobra.Command, args []string) {
2025-01-21 16:42:59 +00:00
itemDeactivate()
2025-01-17 06:02:03 +00:00
},
}
var deacSource string
var deacItem string
func init() {
2025-01-21 16:42:59 +00:00
itemCmd.AddCommand(itemDeactivateCmd)
2025-01-17 06:02:03 +00:00
2025-01-21 16:42:59 +00:00
itemDeactivateCmd.Flags().StringVarP(&deacSource, "source", "s", "", "Source of the item")
itemDeactivateCmd.MarkFlagRequired("source")
itemDeactivateCmd.Flags().StringVarP(&deacItem, "item", "i", "", "Item id")
itemDeactivateCmd.MarkFlagRequired("item")
2025-01-17 06:02:03 +00:00
}
2025-01-21 16:42:59 +00:00
func itemDeactivate() {
2025-01-23 16:36:25 +00:00
db := openAndMigrateDb()
2025-01-17 06:02:03 +00:00
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)
}
}