53 lines
1.1 KiB
Go
53 lines
1.1 KiB
Go
package cmd
|
|
|
|
import (
|
|
"log"
|
|
|
|
"github.com/Jaculabilis/intake/core"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var actionEditCmd = &cobra.Command{
|
|
Use: "edit",
|
|
Short: "Edit an action on a source",
|
|
Long: `Edit an action on a source.
|
|
`,
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
actionEdit(getArgv(cmd, args))
|
|
},
|
|
}
|
|
|
|
var actionEditSource string
|
|
var actionEditAction string
|
|
|
|
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 {
|
|
log.Fatalf("error: %v", err)
|
|
}
|
|
|
|
log.Printf("Updated action %s on source %s", actionEditAction, actionEditSource)
|
|
}
|