forked from PagerDuty/go-pagerduty
/
main.go
123 lines (103 loc) · 4.26 KB
/
main.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package main
import (
"fmt"
"github.com/mitchellh/cli"
"os"
)
const (
version = "0.0.0"
)
func loadCommands() map[string]cli.CommandFactory {
return map[string]cli.CommandFactory{
"ability list": AbilityListCommand,
"ability test": AbilityTestCommand,
"addon list": AddonListCommand,
"addon install": AddonInstallCommand,
"addon show": AddonShowCommand,
"addon delete": AddonDeleteCommand,
"addon update": AddonUpdateCommand,
"escalation-policy list": EscalationPolicyListCommand,
"escalation-policy create": EscalationPolicyCreateCommand,
"escalation-policy delete": EscalationPolicyDeleteCommand,
"escalation-policy show": EscalationPolicyShowCommand,
"escalation-policy update": EscalationPolicyUpdateCommand,
"incident list": IncidentListCommand,
"incident manage": IncidentManageCommand,
"incident show": IncidentShowCommand,
"incident note list": IncidentNoteListCommand,
"incident note create": IncidentNoteCreateCommand,
"incident snooze": IncidentSnoozeCommand,
"log-entry list": LogEntryListCommand,
"log-entry show": LogEntryShowCommand,
"maintenance-window list": MaintenanceWindowListCommand,
"maintenance-window create": MaintenanceWindowCreateCommand,
"maintenance-window delete": MaintenanceWindowDeleteCommand,
"maintenance-window show": MaintenanceWindowShowCommand,
"maintenance-window update": MaintenanceWindowUpdateCommand,
"notification list": NotificationListCommand,
"oncall list": OncallListCommand,
"schedule list": ScheduleListCommand,
"schedule create": ScheduleCreateCommand,
"schedule preview": SchedulePreviewCommand,
"schedule delete": ScheduleDeleteCommand,
"schedule show": ScheduleShowCommand,
"schedule update": ScheduleUpdateCommand,
"schedule override list": ScheduleOverrideListCommand,
"schedule override create": ScheduleOverrideCreateCommand,
"schedule override delete": ScheduleOverrideDeleteCommand,
"schedule oncall list": ScheduleOncallListCommand,
"service list": ServiceListCommand,
"service create": ServiceCreateCommand,
"service delete": ServiceDeleteCommand,
"service show": ServiceShowCommand,
"service update": ServiceUpdateCommand,
"service integration create": ServiceIntegrationCreateCommand,
"service integration show": ServiceIntegrationShowCommand,
"service integration update": ServiceIntegrationUpdateCommand,
"team list": TeamListCommand,
"team create": TeamShowCommand,
"team delete": TeamDeleteCommand,
"team show": TeamShowCommand,
"team update": TeamUpdateCommand,
"team remove escalation-policy": TeamRemoveEscalationPolicyCommand,
"team add escalation-policy": TeamAddEscalationPolicyCommand,
"team add user": TeamAddUserCommand,
"user list": UserListCommand,
"user create": UserCreateCommand,
"user delete": UserDeleteCommand,
"user show": UserShowCommand,
"user update": UserUpdateCommand,
"user contact-method list": UserContactMethodListCommand,
"user contact-method create": UserContactMethodCreateCommand,
"user contact-method delete": UserContactMethodDeleteCommand,
"user contact-method show": UserContactMethodShowCommand,
"user contact-method update": UserContactMethodUpdateCommand,
"user notification-rule list": UserNotificationRuleListCommand,
"user notification-rule create": UserNotificationRuleCreateCommand,
"user notification-rule delete": UserNotificationRuleDeleteCommand,
"user notification-rule show": UserNotificationRuleShowCommand,
"user notification-rule update": UserNotificationRuleUpdateCommand,
}
}
func main() {
os.Exit(invokeCLI(os.Args[1:]))
}
func invokeCLI(args []string) int {
for _, arg := range args {
if arg == "-v" || arg == "--version" {
fmt.Println(version)
return 0
}
}
cli := &cli.CLI{
Args: args,
Commands: loadCommands(),
HelpFunc: cli.BasicHelpFunc("pd"),
}
exitCode, err := cli.Run()
if err != nil {
fmt.Fprintf(os.Stderr, "Error executing CLI: %s\n", err.Error())
return 1
}
return exitCode
}