From b82812a51cb34cf1f3f0c59b4829dc4139af9ca1 Mon Sep 17 00:00:00 2001 From: nida <> Date: Tue, 13 Feb 2024 11:35:32 -0500 Subject: [PATCH 1/2] Added the version command --- .github/workflows/nightly-build.yaml | 4 +-- cmd/root.go | 2 ++ pkg/cmd/version/version.go | 45 ++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 pkg/cmd/version/version.go diff --git a/.github/workflows/nightly-build.yaml b/.github/workflows/nightly-build.yaml index c8f096b1..38214e38 100644 --- a/.github/workflows/nightly-build.yaml +++ b/.github/workflows/nightly-build.yaml @@ -50,8 +50,8 @@ jobs: binName="${binName}.exe" fi go build -o "$binName" \ - -ldflags="-s -w" \ - + ldflags="-s -w -X 'pkg/cmd/version.Version=${version}' -X 'pkg/cmd/version.GitCommit=${gitCommit}' -X 'pkg/cmd/version.BuildTime=${buildTime}'" + - name: Generate archive run: | if [ $GOOS == "windows" ]; then diff --git a/cmd/root.go b/cmd/root.go index c16b5b2d..5f9565d8 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -9,6 +9,7 @@ import ( "jmm/pkg/cmd/models" "jmm/pkg/cmd/pull" "jmm/pkg/cmd/push" + "jmm/pkg/cmd/version" "os" "os/user" "path/filepath" @@ -41,6 +42,7 @@ func init() { rootCmd.AddCommand(pull.NewCmdPull()) rootCmd.AddCommand(push.NewCmdPush()) rootCmd.AddCommand(models.ModelsCommand()) + rootCmd.AddCommand(version.NewCmdVersion()) } func newRootCmd() *cobra.Command { diff --git a/pkg/cmd/version/version.go b/pkg/cmd/version/version.go new file mode 100644 index 00000000..90fe488f --- /dev/null +++ b/pkg/cmd/version/version.go @@ -0,0 +1,45 @@ +package version + +import ( + "fmt" + "github.com/spf13/cobra" + "runtime" +) + +// Default build-time variable. +// These values are overridden via ldflags +var ( + Version = "unknown" + GitCommit = "unknown" + BuildTime = "unknown" + GoVersion = runtime.Version() +) + +func NewCmdVersion() *cobra.Command { + + cmd := &cobra.Command{ + Use: "version", + Short: "Display the version information for jmm", + Long: `The version command prints detailed version information for the jmm CLI tool, +including the current version of the tool, the Git commit that the version was built from, +the build time, and the version of Go it was compiled with. This can be useful for debugging +or verifying that you are running the expected version of jmm.`, + Run: func(cmd *cobra.Command, args []string) { + fmt.Printf("Version: %s\nCommit: %s\nBuilt: %s\nGo version: %s\n", Version, GitCommit, BuildTime, GoVersion) + }, + } + return cmd +} + +func init() { + + // Here you will define your flags and configuration settings. + + // Cobra supports Persistent Flags which will work for this command + // and all subcommands, e.g.: + // pushCmd.PersistentFlags().String("foo", "", "A help for foo") + + // Cobra supports local flags which will only run when this command + // is called directly, e.g.: + // pushCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") +} From 156bd8f394e3a75cf29c5ffd119580862850667e Mon Sep 17 00:00:00 2001 From: nida <> Date: Tue, 13 Feb 2024 11:41:04 -0500 Subject: [PATCH 2/2] removed commented out code --- pkg/cmd/version/version.go | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/pkg/cmd/version/version.go b/pkg/cmd/version/version.go index 90fe488f..52b7245a 100644 --- a/pkg/cmd/version/version.go +++ b/pkg/cmd/version/version.go @@ -31,15 +31,4 @@ or verifying that you are running the expected version of jmm.`, return cmd } -func init() { - - // Here you will define your flags and configuration settings. - - // Cobra supports Persistent Flags which will work for this command - // and all subcommands, e.g.: - // pushCmd.PersistentFlags().String("foo", "", "A help for foo") - - // Cobra supports local flags which will only run when this command - // is called directly, e.g.: - // pushCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") -} +func init() {}