-
Notifications
You must be signed in to change notification settings - Fork 20
/
runstatus_list.go
61 lines (49 loc) · 1.2 KB
/
runstatus_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
package cmd
import (
"os"
"github.com/exoscale/cli/table"
"github.com/exoscale/egoscale"
"github.com/spf13/cobra"
)
// runstatusListCmd represents the list command
var runstatusListCmd = &cobra.Command{
Use: "list [page name]+",
Short: "List runstat.us pages",
Aliases: gListAlias,
RunE: func(cmd *cobra.Command, args []string) error {
pages, err := runstatusAllPages(args)
if err != nil {
return err
}
table := table.NewTable(os.Stdout)
table.SetHeader([]string{"Page Name", "Public URL"})
for _, page := range pages {
table.Append([]string{page.Subdomain, page.PublicURL})
}
table.Render()
return nil
},
}
func runstatusAllPages(args []string) ([]egoscale.RunstatusPage, error) {
pages := []egoscale.RunstatusPage{}
if len(args) == 0 {
ps, err := csRunstatus.ListRunstatusPages(gContext)
if err != nil {
return nil, err
}
for i := range ps {
pages = append(pages, ps[i])
}
}
for _, arg := range args {
page, err := csRunstatus.GetRunstatusPage(gContext, egoscale.RunstatusPage{Subdomain: arg})
if err != nil {
return nil, err
}
pages = append(pages, *page)
}
return pages, nil
}
func init() {
runstatusCmd.AddCommand(runstatusListCmd)
}