-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdump.go
51 lines (42 loc) · 1.07 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
package main
import (
"fmt"
"os"
"text/tabwriter"
)
// dumps a given word list, identified by 'name', to stdout
// 'horizontal' - prints 6 words (+ the index) on each line
// 'verbose' - prints also the available meta data befor all words
func doDumpList(name string, horizontal, verbose bool) {
list, exists := internalLists[name]
if !exists {
fmt.Fprintf(os.Stderr, "error: list %q does not exist\n", name)
return
}
w := &tabwriter.Writer{}
w.Init(os.Stdout, 0, 8, 2, ' ', 0)
defer w.Flush()
if verbose {
fmt.Fprintln(w, "Name:", "\t", list.Name)
fmt.Fprintln(w, "Author:", "\t", list.Author)
fmt.Fprintln(w, "Origin:", "\t", list.Origin)
fmt.Fprintln(w, "License:", "\t", list.License)
fmt.Fprintln(w, "---")
}
if horizontal {
for i, word := range linesFromInternalList(name) {
idx := list.Index(i)
fmt.Fprintf(w, "%s %s", idx, word)
if (i+1)%6 == 0 {
fmt.Fprintln(w)
} else {
fmt.Fprint(w, "\t")
}
}
} else {
for i, word := range linesFromInternalList(name) {
idx := list.Index(i)
fmt.Fprintln(w, idx, "\t", word)
}
}
}