Skip to content

Commit

Permalink
Add a refresh command
Browse files Browse the repository at this point in the history
Forces data to reload
  • Loading branch information
jason0x43 committed May 5, 2017
1 parent 4f05f78 commit e928b50
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ func main() {
DailyCommand{},
HourlyCommand{},
OptionsCommand{},
RefreshCommand{},
}

workflow.Run(commands)
Expand Down
37 changes: 37 additions & 0 deletions refresh.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package main

import (
"time"

"github.com/jason0x43/go-alfred"
)

// RefreshCommand forces data to refresh
type RefreshCommand struct{}

// About returns information about a command
func (c RefreshCommand) About() alfred.CommandDef {
return alfred.CommandDef{
Keyword: "refresh",
Description: "Force forecast data to be re-downloaded",
IsEnabled: true,
Arg: &alfred.ItemArg{
Keyword: "refresh",
},
}
}

// Items returns the items for the command
func (c RefreshCommand) Items(arg, data string) (items []alfred.Item, err error) {
dlog.Printf("Running RefreshCommand")

cache.Time = time.Time{}
if err = alfred.SaveJSON(cacheFile, &cache); err == nil {
items = append(items, alfred.Item{
Title: "Refreshed!",
Subtitle: "Data will be reloaded on the next forecast",
})
}

return
}

0 comments on commit e928b50

Please sign in to comment.