github.com/tagesspiegel/helm-plugin-bootstrap@v0.2.3/cmd/bootstrap/main.go (about) 1 package main 2 3 import ( 4 "fmt" 5 "os" 6 "runtime/debug" 7 "time" 8 9 "github.com/tagesspiegel/helm-plugin-bootstrap/internal/cli" 10 ) 11 12 var ( 13 revision string 14 buildTime time.Time 15 dirtyBuild bool 16 arch string 17 goos string 18 19 rootCmd = cli.NewBootstrapCmd(os.Stdout) 20 ) 21 22 // we use the init function to setup the version information and flags for the root command 23 func init() { 24 buildInfo, ok := debug.ReadBuildInfo() 25 if !ok { 26 return 27 } 28 for _, set := range buildInfo.Settings { 29 switch set.Key { 30 case "vcs.revision": 31 revision = set.Value 32 case "vcs.time": 33 buildTime, _ = time.Parse(time.RFC3339, set.Value) 34 case "GOARCH": 35 arch = set.Value 36 case "GOOS": 37 goos = set.Value 38 case "vcs.modified": 39 dirtyBuild = set.Value == "true" 40 } 41 } 42 // add version info 43 rootCmd.Version = fmt.Sprintf("%s %s - %v [ %s/%s ] [ %v ]", buildInfo.Main.Version, revision, buildTime, arch, goos, dirtyBuild) 44 } 45 46 func main() { 47 if err := rootCmd.Execute(); err != nil { 48 panic(err) 49 } 50 }