-
-
Notifications
You must be signed in to change notification settings - Fork 72
/
channels.go
37 lines (31 loc) · 833 Bytes
/
channels.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
package types
import (
"fmt"
"io"
"os"
"text/tabwriter"
"github.com/slack-go/slack"
"github.com/rusq/slackdump/v2/internal/structures"
)
// Channels keeps slice of channels.
type Channels []slack.Channel
// ToText outputs Channels to w in text format.
func (cs Channels) ToText(w io.Writer, ui structures.UserIndex) (err error) {
const strFormat = "%s\t%s\t%s\t%s\n"
writer := tabwriter.NewWriter(w, 0, 0, 2, ' ', 0)
defer writer.Flush()
fmt.Fprintf(writer, strFormat, "ID", "Arch", "Saved", "What")
for i, ch := range cs {
who := ui.ChannelName(&ch)
archived := "-"
if cs[i].IsArchived || ui.IsDeleted(ch.User) {
archived = "arch"
}
saved := "-"
if _, err := os.Stat(ch.ID + ".json"); err == nil {
saved = "saved"
}
fmt.Fprintf(writer, strFormat, ch.ID, archived, saved, who)
}
return nil
}