generated from roerohan/Template
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathmain.go
66 lines (53 loc) · 1.14 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
package main
import (
"flag"
"fmt"
"os"
)
var (
timeout int
services Services
quiet bool
strict bool
)
func init() {
flag.IntVar(&timeout, "t", 15, "Timeout in seconds, zero for no timeout")
flag.BoolVar(&quiet, "q", false, "Quiet, don't output any status messages")
flag.BoolVar(&strict, "s", false, "Only execute subcommand if the test succeeds")
flag.Var(&services, "w", "Services to be waiting for, in the form `host:port`")
}
// Log is used to log with prefix wait-for-it:
func Log(message string) {
if quiet {
return
}
fmt.Println("wait-for-it: " + message)
}
func main() {
flag.Parse()
args := os.Args
if len(services) != 0 {
Log(fmt.Sprintf("waiting %d seconds for %s", timeout, services.String()))
ok := services.Wait(timeout)
if !ok {
Log(fmt.Sprintf("timeout occured after waiting for %d seconds", timeout))
if strict {
Log("strict mode, refusing to execute subprocess")
os.Exit(1)
}
}
}
var command []string
for i, arg := range args {
if arg == "--" {
if (i + 1) < len(args) {
command = args[i+1:]
}
break
}
}
if len(command) == 0 {
return
}
os.Exit(Execute(command))
}