-
Notifications
You must be signed in to change notification settings - Fork 230
/
main.go
50 lines (38 loc) · 942 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
import (
"context"
"os"
"os/signal"
"runtime"
"syscall"
"github.com/superfly/flyctl/pkg/iostreams"
"github.com/superfly/flyctl/internal/buildinfo"
"github.com/superfly/flyctl/internal/cli"
"github.com/superfly/flyctl/internal/sentry"
)
func main() {
os.Exit(run())
}
func run() (exitCode int) {
ctx, cancel := newContext()
defer cancel()
if !buildinfo.IsDev() {
defer func() {
if r := recover(); r != nil {
sentry.Record(r)
exitCode = 3
}
}()
}
exitCode = cli.Run(ctx, iostreams.System(), os.Args[1:]...)
return
}
func newContext() (context.Context, context.CancelFunc) {
// NOTE: when signal.Notify is called for os.Interrupt it traps both
// ^C (Control-C) and ^BREAK (Control-Break) on Windows.
signals := []os.Signal{os.Interrupt}
if runtime.GOOS != "windows" {
signals = append(signals, syscall.SIGTERM)
}
return signal.NotifyContext(context.Background(), signals...)
}