2025-01-21 16:42:59 +00:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
|
2025-01-23 16:22:50 +00:00
|
|
|
"github.com/Jaculabilis/intake/core"
|
2025-01-21 16:42:59 +00:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
var actionDeleteCmd = &cobra.Command{
|
2025-01-23 16:22:50 +00:00
|
|
|
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) {
|
2025-01-23 16:22:50 +00:00
|
|
|
actionDelete()
|
2025-01-21 16:42:59 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2025-01-23 16:22:50 +00:00
|
|
|
var actionDeleteSource string
|
|
|
|
var actionDeleteAction string
|
|
|
|
|
2025-01-21 16:42:59 +00:00
|
|
|
func init() {
|
|
|
|
actionCmd.AddCommand(actionDeleteCmd)
|
2025-01-23 16:22:50 +00:00
|
|
|
|
|
|
|
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)
|
2025-01-23 16:22:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
log.Printf("Deleted action %s from source %s", actionDeleteAction, actionDeleteSource)
|
2025-01-21 16:42:59 +00:00
|
|
|
}
|