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 actionAddCmd = &cobra.Command{
|
2025-01-23 16:22:50 +00:00
|
|
|
Use: "add [flags] -- argv...",
|
2025-01-21 16:42:59 +00:00
|
|
|
Short: "Add an action to a source",
|
2025-01-23 16:22:50 +00:00
|
|
|
Long: `Add an action to a source.
|
2025-01-21 16:42:59 +00:00
|
|
|
`,
|
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
2025-01-30 15:54:13 +00:00
|
|
|
actionAdd(stringArg(cmd, "source"), stringArg(cmd, "action"), getArgv(cmd, args))
|
2025-01-21 16:42:59 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
actionCmd.AddCommand(actionAddCmd)
|
2025-01-23 16:22:50 +00:00
|
|
|
|
2025-01-30 15:54:13 +00:00
|
|
|
actionAddCmd.Flags().StringP("source", "s", "", "Source to add action")
|
2025-01-23 16:22:50 +00:00
|
|
|
actionAddCmd.MarkFlagRequired("source")
|
|
|
|
|
2025-01-30 15:54:13 +00:00
|
|
|
actionAddCmd.Flags().StringP("action", "a", "", "Action name")
|
2025-01-23 16:22:50 +00:00
|
|
|
actionAddCmd.MarkFlagRequired("action")
|
|
|
|
}
|
|
|
|
|
2025-02-12 17:49:27 +00:00
|
|
|
// TODO: This is a duplicate of `action edit`, the action CLI should be simplified
|
|
|
|
|
2025-01-30 15:54:13 +00:00
|
|
|
func actionAdd(source string, action string, argv []string) {
|
|
|
|
if source == "" {
|
2025-01-23 16:22:50 +00:00
|
|
|
log.Fatal("error: --source is empty")
|
|
|
|
}
|
2025-01-30 15:54:13 +00:00
|
|
|
if action == "" {
|
2025-01-23 16:22:50 +00:00
|
|
|
log.Fatal("error: --action is empty")
|
|
|
|
}
|
|
|
|
if len(argv) == 0 {
|
|
|
|
log.Fatal("error: no argv provided")
|
|
|
|
}
|
|
|
|
|
|
|
|
db := openAndMigrateDb()
|
|
|
|
|
2025-02-12 17:49:27 +00:00
|
|
|
err := core.SetAction(db, source, action, argv)
|
2025-01-23 16:22:50 +00:00
|
|
|
if err != nil {
|
2025-01-23 21:22:38 +00:00
|
|
|
log.Fatalf("error: failed to add action: %v", err)
|
2025-01-23 16:22:50 +00:00
|
|
|
}
|
|
|
|
|
2025-01-30 15:54:13 +00:00
|
|
|
log.Printf("Added action %s to source %s", action, source)
|
2025-01-21 16:42:59 +00:00
|
|
|
}
|