/
cmd_chat_archive_list.go
104 lines (95 loc) · 2.71 KB
/
cmd_chat_archive_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
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
package client
import (
"fmt"
"slices"
"strings"
"github.com/keybase/cli"
"github.com/keybase/client/go/chatrender"
"github.com/keybase/client/go/libcmdline"
"github.com/keybase/client/go/libkb"
gregor1 "github.com/keybase/client/go/protocol/gregor1"
"github.com/keybase/client/go/protocol/keybase1"
"golang.org/x/net/context"
)
type CmdChatArchiveList struct {
libkb.Contextified
}
func NewCmdChatArchiveListListRunner(g *libkb.GlobalContext) *CmdChatArchiveList {
return &CmdChatArchiveList{
Contextified: libkb.NewContextified(g),
}
}
func newCmdChatArchiveList(cl *libcmdline.CommandLine, g *libkb.GlobalContext) cli.Command {
return cli.Command{
Name: "archive-list",
Usage: "List metadata about chat archive jobs",
Action: func(c *cli.Context) {
cl.ChooseCommand(NewCmdChatArchiveListListRunner(g), "archive-list", c)
cl.SetLogForward(libcmdline.LogForwardNone)
},
}
}
func (c *CmdChatArchiveList) Run() error {
client, err := GetChatLocalClient(c.G())
if err != nil {
return err
}
res, err := client.ArchiveChatList(context.TODO(), keybase1.TLFIdentifyBehavior_CHAT_CLI)
if err != nil {
return err
}
ui := c.G().UI.GetTerminalUI()
ui.Printf("Found %d job(s)\n\n", len(res.Jobs))
for _, job := range res.Jobs {
percent := 100
if job.MessagesTotal > 0 {
percent = int((100 * job.MessagesComplete) / job.MessagesTotal)
}
matchingConvs := ""
if job.Request.Query == nil || (job.Request.Query.Name == nil && job.Request.Query.TopicName == nil && len(job.Request.Query.ConvIDs) == 0) {
matchingConvs = "<all chat>"
} else {
names := make([]string, 0, len(job.MatchingConvs))
for _, conv := range job.MatchingConvs {
name := conv.Name
if len(name) == 0 {
continue
}
if conv.Channel != "" {
name += fmt.Sprintf("#%s", conv.Channel)
}
names = append(names, name)
}
slices.Sort(names)
matchingConvs += strings.Join(names, "\n")
}
ui.Printf(`Job ID: %s
Matching Conversations:
%s
Output Path: %s
Started At: %s (%s)
Status: %s
Progress: %d%% (%d of %d messages archived)
`, job.Request.JobID, matchingConvs, job.Request.OutputPath,
chatrender.FmtTime(gregor1.FromTime(job.StartedAt), chatrender.RenderOptions{UseDateTime: true}),
chatrender.FmtTime(gregor1.FromTime(job.StartedAt), chatrender.RenderOptions{}),
job.Status.String(), percent, job.MessagesComplete, job.MessagesTotal)
if job.Err != "" {
ui.Printf("Err: %s\n", job.Err)
}
ui.Printf("\n")
}
return nil
}
func (c *CmdChatArchiveList) ParseArgv(ctx *cli.Context) (err error) {
if len(ctx.Args()) > 0 {
return fmt.Errorf("no arguments required")
}
return nil
}
func (c *CmdChatArchiveList) GetUsage() libkb.Usage {
return libkb.Usage{
Config: true,
API: true,
}
}