-
Notifications
You must be signed in to change notification settings - Fork 223
/
main.go
109 lines (86 loc) · 1.97 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package main
import (
"context"
"fmt"
"os"
"runtime/debug"
"time"
"github.com/getsentry/sentry-go"
"github.com/hashicorp/go-multierror"
"github.com/logrusorgru/aurora"
"github.com/superfly/flyctl/cmd"
"github.com/superfly/flyctl/flyctl"
"github.com/superfly/flyctl/flyname"
"github.com/superfly/flyctl/internal/client"
)
func main() {
flyname.Name() // Initialise
opts := sentry.ClientOptions{
Dsn: "https://89fa584dc19b47a6952dd94bf72dbab4@sentry.io/4492967",
// Debug: true,
Environment: flyctl.Environment,
Release: flyctl.Version,
}
if err := sentry.Init(opts); err != nil {
fmt.Printf("sentry.Init: %s", err)
}
defer func() {
if err := recover(); err != nil {
sentry.CurrentHub().Recover(err)
fmt.Println(aurora.Red("Oops, something went wrong! Could you try that again?"))
if flyctl.Environment == "production" {
flyctl.BackgroundTaskWG.Add(1)
go func() {
sentry.Flush(2 * time.Second)
flyctl.BackgroundTaskWG.Done()
}()
} else {
if flyctl.Environment != "production" {
fmt.Println()
fmt.Println(err)
fmt.Println(string(debug.Stack()))
}
}
flyctl.BackgroundTaskWG.Wait()
os.Exit(1)
}
}()
defer flyctl.BackgroundTaskWG.Wait()
client := client.NewClient()
if !client.IO.ColorEnabled() {
// disable colors
}
root := cmd.NewRootCmd(client)
// cmd, _, err := root.Traverse(os.Args[1:])
// fmt.Println("resolved to", cmd.Use)
// checkErr(err)
_, err := root.ExecuteC()
checkErr(err)
}
func checkErr(err error) {
if err == nil {
return
}
if !isCancelledError(err) {
fmt.Println(aurora.Red("Error"), err)
}
safeExit()
}
func isCancelledError(err error) bool {
if err == cmd.ErrAbort {
return true
}
if err == context.Canceled {
return true
}
if merr, ok := err.(*multierror.Error); ok {
if len(merr.Errors) == 1 && merr.Errors[0] == context.Canceled {
return true
}
}
return false
}
func safeExit() {
flyctl.BackgroundTaskWG.Wait()
os.Exit(1)
}