-
Notifications
You must be signed in to change notification settings - Fork 51
/
version.go
60 lines (51 loc) · 1.24 KB
/
version.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
package version
import (
"github.com/jenkins-x/jx-helpers/v3/pkg/cobras/helper"
"github.com/jenkins-x/jx-helpers/v3/pkg/termcolor"
"github.com/jenkins-x/jx-logging/v3/pkg/log"
"github.com/spf13/cobra"
)
// Build information. Populated at build-time.
var (
Version string
Revision string
Branch string
BuildUser string
BuildDate string
GoVersion string
)
const (
// TestVersion used in test cases for the current version if no
// version can be found - such as if the version property is not properly
// included in the go test flags
TestVersion = "1.0.0-SNAPSHOT"
)
// ShowOptions the options for viewing running PRs
type Options struct {
Verbose bool
}
// NewCmdVersion creates a command object for the "version" command
func NewCmdVersion() (*cobra.Command, *Options) {
o := &Options{}
cmd := &cobra.Command{
Use: "version",
Short: "Displays the version of this command",
Run: func(cmd *cobra.Command, args []string) {
err := o.Run()
helper.CheckErr(err)
},
}
return cmd, o
}
// Run implements the command
func (o *Options) Run() error {
v := GetVersion()
log.Logger().Infof("version: %s", termcolor.ColorInfo(v))
return nil
}
func GetVersion() string {
if Version != "" {
return Version
}
return TestVersion
}