File tree 2 files changed +58
-0
lines changed
2 files changed +58
-0
lines changed Original file line number Diff line number Diff line change 9
9
"github.com/operator-framework/operator-registry/cmd/opm/alpha"
10
10
"github.com/operator-framework/operator-registry/cmd/opm/index"
11
11
"github.com/operator-framework/operator-registry/cmd/opm/registry"
12
+ "github.com/operator-framework/operator-registry/cmd/opm/version"
12
13
)
13
14
14
15
func main () {
@@ -26,6 +27,7 @@ func main() {
26
27
27
28
rootCmd .AddCommand (registry .NewOpmRegistryCmd (), alpha .NewCmd ())
28
29
index .AddCommand (rootCmd )
30
+ version .AddCommand (rootCmd )
29
31
30
32
rootCmd .Flags ().Bool ("debug" , false , "enable debug logging" )
31
33
if err := rootCmd .Flags ().MarkHidden ("debug" ); err != nil {
Original file line number Diff line number Diff line change
1
+ package version
2
+
3
+ import (
4
+ "fmt"
5
+ "runtime"
6
+
7
+ "github.com/spf13/cobra"
8
+ )
9
+
10
+ var (
11
+ // opmVersion is the constant representing the version of the opm binary
12
+ opmVersion = "unknown"
13
+ // gitCommit is a constant representing the source version that
14
+ // generated this build. It should be set during build via -ldflags.
15
+ gitCommit string
16
+ // buildDate in ISO8601 format, output of $(date -u +'%Y-%m-%dT%H:%M:%SZ')
17
+ buildDate string
18
+ )
19
+
20
+ type Version struct {
21
+ OpmVersion string `json:"opmVersion"`
22
+ GitCommit string `json:"gitCommit"`
23
+ BuildDate string `json:"buildDate"`
24
+ GoOs string `json:"goOs"`
25
+ GoArch string `json:"goArch"`
26
+ }
27
+
28
+ func getVersion () Version {
29
+ return Version {
30
+ OpmVersion : opmVersion ,
31
+ GitCommit : gitCommit ,
32
+ BuildDate : buildDate ,
33
+ GoOs : runtime .GOOS ,
34
+ GoArch : runtime .GOARCH ,
35
+ }
36
+ }
37
+
38
+ func (v Version ) Print () {
39
+ fmt .Printf ("Version: %#v\n " , v )
40
+ }
41
+
42
+ func AddCommand (parent * cobra.Command ) {
43
+ cmd := & cobra.Command {
44
+ Use : "version" ,
45
+ Short : "Print the opm version" ,
46
+ Long : `Print the opm version` ,
47
+ Example : `kubebuilder version` ,
48
+ Run : runVersion ,
49
+ }
50
+
51
+ parent .AddCommand (cmd )
52
+ }
53
+
54
+ func runVersion (_ * cobra.Command , _ []string ) {
55
+ getVersion ().Print ()
56
+ }
You can’t perform that action at this time.
0 commit comments