-
Notifications
You must be signed in to change notification settings - Fork 0
/
show.go
48 lines (40 loc) · 997 Bytes
/
show.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package cli
import (
"fmt"
"os"
"strings"
"text/template"
)
func displayTemplate() *template.Template {
return template.Must(
template.New("display").Funcs(templateFuncs).Parse(
strings.TrimSpace(`
{{ .bookmark.URL }}
{{ .bookmark.Title | trimspace}}
{{ .bookmark.Description | trimspace | wordwrap 80 }}
---
Tags: {{ .bookmark.Tags | formatTags false }}
Saved at: {{ .bookmark.SavedAt }}
Context: https://pinboard.in/u:{{ .user }}/before:{{ .bookmark.SavedAt.Unix }}
`) + "\n"))
}
type showCmd struct {
URL string `arg:"" help:"The URL of the bookmark to show."`
}
func (cmd *showCmd) Run(_ *globals) error {
collection, err := loadCollection()
if err != nil {
return err
}
for _, bookmark := range collection.Bookmarks {
if bookmark.URL == cmd.URL {
return displayTemplate().Execute(
os.Stdout,
map[string]interface{}{
"bookmark": bookmark,
"user": collection.User,
})
}
}
return fmt.Errorf("no bookmark found with URL %q", cmd.URL)
}