filebrowser/cmd/cmds_add.go
Henrique Dias f3c1c4b5d2 some cleaning
License: MIT
Signed-off-by: Henrique Dias <hacdias@gmail.com>
2019-01-03 14:06:03 +00:00

36 lines
847 B
Go

package cmd
import (
"github.com/spf13/cobra"
)
func init() {
cmdsCmd.AddCommand(cmdsAddCmd)
cmdsAddCmd.Flags().StringP("command", "c", "", "command to add")
cmdsAddCmd.Flags().StringP("event", "e", "", "corresponding event")
cmdsAddCmd.MarkFlagRequired("command")
cmdsAddCmd.MarkFlagRequired("event")
}
var cmdsAddCmd = &cobra.Command{
Use: "add",
Short: "Add a command to run on a specific event",
Long: `Add a command to run on a specific event.`,
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
db := getDB()
defer db.Close()
st := getStore(db)
s, err := st.GetSettings()
checkErr(err)
evt := mustGetString(cmd, "event")
command := mustGetString(cmd, "command")
s.Commands[evt] = append(s.Commands[evt], command)
err = st.SaveSettings(s)
checkErr(err)
printEvents(s.Commands)
},
}