intake/cmd/actionDelete.go

51 lines
1.1 KiB
Go
Raw Permalink Normal View History

2025-01-21 16:42:59 +00:00
package cmd
import (
"log"
"github.com/Jaculabilis/intake/core"
2025-01-21 16:42:59 +00:00
"github.com/spf13/cobra"
)
var actionDeleteCmd = &cobra.Command{
Use: "delete",
Aliases: []string{"rm"},
Short: "Delete an action from a source",
Long: `Delete an action from a source.
2025-01-21 16:42:59 +00:00
`,
Run: func(cmd *cobra.Command, args []string) {
actionDelete()
2025-01-21 16:42:59 +00:00
},
}
var actionDeleteSource string
var actionDeleteAction string
2025-01-21 16:42:59 +00:00
func init() {
actionCmd.AddCommand(actionDeleteCmd)
actionDeleteCmd.Flags().StringVarP(&actionDeleteSource, "source", "s", "", "Source to add action")
actionDeleteCmd.MarkFlagRequired("source")
actionDeleteCmd.Flags().StringVarP(&actionDeleteAction, "action", "a", "", "Action name")
actionDeleteCmd.MarkFlagRequired("action")
}
func actionDelete() {
if actionDeleteSource == "" {
log.Fatal("error: --source is empty")
}
if actionDeleteAction == "" {
log.Fatal("error: --action is empty")
}
db := openAndMigrateDb()
err := core.DeleteAction(db, actionDeleteSource, actionDeleteAction)
if err != nil {
2025-01-23 21:22:38 +00:00
log.Fatalf("error: failed to delete action: %v", err)
}
log.Printf("Deleted action %s from source %s", actionDeleteAction, actionDeleteSource)
2025-01-21 16:42:59 +00:00
}