-
Notifications
You must be signed in to change notification settings - Fork 3
/
inbox.go
75 lines (63 loc) · 1.39 KB
/
inbox.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
package commander
import (
"context"
"time"
"github.com/c-bata/go-prompt"
"github.com/dustin/go-humanize"
"github.com/gogo/protobuf/types"
"github.com/olekukonko/tablewriter"
"github.com/aphistic/softcopy/internal/pkg/consts"
"github.com/aphistic/softcopy/pkg/proto"
)
type cmdInbox struct {
w Writer
client scproto.SoftcopyClient
}
func newCmdInbox(w Writer, client scproto.SoftcopyClient) *cmdInbox {
return &cmdInbox{
w: w,
client: client,
}
}
func (c *cmdInbox) SubCommands() map[string]ParserCmd {
return map[string]ParserCmd{}
}
func (c *cmdInbox) Description() string {
return "Show documents in the Inbox"
}
func (c *cmdInbox) Suggestions(d prompt.Document) []prompt.Suggest {
return []prompt.Suggest{}
}
func (c *cmdInbox) Execute(s string) error {
res, err := c.client.FindFilesWithTags(context.Background(), &scproto.FindFilesWithTagsRequest{
TagNames: []string{
consts.TagUnfiled,
},
})
if err != nil {
return err
}
t := tablewriter.NewWriter(c.w)
t.SetBorder(false)
t.SetHeader([]string{
"ID",
"Filename",
"Date",
"Size",
})
for _, file := range res.Files {
docDate, err := types.TimestampFromProto(file.DocumentDate)
if err != nil {
continue
}
docDate = docDate.Local()
t.Append([]string{
file.Id,
file.Filename,
docDate.Format(time.RFC1123),
humanize.Bytes(file.GetContentSize()),
})
}
t.Render()
return nil
}