[DEPRECATED] Go implementation of plcbundle
1package commands
2
3import (
4 "fmt"
5 "runtime/debug"
6)
7
8var (
9 version = "dev"
10 gitCommit = "unknown"
11 buildDate = "unknown"
12)
13
14func init() {
15 if info, ok := debug.ReadBuildInfo(); ok {
16 if info.Main.Version != "" && info.Main.Version != "(devel)" {
17 version = info.Main.Version
18 }
19
20 for _, setting := range info.Settings {
21 switch setting.Key {
22 case "vcs.revision":
23 if setting.Value != "" {
24 gitCommit = setting.Value
25 if len(gitCommit) > 7 {
26 gitCommit = gitCommit[:7]
27 }
28 }
29 case "vcs.time":
30 if setting.Value != "" {
31 buildDate = setting.Value
32 }
33 }
34 }
35 }
36}
37
38// VersionCommand handles the version subcommand
39func VersionCommand(args []string) error {
40 fmt.Printf("plcbundle version %s\n", version)
41 fmt.Printf(" commit: %s\n", gitCommit)
42 fmt.Printf(" built: %s\n", buildDate)
43 return nil
44}
45
46// GetVersion returns the version string
47func GetVersion() string {
48 return version
49}