2019-01-05 22:44:33 +00:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2019-01-06 13:21:31 +00:00
|
|
|
"strings"
|
|
|
|
|
2019-01-05 22:44:33 +00:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
cmdsCmd.AddCommand(cmdsAddCmd)
|
|
|
|
}
|
|
|
|
|
|
|
|
var cmdsAddCmd = &cobra.Command{
|
2019-01-06 13:21:31 +00:00
|
|
|
Use: "add <event> <command>",
|
2019-01-05 22:44:33 +00:00
|
|
|
Short: "Add a command to run on a specific event",
|
|
|
|
Long: `Add a command to run on a specific event.`,
|
2020-05-31 23:12:36 +00:00
|
|
|
Args: cobra.MinimumNArgs(2), //nolint:mnd
|
2019-01-07 20:24:23 +00:00
|
|
|
Run: python(func(cmd *cobra.Command, args []string, d pythonData) {
|
|
|
|
s, err := d.store.Settings.Get()
|
2019-01-05 22:44:33 +00:00
|
|
|
checkErr(err)
|
2019-01-06 13:21:31 +00:00
|
|
|
command := strings.Join(args[1:], " ")
|
|
|
|
s.Commands[args[0]] = append(s.Commands[args[0]], command)
|
2019-01-07 20:24:23 +00:00
|
|
|
err = d.store.Settings.Save(s)
|
2019-01-05 22:44:33 +00:00
|
|
|
checkErr(err)
|
|
|
|
printEvents(s.Commands)
|
2019-01-07 20:24:23 +00:00
|
|
|
}, pythonConfig{}),
|
2019-01-05 22:44:33 +00:00
|
|
|
}
|