-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathexample_test.go
138 lines (117 loc) · 3.13 KB
/
example_test.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
//nolint:exhaustive,testableexamples
package starrcmd_test
import (
"fmt"
"golift.io/starr"
"golift.io/starr/starrcmd"
)
/* This example assumes you want to handle custom script command hooks for all applications.
Trim it to what you need; this is just an example.
*/
// This is an example main() function that uses the golft.io/starr/starrcmd module.
func Example() {
// Do your own configuration input here.
cmd, err := starrcmd.New()
if err != nil {
panic(err)
}
switch cmd.App {
case starr.Radarr:
DoRadarr(cmd)
case starr.Sonarr:
DoSonarr(cmd)
case starr.Readarr:
DoReadarr(cmd)
case starr.Lidarr:
DoLidarr(cmd)
case starr.Prowlarr:
DoProwlarr(cmd)
}
}
// DoRadarr handles any Radarr event.
func DoRadarr(cmd *starrcmd.CmdEvent) { //nolint:cyclop
fmt.Println("Processing Radarr Event: ", cmd.Type)
switch cmd.Type {
case starrcmd.EventGrab:
grab, err := cmd.GetRadarrGrab()
if err != nil {
panic(err)
}
fmt.Println(grab.Title)
case starrcmd.EventApplicationUpdate:
update, err := cmd.GetRadarrApplicationUpdate()
if err != nil {
panic(err)
}
fmt.Println(update.Message)
case starrcmd.EventDownload:
download, err := cmd.GetRadarrDownload()
if err != nil {
panic(err)
}
fmt.Println(download.Title)
case starrcmd.EventHealthIssue:
health, err := cmd.GetRadarrHealthIssue()
if err != nil {
panic(err)
}
fmt.Println(health.IssueType, health.Message)
case starrcmd.EventMovieFileDelete:
movie, err := cmd.GetRadarrMovieFileDelete()
if err != nil {
panic(err)
}
fmt.Println(movie.Title, movie.Path)
case starrcmd.EventTest:
// nothing, it's useless
default:
fmt.Println("Ignored Radarr Event: ", cmd.Type)
}
}
/* The following procedures are just more examples. They're left empty on purpose. */
// DoSonarr handles any Sonarr event.
func DoSonarr(command *starrcmd.CmdEvent) {
fmt.Println("Processing Sonarr Event: ", command.Type)
switch command.Type {
case starrcmd.EventGrab:
case starrcmd.EventApplicationUpdate:
case starrcmd.EventDownload:
case starrcmd.EventHealthIssue:
default:
fmt.Println("Ignored Sonarr Event: ", command.Type)
}
}
// DoLidarr handles any Lidarr event.
func DoLidarr(command *starrcmd.CmdEvent) {
fmt.Println("Processing Lidarr Event: ", command.Type)
switch command.Type {
case starrcmd.EventGrab:
case starrcmd.EventApplicationUpdate:
case starrcmd.EventDownload:
case starrcmd.EventHealthIssue:
default:
fmt.Println("Ignored Lidarr Event: ", command.Type)
}
}
// DoReadarr handles any Readarr event.
func DoReadarr(command *starrcmd.CmdEvent) {
fmt.Println("Processing Readarr Event: ", command.Type)
switch command.Type {
case starrcmd.EventGrab:
case starrcmd.EventApplicationUpdate:
case starrcmd.EventDownload:
case starrcmd.EventHealthIssue:
default:
fmt.Println("Ignored Readarr Event: ", command.Type)
}
}
// DoProwlarr handles any Prowlarr event.
func DoProwlarr(command *starrcmd.CmdEvent) {
fmt.Println("Processing Prowlarr Event: ", command.Type)
switch command.Type {
case starrcmd.EventApplicationUpdate:
case starrcmd.EventHealthIssue:
default:
fmt.Println("Ignored Prowlarr Event: ", command.Type)
}
}