-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdump.go
56 lines (50 loc) · 1.19 KB
/
dump.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
package main
import (
"fmt"
log "github.com/sirupsen/logrus"
)
func dumpAll() {
c, err := db.ReadAll()
if err != nil {
panic(err)
}
if len(*c) > 0 {
fmt.Println(" ID │ AlbumId │ PlaylistId │ Title")
fmt.Println("───────────────┼─────────────┼─────────────────┼─────────────────────────────────────────")
} else {
fmt.Println("No cards found in the database...")
}
for _, card := range *c {
title := card.Title
album := card.AlbumIDString()
playlist := card.PlaylistIDString()
if len(title) > 40 {
title = fmt.Sprintf("%.39v…", title)
}
fmt.Printf("%14v │ %11v │ %15v │ %v\n", card.ID, album, playlist, title)
}
}
func dumpCard(cardId string) {
if cardId == "" {
id, err := readSingleCard()
if err != nil {
log.Fatal(err)
}
cardId = id
}
p, err := db.ReadCard(cardId)
if err != nil {
log.Error(err)
return
}
if *dumpInfo {
a, err := p.ToPlayable()
if err != nil {
log.Error(err)
return
}
fmt.Println(a)
} else {
fmt.Println(p)
}
}