Skip to content
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

Add Version Command to the CLI Tool #14

Merged
merged 2 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions .github/workflows/nightly-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down
34 changes: 34 additions & 0 deletions pkg/cmd/version/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
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() {}