forked from winjer/k8s-safe-cronjob
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
36 lines (33 loc) · 770 Bytes
/
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
package main
import (
"flag"
"fmt"
"errors"
"os/exec"
"github.com/getsentry/raven-go"
)
func main() {
dsn := flag.String("dsn", "", "Sentry dsn to report errors")
flag.Parse()
command := flag.Arg(0)
args := flag.Args()[1:]
if *dsn != "" {
fmt.Println("Using sentry dsn", *dsn)
raven.SetDSN(*dsn)
}
if command != "" {
cmd := exec.Command(command, args...)
output, err := cmd.CombinedOutput()
fmt.Printf("%s", string(output))
if err != nil {
if *dsn != "" {
wrapper := errors.New(fmt.Sprintf("Command exited with non-zero status: %s, reported: %s, output: %s", command, err.Error(), output))
raven.CaptureErrorAndWait(wrapper, nil)
} else {
fmt.Println(err.Error())
}
}
} else {
fmt.Println("No command provided")
}
}