-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtag.go
53 lines (43 loc) · 1.02 KB
/
tag.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
49
50
51
52
53
package main
import (
"bufio"
"fmt"
"github.com/codegangsta/cli"
"github.com/evoL/gif/image"
"github.com/evoL/gif/store"
"os"
"regexp"
"strings"
)
func TagInterface(s *store.Store, img *image.Image) error {
fmt.Println("How would you like to tag this image? (Enter new tags separated by commas)")
if len(img.Tags) > 0 {
fmt.Println("Current tags:", strings.Join(img.Tags, ", "))
}
fmt.Print("=> ")
bio := bufio.NewReader(os.Stdin)
tagList, _, _ := bio.ReadLine()
return s.UpdateTags(img, regexp.MustCompile(`,\s*`).Split(string(tagList[:]), -1))
}
func TagCommand(c *cli.Context) {
s := getStore()
defer s.Close()
if !c.Args().Present() {
cli.ShowCommandHelp(c, "tag")
os.Exit(1)
}
filter := listFilter(c)
images, err := s.List(filter)
if err != nil {
fmt.Println("Error while fetching: " + err.Error())
os.Exit(1)
}
for _, image := range images {
image.Print()
err = TagInterface(s, &image)
if err != nil {
fmt.Println("Error while updating tags: " + err.Error())
os.Exit(1)
}
}
}