-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
main.go
90 lines (74 loc) · 2.27 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
package main // import "github.com/nix-community/queued-build-hook"
import (
"flag"
"fmt"
"log"
"os"
)
func main() {
stderr := log.New(os.Stderr, "queued-build-hook: ", 0)
daemonCommand := flag.NewFlagSet("daemon", flag.ExitOnError)
realHook := daemonCommand.String("hook", "", "Path to the 'real' post-build-hook")
retryInterval := daemonCommand.Int("retry-interval", 1, "Retry interval (in seconds)")
retries := daemonCommand.Int("retries", 5, "How many retries to attempt before dropping")
concurrency := daemonCommand.Int("concurrency", 0, "How many jobs to run in parallel (default 0 / infinite)")
queueCommand := flag.NewFlagSet("queue", flag.ExitOnError)
queueSockPath := queueCommand.String("socket", "", "Path to daemon socket")
queueTag := queueCommand.String("tag", "", "Optional tag, for use with wait")
waitCommand := flag.NewFlagSet("wait", flag.ExitOnError)
waitSockPath := waitCommand.String("socket", "", "Path to daemon socket")
waitTag := waitCommand.String("tag", "", "Optional tag to filter on")
printDefaults := func() {
fmt.Printf("Usage: \"%s daemon\", \"%s queue\" \"%s wait\"\n", os.Args[0], os.Args[0], os.Args[0])
fmt.Println("\nUsage of daemon:")
daemonCommand.PrintDefaults()
fmt.Println("\nUsage of queue:")
queueCommand.PrintDefaults()
fmt.Println("\nUsage of wait:")
waitCommand.PrintDefaults()
}
if len(os.Args) <= 1 {
printDefaults()
os.Exit(1)
}
switch os.Args[1] {
case "daemon":
daemonCommand.Parse(os.Args[2:])
case "queue":
queueCommand.Parse(os.Args[2:])
case "wait":
waitCommand.Parse(os.Args[2:])
}
if daemonCommand.Parsed() {
hook := *realHook
if hook == "" {
panic("Missing required flag hook")
}
RunDaemon(stderr, hook, &DaemonConfig{
RetryInterval: *retryInterval,
Retries: *retries,
Concurrency: *concurrency,
})
} else if queueCommand.Parsed() {
sock := *queueSockPath
if sock == "" {
panic("Missing required flag socket")
}
err := RunQueueClient(sock, *queueTag)
if err != nil {
panic(err)
}
} else if waitCommand.Parsed() {
sock := *waitSockPath
if sock == "" {
panic("Missing required flag socket")
}
err := RunWaitClient(sock, *waitTag)
if err != nil {
panic(err)
}
} else {
printDefaults()
panic("No supported command parsed")
}
}