Unified deactivate command

This commit is contained in:
Tim Van Baak 2025-03-06 17:12:00 -08:00
parent d5a00b7dc3
commit a0c7d620ad
2 changed files with 19 additions and 32 deletions

View File

@ -10,29 +10,36 @@ import (
)
var itemDeactivateCmd = &cobra.Command{
Use: "deactivate",
Use: "deactivate --source source [--item item]",
Aliases: []string{"deac"},
Short: "Deactivate an item",
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() {
itemCmd.AddCommand(itemDeactivateCmd)
rootCmd.AddCommand(itemDeactivateCmd)
itemDeactivateCmd.Flags().StringP("source", "s", "", "Source of the item")
itemDeactivateCmd.MarkFlagRequired("source")
itemDeactivateCmd.Flags().StringP("item", "i", "", "Item id")
itemDeactivateCmd.MarkFlagRequired("item")
}
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)
@ -40,4 +47,5 @@ func itemDeactivate(source string, item string) {
if active {
fmt.Printf("Deactivated %s/%s\n", source, item)
}
}
}

View File

@ -1,21 +0,0 @@
package cmd
import (
"log"
"github.com/spf13/cobra"
)
var sourceDeactivateCmd = &cobra.Command{
Use: "deactivate",
Short: "Deactivate all items in a source",
Long: `
`,
Run: func(cmd *cobra.Command, args []string) {
log.Fatal("not implemented")
},
}
func init() {
sourceCmd.AddCommand(sourceDeactivateCmd)
}