func main() { app.Boot() if !app.STARTDAEMON { os.Exit(0) } saveChange := make(chan bool) saveCol := model.GetSaveCollection() saveFileWatcher := app.Watcher{ ModTimes: make(map[string]time.Time, 0), ModFiles: make(map[string]int, 0), } go saveFileWatcher.ObserveFile(model.GetSaveLocal(), saveChange) fileWatchers := make([]app.Watcher, len(saveCol.Saves)) for i, _ := range fileWatchers { fileWatchers[i] = app.Watcher{ ModTimes: make(map[string]time.Time, 0), ModFiles: make(map[string]int, 0), Dir: saveCol.Saves[i].Location, Root: saveCol.Saves[i].Name, } go fileWatchers[i].ObserveDir() } for { if <-saveChange { fmt.Println("Please restart the deamon if you want to commit the changes") } } }
func RegisterCommands() []cli.Command { return []cli.Command{ { Name: "add", Aliases: nil, Usage: "Adds a new directory/file to be watched", Action: func(c *cli.Context) { name := c.Args().First() path := c.Args().Get(1) save := model.NewSave(name, path) if save != nil { save.Save() } }, }, { Name: "list", Aliases: []string{"ls"}, Usage: "Lists regitered directories", Action: func(c *cli.Context) { col := model.GetSaveCollection() table := clitable.New([]string{"Name", "Path"}) for _, save := range col.Saves { table.AddRow(map[string]interface{}{"Name": save.Name, "Path": save.Location}) } table.Print() }, }, { Name: "remove", Aliases: []string{"rm"}, Usage: "Removes a registered directory", Action: func(c *cli.Context) { col := model.GetSaveCollection() name := c.Args().First() save, id := col.Where(name) if save != nil { col.Remove(id) } else { fmt.Println("Failed deleting, unable to find the game: ", name) } }, }, { Name: "start", Aliases: nil, Usage: "Starts gync as a daemon", Action: func(c *cli.Context) { fmt.Println("Starting daemon...") STARTDAEMON = true }, }, } }