-
Notifications
You must be signed in to change notification settings - Fork 152
/
main.go
69 lines (57 loc) · 1.77 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
package main
import (
"fmt"
"os"
"runtime"
"runtime/debug"
"github.com/hashicorp/go-version"
"github.com/mattn/go-colorable"
"github.com/scaleway/scaleway-cli/v2/internal/core"
"github.com/scaleway/scaleway-cli/v2/internal/namespaces"
"github.com/scaleway/scaleway-cli/v2/internal/sentry"
"github.com/scaleway/scaleway-sdk-go/scw"
)
var (
// Version is updated by goreleaser
Version = "v2-dev" // ${BUILD_VERSION:-`git describe --tags --dirty --always`}"
// These are initialized by the build script
BuildDate = "unknown" // date -u '+%Y-%m-%d_%I:%M:%S%p'
GitBranch = "unknown" // git symbolic-ref -q --short HEAD || echo HEAD"
GitCommit = "unknown" // git rev-parse --short HEAD
// These are GO constants
GoVersion = runtime.Version()
GoOS = runtime.GOOS
GoArch = runtime.GOARCH
BetaMode = os.Getenv(scw.ScwEnableBeta) != ""
)
func cleanup(buildInfo *core.BuildInfo) {
if err := recover(); err != nil {
fmt.Println(sentry.ErrorBanner)
fmt.Println("stacktrace from panic: \n" + string(debug.Stack()))
// This will send an anonymous report on Scaleway's sentry.
if buildInfo.IsRelease() {
sentry.RecoverPanicAndSendReport(buildInfo, err)
}
}
}
func main() {
buildInfo := &core.BuildInfo{
Version: version.Must(version.NewSemver(Version)), // panic when version does not respect semantic versionning
BuildDate: BuildDate,
GoVersion: GoVersion,
GitBranch: GitBranch,
GitCommit: GitCommit,
GoOS: GoOS,
GoArch: GoArch,
}
defer cleanup(buildInfo)
exitCode, _, _ := core.Bootstrap(&core.BootstrapConfig{
Args: os.Args,
Commands: namespaces.GetCommands(BetaMode),
BuildInfo: buildInfo,
Stdout: colorable.NewColorableStdout(),
Stderr: colorable.NewColorableStderr(),
Stdin: os.Stdin,
})
os.Exit(exitCode)
}