-
Notifications
You must be signed in to change notification settings - Fork 20
/
runstatus_maintenance_show.go
78 lines (65 loc) · 2.17 KB
/
runstatus_maintenance_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
74
75
76
77
78
package cmd
import (
"fmt"
"time"
"github.com/exoscale/egoscale"
"github.com/spf13/cobra"
)
type runstatusMaintenanceShowOutput struct {
ID int `json:"id"`
Title string `json:"title"`
Description string `json:"description,omitempty"`
State string `json:"state"`
StartDate *time.Time `json:"start_date"`
EndDate *time.Time `json:"end_date"`
AffectedServices []string `json:"affected_services,omitempty"`
}
func (o *runstatusMaintenanceShowOutput) Type() string { return "Maintenance" }
func (o *runstatusMaintenanceShowOutput) toJSON() { outputJSON(o) }
func (o *runstatusMaintenanceShowOutput) toText() { outputText(o) }
func (o *runstatusMaintenanceShowOutput) toTable() { outputTable(o) }
func init() {
runstatusMaintenanceCmd.AddCommand(
&cobra.Command{
Use: "show [PAGE] MAINTENANCE-NAME|ID",
Short: "Show a maintenance details",
Aliases: gShowAlias,
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
return cmd.Usage()
}
page := gCurrentAccount.DefaultRunstatusPage
maintenance := 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]
maintenance = args[1]
}
return output(showRunstatusMaintenance(page, maintenance))
},
})
}
func showRunstatusMaintenance(p, m string) (outputter, error) {
page, err := csRunstatus.GetRunstatusPage(gContext, egoscale.RunstatusPage{Subdomain: p})
if err != nil {
return nil, err
}
maintenance, err := getRunstatusMaintenanceByNameOrID(*page, m)
if err != nil {
return nil, err
}
out := runstatusMaintenanceShowOutput{
ID: maintenance.ID,
Title: maintenance.Title,
Description: maintenance.Description,
State: maintenance.Status,
StartDate: maintenance.StartDate,
EndDate: maintenance.EndDate,
AffectedServices: maintenance.Services,
}
return &out, nil
}