This repository has been archived by the owner on Apr 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
buffer_info.go
75 lines (59 loc) · 1.79 KB
/
buffer_info.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 command
import (
"flag"
"fmt"
"strings"
"github.com/TailorDev/msw/buffer"
"github.com/TailorDev/msw/config"
"github.com/mitchellh/cli"
)
// BufferInfoCommand is a Command that outputs Buffer.com information.
type BufferInfoCommand struct {
UI cli.Ui
Conf config.Config
}
// Run runs the code of the comand.
func (c *BufferInfoCommand) Run(args []string) int {
cmdFlags := flag.NewFlagSet("buffer-info", flag.ContinueOnError)
cmdFlags.Usage = func() { c.UI.Output(c.Help()) }
if err := cmdFlags.Parse(args); err != nil {
return 1
}
if c.Conf.Buffer.AccessToken == "" {
c.UI.Error("You must specify an access token in the configuration file.")
return 1
}
if len(c.Conf.Buffer.ProfileIDs) == 0 {
c.UI.Error("You must specify at least one profile ID in the configuration file.")
return 1
}
cli := buffer.NewClient(c.Conf.Buffer.AccessToken)
for _, id := range c.Conf.Buffer.ProfileIDs {
p, err := cli.GetProfile(id)
if err != nil {
c.UI.Error(fmt.Sprintf("%s", err))
continue
}
c.UI.Output(fmt.Sprintf("\nProfile: %s (%s)", p.FormattedUsername, p.Service))
updates, _ := cli.GetPendingUpdates(id)
c.UI.Output(fmt.Sprintf("Buffer : %d / %d\n", len(updates), c.Conf.Buffer.BufferSize))
c.UI.Output("Scheduled updates:\n")
for _, u := range updates {
c.UI.Output(fmt.Sprintf("%-25s: %s", u.Day, u.Text))
}
}
return 0
}
// Help returns the description of the command.
func (*BufferInfoCommand) Help() string {
helpText := `
Usage: msw buffer info
This command shows information about Buffer.com. You need a configuration
file with Buffer credentials ('~/.msw/msw.yml').
`
return strings.TrimSpace(helpText)
}
// Synopsis returns the short description of the command.
func (*BufferInfoCommand) Synopsis() string {
return "output Buffer.com information"
}