/
list.go
58 lines (46 loc) · 1.07 KB
/
list.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
package main
import (
"fmt"
"gopkg.in/urfave/cli.v1"
"sort"
"strings"
)
func ListCommand() cli.Command {
return cli.Command{
Name: "list",
Usage: "list various stats",
ArgsUsage: "input.json",
Action: ListAction,
Flags: []cli.Flag{
cli.IntFlag{
Name: "count, c",
Value: 50,
Usage: "how much to list",
},
},
}
}
func ListAction(c *cli.Context) {
// Figure out input
if len(c.Args()) < 1 {
cli.ShowCommandHelp(c, c.Command.Name)
return
}
jsonFile := c.Args()[0]
data := FromJSON(GetFileContent(jsonFile))
count := c.Int("count")
threads := data.Threads
if count > len(threads) {
count = len(threads)
}
// Sort by message count
sort.Sort(ByMessage(threads))
// Reverse (top = more)
for i, j := 0, len(threads)-1; i < j; i, j = i+1, j-1 {
threads[i], threads[j] = threads[j], threads[i]
}
threads = threads[:count]
for _, thread := range threads {
fmt.Println(strings.Join(DeleteElementFromSlice(thread.Persons, data.WhoAmI), ", ")+" > Messages:", thread.CountMessages(), "Words:", thread.CountWords())
}
}