/
cmd_attrs.go
126 lines (108 loc) · 3.19 KB
/
cmd_attrs.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package main
import (
"flag"
"sort"
"github.com/BurntSushi/ty/fun"
"github.com/BurntSushi/goim/imdb"
"github.com/BurntSushi/goim/tpl"
)
var attrCommands = map[string]string{
"running-times": "show running times (by region) for media",
"release-dates": "show release dates (by region) for media",
"aka-titles": "show AKA titles for media",
"alternate-versions": "show alternate versions for media",
"color-info": "show color info for media",
"mpaa": "show MPAA rating for media",
"sound-mix": "show sound mix information for media",
"taglines": "show taglines for media",
"trivia": "show trivia for media",
"genres": "show genres tags for media",
"goofs": "show goofs for media",
"languages": "show language information for media",
"literature": "show literature references for media",
"locations": "show geography locations for media",
"links": "show links (prequels, sequels, versions) of media",
"plots": "show plot summaries for media",
"quotes": "show quotes for media",
"rank": "show user rank/votes for media",
"credits": "show actor/media credits",
}
func init() {
for name, help := range attrCommands {
commands = append(commands, &command{
name: name,
other: true,
positionalUsage: "query",
shortHelp: help,
flags: flag.NewFlagSet(name, flag.ExitOnError),
run: cmd_attr(name),
})
}
}
func cmd_attr(name string) func(*command) bool {
return func(c *command) bool {
c.assertLeastNArg(1)
db := openDb(c.dbinfo())
defer closeDb(db)
ent, ok := c.oneEntity(db)
if !ok {
return false
}
return c.showAttr(db, ent, name)
}
}
func (c *command) showAttr(db *imdb.DB, ent imdb.Entity, name string) bool {
tpl.SetDB(db)
c.tplExec(c.tpl(name), tpl.Args{E: ent, A: nil})
return true
}
var cmdFull = &command{
name: "full",
other: true,
positionalUsage: "query",
shortHelp: "show exhaustive information about an entity",
help: "",
flags: flag.NewFlagSet("full", flag.ExitOnError),
run: cmd_full,
}
func cmd_full(c *command) bool {
c.assertLeastNArg(1)
db := openDb(c.dbinfo())
defer closeDb(db)
attrs := fun.Keys(attrCommands).([]string)
sort.Sort(sort.StringSlice(attrs))
ent, ok := c.oneEntity(db)
if !ok {
return false
}
for _, attr := range attrs {
if !c.showAttr(db, ent, attr) {
return false
}
}
return true
}
var cmdShort = &command{
name: "short",
other: true,
positionalUsage: "query",
shortHelp: "show selected information about an entity",
help: "",
flags: flag.NewFlagSet("short", flag.ExitOnError),
run: cmd_short,
}
func cmd_short(c *command) bool {
c.assertLeastNArg(1)
db := openDb(c.dbinfo())
defer closeDb(db)
attrs := fun.Keys(attrCommands).([]string)
sort.Sort(sort.StringSlice(attrs))
ent, ok := c.oneEntity(db)
if !ok {
return false
}
tplName := sf("short_%s", ent.Type().String())
tpl.SetDB(db)
c.tplExec(c.tpl(tplName), tpl.Args{E: ent, A: nil})
return true
}