2019-01-06 06:44:33 +08:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2019-01-06 21:21:31 +08:00
|
|
|
"strings"
|
|
|
|
|
2019-01-06 06:44:33 +08:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
cmdsCmd.AddCommand(cmdsAddCmd)
|
|
|
|
}
|
|
|
|
|
|
|
|
var cmdsAddCmd = &cobra.Command{
|
2019-01-06 21:21:31 +08:00
|
|
|
Use: "add <event> <command>",
|
2019-01-06 06:44:33 +08:00
|
|
|
Short: "Add a command to run on a specific event",
|
|
|
|
Long: `Add a command to run on a specific event.`,
|
2019-01-06 21:21:31 +08:00
|
|
|
Args: cobra.MinimumNArgs(2),
|
2019-01-06 06:44:33 +08:00
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
|
|
db := getDB()
|
|
|
|
defer db.Close()
|
|
|
|
st := getStorage(db)
|
|
|
|
s, err := st.Settings.Get()
|
|
|
|
checkErr(err)
|
|
|
|
|
2019-01-06 21:21:31 +08:00
|
|
|
command := strings.Join(args[1:], " ")
|
2019-01-06 06:44:33 +08:00
|
|
|
|
2019-01-06 21:21:31 +08:00
|
|
|
s.Commands[args[0]] = append(s.Commands[args[0]], command)
|
2019-01-06 06:44:33 +08:00
|
|
|
err = st.Settings.Save(s)
|
|
|
|
checkErr(err)
|
|
|
|
printEvents(s.Commands)
|
|
|
|
},
|
|
|
|
}
|