From 66a32dc33122db37da7720f975188d0a76536170 Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Sat, 8 Jul 2017 18:08:11 +0100 Subject: [PATCH] Add Commands option --- 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, " ")