-
Notifications
You must be signed in to change notification settings - Fork 18
/
runstatus_service_show.go
73 lines (59 loc) · 1.78 KB
/
runstatus_service_show.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
package cmd
import (
"fmt"
"strings"
"github.com/exoscale/egoscale"
"github.com/spf13/cobra"
)
type runstatusServiceShowOutput struct {
ID int `json:"id"`
Name string `json:"name"`
State string `json:"state"`
}
func (o *runstatusServiceShowOutput) Type() string { return "Service" }
func (o *runstatusServiceShowOutput) toJSON() { outputJSON(o) }
func (o *runstatusServiceShowOutput) toText() { outputText(o) }
func (o *runstatusServiceShowOutput) toTable() { outputTable(o) }
func init() {
runstatusServiceCmd.AddCommand(&cobra.Command{
Use: "show [PAGE] SERVICE-NAME",
Short: "Show a service details",
Long: fmt.Sprintf(`This command shows a runstat.us page details.
Supported output template annotations: %s`,
strings.Join(outputterTemplateAnnotations(&runstatusServiceShowOutput{}), ", ")),
Aliases: gShowAlias,
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
return cmd.Usage()
}
page := gCurrentAccount.DefaultRunstatusPage
service := args[0]
if gCurrentAccount.DefaultRunstatusPage == "" && len(args) == 1 {
return fmt.Errorf("No default runstat.us page is set.\n"+
"Please specify a page in parameter or add it to your configuration file %s",
gConfigFilePath)
}
if len(args) > 1 {
page = args[0]
service = args[1]
}
return output(runstatusShowService(page, service))
},
})
}
func runstatusShowService(p, s string) (outputter, error) {
page, err := csRunstatus.GetRunstatusPage(gContext, egoscale.RunstatusPage{Subdomain: p})
if err != nil {
return nil, err
}
service, err := getServiceByName(*page, s)
if err != nil {
return nil, err
}
out := runstatusServiceShowOutput{
ID: service.ID,
Name: service.Name,
State: service.State,
}
return &out, nil
}