intake/cmd/actionEdit.go

53 lines
1.2 KiB
Go
Raw 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 actionEditCmd = &cobra.Command{
Use: "edit",
Short: "Edit an action on a source",
Long: `Edit an action on a source.
2025-01-21 16:42:59 +00:00
`,
Run: func(cmd *cobra.Command, args []string) {
actionEdit(getArgv(cmd, args))
2025-01-21 16:42:59 +00:00
},
}
var actionEditSource string
var actionEditAction string
2025-01-21 16:42:59 +00:00
func init() {
actionCmd.AddCommand(actionEditCmd)
actionEditCmd.Flags().StringVarP(&actionEditSource, "source", "s", "", "Source to edit action")
actionEditCmd.MarkFlagRequired("source")
actionEditCmd.Flags().StringVarP(&actionEditAction, "action", "a", "", "Action name")
actionEditCmd.MarkFlagRequired("action")
}
func actionEdit(argv []string) {
if actionEditSource == "" {
log.Fatal("error: --source is empty")
}
if actionEditAction == "" {
log.Fatal("error: --action is empty")
}
if len(argv) == 0 {
log.Fatal("error: no argv provided")
}
db := openAndMigrateDb()
err := core.UpdateAction(db, actionEditSource, actionEditAction, argv)
if err != nil {
2025-01-23 21:22:38 +00:00
log.Fatalf("error: failed to update action: %v", err)
}
log.Printf("Updated action %s on source %s", actionEditAction, actionEditSource)
2025-01-21 16:42:59 +00:00
}