-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlists.go
More file actions
74 lines (61 loc) · 1.51 KB
/
lists.go
File metadata and controls
74 lines (61 loc) · 1.51 KB
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
package cmd
import (
"fmt"
"github.com/loops-so/cli/internal/api"
"github.com/loops-so/cli/internal/config"
"github.com/spf13/cobra"
)
func runListsList(cfg *config.Config) ([]api.MailingList, error) {
return newAPIClient(cfg).ListMailingLists()
}
var listsCmd = &cobra.Command{
Use: "lists",
Short: "Manage mailing lists",
}
var listsListCmd = &cobra.Command{
Use: "list",
Short: "List mailing lists",
RunE: func(cmd *cobra.Command, args []string) error {
if err := validatePickFlags(cmd); err != nil {
return err
}
cfg, err := loadConfig()
if err != nil {
return err
}
lists, err := runListsList(cfg)
if err != nil {
return err
}
if isJSONOutput() {
if lists == nil {
lists = []api.MailingList{}
}
return printJSON(cmd.OutOrStdout(), lists)
}
if len(lists) == 0 {
fmt.Fprintln(cmd.OutOrStdout(), "No mailing lists found.")
return nil
}
headers := []string{"ID", "NAME", "DESCRIPTION", "PUBLIC"}
rows := make([][]string, 0, len(lists))
for _, l := range lists {
rows = append(rows, []string{l.ID, l.Name, l.Description, fmt.Sprintf("%v", l.IsPublic)})
}
if isPicking(cmd) {
return runPicker(headers, rows, []pickBinding{
copyColumnBinding("enter", "copy id", "list ID", rows, 0, cmd.OutOrStdout()),
})
}
t := newStyledTable(cmd.OutOrStdout(), headers...)
for _, r := range rows {
t.Row(r...)
}
return t.Render()
},
}
func init() {
addPickFlag(listsListCmd)
listsCmd.AddCommand(listsListCmd)
rootCmd.AddCommand(listsCmd)
}