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,34 +10,42 @@ import (
) )
var itemDeactivateCmd = &cobra.Command{ var itemDeactivateCmd = &cobra.Command{
Use: "deactivate", Use: "deactivate --source source [--item item]",
Aliases: []string{"deac"}, Aliases: []string{"deac"},
Short: "Deactivate an item", Short: "Deactivate items",
Long: `Deactivate items, hiding them from feeds and marking them for deletion. Long: `Deactivate items, hiding them from feeds and marking them for deletion.
Deactivation is idempotent.`, Deactivation is idempotent.`,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
itemDeactivate(stringArg(cmd, "source"), stringArg(cmd, "item")) itemDeactivate(stringArg(cmd, "source"), stringArg(cmd, "item"))
}, },
DisableFlagsInUseLine: true,
} }
func init() { func init() {
itemCmd.AddCommand(itemDeactivateCmd) rootCmd.AddCommand(itemDeactivateCmd)
itemDeactivateCmd.Flags().StringP("source", "s", "", "Source of the item") itemDeactivateCmd.Flags().StringP("source", "s", "", "Source of the item")
itemDeactivateCmd.MarkFlagRequired("source") itemDeactivateCmd.MarkFlagRequired("source")
itemDeactivateCmd.Flags().StringP("item", "i", "", "Item id") itemDeactivateCmd.Flags().StringP("item", "i", "", "Item id")
itemDeactivateCmd.MarkFlagRequired("item")
} }
func itemDeactivate(source string, item string) { func itemDeactivate(source string, item string) {
if source == "" {
log.Fatal("error: --source is empty")
}
db := openAndMigrateDb() db := openAndMigrateDb()
active, err := core.DeactivateItem(db, source, item) if item == "" {
if err != nil { log.Fatal("source deactivation is not implemented")
log.Fatalf("Failed to deactivate item: %s", err) } else {
} active, err := core.DeactivateItem(db, source, item)
if active { if err != nil {
fmt.Printf("Deactivated %s/%s\n", source, item) log.Fatalf("Failed to deactivate item: %s", err)
}
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)
}