-
Notifications
You must be signed in to change notification settings - Fork 19
/
main.go
56 lines (47 loc) · 1.31 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
package main
import (
"context"
"os"
"github.com/spf13/viper"
"github.com/turbot/go-kit/helpers"
"github.com/turbot/pipe-fittings/error_helpers"
"github.com/turbot/pipe-fittings/utils"
"github.com/turbot/powerpipe/internal/cmd"
"github.com/turbot/powerpipe/internal/cmdconfig"
"github.com/turbot/powerpipe/internal/constants"
)
var exitCode int
var (
// These variables will be set by GoReleaser.
version = constants.DefaultVersion
commit = constants.DefaultCommit
date = constants.DefaultDate
builtBy = constants.DefaultBuiltBy
)
func main() {
ctx := context.Background()
utils.LogTime("main start")
// add the auto-populated version properties into viper
setVersionProperties()
// set app specific constants defined in pipe-fittings
cmdconfig.SetAppSpecificConstants()
defer func() {
if r := recover(); r != nil {
error_helpers.ShowError(ctx, helpers.ToError(r))
if exitCode == 0 {
exitCode = 255
}
}
utils.LogTime("main end")
utils.DisplayProfileData(os.Stderr)
os.Exit(exitCode)
}()
// execute the root command
exitCode = cmd.Execute()
}
func setVersionProperties() {
viper.SetDefault(constants.ConfigKeyVersion, version)
viper.SetDefault(constants.ConfigKeyCommit, commit)
viper.SetDefault(constants.ConfigKeyDate, date)
viper.SetDefault(constants.ConfigKeyBuiltBy, builtBy)
}