From a072d47f5bb9e4920df97eec19be1cb9a0ee989d Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Sat, 8 Jul 2017 18:08:11 +0100 Subject: [PATCH] Add Commands option Former-commit-id: 2fd6defee4579de1aa0b59335f6f98efb269f4df [formerly c42dfd64305c057bb8910983a42418328157a1ee] [formerly dfaf23ff66681114a04bca84c7cb13667b52499e [formerly 66a32dc33122db37da7720f975188d0a76536170]] Former-commit-id: 01fb2c6ec83c134619696cafefbdcdd7ce2b0b61 [formerly 2b42ee8c84ba52c44928bd35a04964718dbd72ee] Former-commit-id: db59756eff3f49cfdf04eb6147e37867963f7090 --- filemanager.go | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/filemanager.go b/filemanager.go index a1aa0a5f..935b0cdd 100644 --- a/filemanager.go +++ b/filemanager.go @@ -143,10 +143,6 @@ func New(database string, base User) (*FileManager, error) { assets: rice.MustFindBox("./assets/dist"), } - m.Commands = map[string][]string{ - "before_save": []string{"cmd /c \"echo %file%\""}, - } - // Tries to open a database on the location provided. This // function will automatically create a new one if it doesn't // exist. @@ -167,6 +163,21 @@ func New(database string, base User) (*FileManager, error) { return nil, err } + // Tries to get the event commands from the database. + // If they don't exist, initialize them. + err = db.Get("config", "commands", &m.Commands) + if err != nil && err == storm.ErrNotFound { + m.Commands = map[string][]string{ + "before_save": []string{}, + "after_save": []string{}, + } + err = db.Set("config", "commands", m.Commands) + } + + if err != nil { + return nil, err + } + // Tries to fetch the users from the database and if there are // any, add them to the current File Manager instance. var users []User @@ -285,7 +296,7 @@ func (r *Regexp) MatchString(s string) bool { return r.regexp.MatchString(s) } -// Runner ... +// Runner runs the commands for a certain event type. func (m FileManager) Runner(event string, path string) error { for _, command := range m.Commands[event] { args := strings.Split(command, " ")