You've already forked filebrowser
mirror of
https://github.com/filebrowser/filebrowser.git
synced 2025-11-26 14:25:26 +08:00
feat: v2 (#599)
Read https://github.com/filebrowser/filebrowser/pull/575.
This commit is contained in:
35
cmd/cmds_add.go
Normal file
35
cmd/cmds_add.go
Normal file
@@ -0,0 +1,35 @@
|
||||
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 := getStorage(db)
|
||||
s, err := st.Settings.Get()
|
||||
checkErr(err)
|
||||
|
||||
evt := mustGetString(cmd, "event")
|
||||
command := mustGetString(cmd, "command")
|
||||
|
||||
s.Commands[evt] = append(s.Commands[evt], command)
|
||||
err = st.Settings.Save(s)
|
||||
checkErr(err)
|
||||
printEvents(s.Commands)
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user