Skip to content

Bug 1827738: feat(opm): add version command #306

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 7, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cmd/opm/main.go
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@ import (
"github.com/operator-framework/operator-registry/cmd/opm/alpha"
"github.com/operator-framework/operator-registry/cmd/opm/index"
"github.com/operator-framework/operator-registry/cmd/opm/registry"
"github.com/operator-framework/operator-registry/cmd/opm/version"
)

func main() {
@@ -26,6 +27,7 @@ func main() {

rootCmd.AddCommand(registry.NewOpmRegistryCmd(), alpha.NewCmd())
index.AddCommand(rootCmd)
version.AddCommand(rootCmd)

rootCmd.Flags().Bool("debug", false, "enable debug logging")
if err := rootCmd.Flags().MarkHidden("debug"); err != nil {
56 changes: 56 additions & 0 deletions cmd/opm/version/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package version

import (
"fmt"
"runtime"

"github.com/spf13/cobra"
)

var (
// opmVersion is the constant representing the version of the opm binary
opmVersion = "unknown"
// gitCommit is a constant representing the source version that
// generated this build. It should be set during build via -ldflags.
gitCommit string
// buildDate in ISO8601 format, output of $(date -u +'%Y-%m-%dT%H:%M:%SZ')
buildDate string
)

type Version struct {
OpmVersion string `json:"opmVersion"`
GitCommit string `json:"gitCommit"`
BuildDate string `json:"buildDate"`
GoOs string `json:"goOs"`
GoArch string `json:"goArch"`
}

func getVersion() Version {
return Version{
OpmVersion: opmVersion,
GitCommit: gitCommit,
BuildDate: buildDate,
GoOs: runtime.GOOS,
GoArch: runtime.GOARCH,
}
}

func (v Version) Print() {
fmt.Printf("Version: %#v\n", v)
}

func AddCommand(parent *cobra.Command) {
cmd := &cobra.Command{
Use: "version",
Short: "Print the opm version",
Long: `Print the opm version`,
Example: `kubebuilder version`,
Run: runVersion,
}

parent.AddCommand(cmd)
}

func runVersion(_ *cobra.Command, _ []string) {
getVersion().Print()
}