Add Commands option
parent
1a4242ca06
commit
66a32dc331
|
@ -143,10 +143,6 @@ func New(database string, base User) (*FileManager, error) {
|
||||||
assets: rice.MustFindBox("./assets/dist"),
|
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
|
// Tries to open a database on the location provided. This
|
||||||
// function will automatically create a new one if it doesn't
|
// function will automatically create a new one if it doesn't
|
||||||
// exist.
|
// exist.
|
||||||
|
@ -167,6 +163,21 @@ func New(database string, base User) (*FileManager, error) {
|
||||||
return nil, err
|
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
|
// Tries to fetch the users from the database and if there are
|
||||||
// any, add them to the current File Manager instance.
|
// any, add them to the current File Manager instance.
|
||||||
var users []User
|
var users []User
|
||||||
|
@ -285,7 +296,7 @@ func (r *Regexp) MatchString(s string) bool {
|
||||||
return r.regexp.MatchString(s)
|
return r.regexp.MatchString(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Runner ...
|
// Runner runs the commands for a certain event type.
|
||||||
func (m FileManager) Runner(event string, path string) error {
|
func (m FileManager) Runner(event string, path string) error {
|
||||||
for _, command := range m.Commands[event] {
|
for _, command := range m.Commands[event] {
|
||||||
args := strings.Split(command, " ")
|
args := strings.Split(command, " ")
|
||||||
|
|
Loading…
Reference in New Issue