Skip to content

Commit

Permalink
Make edit command update updateAt field in cache
Browse files Browse the repository at this point in the history
  • Loading branch information
babarot committed Jan 24, 2020
1 parent aa19680 commit fbf001f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
4 changes: 3 additions & 1 deletion cmd/edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ func (c *editCmd) run(args []string) error {
return err
}

c.UpdateCache(file)

s.Stop()
fmt.Println("Pushed")
fmt.Printf("Pushed: %s\n", file.URL)

return nil
}
15 changes: 15 additions & 0 deletions cmd/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"
"path/filepath"
"strings"
"time"

"github.com/b4b4r07/gist/pkg/gist"
"github.com/b4b4r07/gist/pkg/spin"
Expand Down Expand Up @@ -79,6 +80,20 @@ func (m *meta) init(args []string) error {
return nil
}

func (m *meta) UpdateCache(file gist.File) {
if file.ID == "" {
return
}
var pages []gist.Page
for _, page := range m.cache.Pages {
if page.ID == file.ID {
page.UpdatedAt = time.Now()
}
pages = append(pages, page)
}
m.cache.Save(pages)
}

func head(content string) string {
wrap := func(line string) string {
line = strings.ReplaceAll(line, "\t", " ")
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYU
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
github.com/b4b4r07/go-cli-log v0.0.0-20200124115450-c6d0a1621967 h1:ku6R6/I1sIdcFtAzpP5qfBr5OWn981X0kmOnxIp4Mas=
github.com/b4b4r07/go-cli-log v0.0.0-20200124115450-c6d0a1621967/go.mod h1:banxIPzSdnym1ZZb48bKR3ojP9fW9fuYnM8XZeYlvbA=
github.com/b4b4r07/go-cli-log v0.0.0-20200124120248-8fac4d71de01 h1:rH+k/Ce7EpkeraV5xHl9Dd/PWPsKLX8f7HRfzumoGmA=
github.com/b4b4r07/go-cli-log v0.0.0-20200124120248-8fac4d71de01/go.mod h1:banxIPzSdnym1ZZb48bKR3ojP9fW9fuYnM8XZeYlvbA=
github.com/caarlos0/spin v1.1.1-0.20200123125736-2bc438191c89 h1:9zUBQuu3b8WvC4Um/KUXciqr0kdTw8PKIGzbzm2b2gU=
Expand Down

0 comments on commit fbf001f

Please sign in to comment.