50 lines
1.1 KiB
Go
50 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(stringArg(cmd, "source"), stringArg(cmd, "action"), getArgv(cmd, args))
|
|
},
|
|
}
|
|
|
|
func init() {
|
|
actionCmd.AddCommand(actionEditCmd)
|
|
|
|
actionEditCmd.Flags().StringP("source", "s", "", "Source to edit action")
|
|
actionEditCmd.MarkFlagRequired("source")
|
|
|
|
actionEditCmd.Flags().StringP("action", "a", "", "Action name")
|
|
actionEditCmd.MarkFlagRequired("action")
|
|
}
|
|
|
|
func actionEdit(source string, action string, argv []string) {
|
|
if source == "" {
|
|
log.Fatal("error: --source is empty")
|
|
}
|
|
if action == "" {
|
|
log.Fatal("error: --action is empty")
|
|
}
|
|
if len(argv) == 0 {
|
|
log.Fatal("error: no argv provided")
|
|
}
|
|
|
|
db := openAndMigrateDb()
|
|
|
|
err := core.SetAction(db, source, action, argv)
|
|
if err != nil {
|
|
log.Fatalf("error: failed to update action: %v", err)
|
|
}
|
|
|
|
log.Printf("Updated action %s on source %s", action, source)
|
|
}
|