Adds version command and Makefile for build info
Provides a `gitlocal version` command to display the application's version, commit hash, and build date. Introduces a `Makefile` to automate builds, installations, and tests. The Makefile dynamically extracts version, commit, and date from git tags, commit hashes, and build timestamps, injecting this metadata into the Go binary via `ldflags`. Updates the `README.md` to document the new command and recommended build process using the Makefile.
This commit is contained in:
31
cmd/version.go
Normal file
31
cmd/version.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var (
|
||||
// Version is set via -ldflags during build
|
||||
Version = "dev"
|
||||
// Commit is set via -ldflags during build
|
||||
Commit = "unknown"
|
||||
// Date is set via -ldflags during build
|
||||
Date = "unknown"
|
||||
)
|
||||
|
||||
var versionCmd = &cobra.Command{
|
||||
Use: "version",
|
||||
Short: "Print version information",
|
||||
Long: `Display the version, commit hash, and build date of gitlocal.`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
fmt.Printf("gitlocal version %s\n", Version)
|
||||
fmt.Printf(" Commit: %s\n", Commit)
|
||||
fmt.Printf(" Built: %s\n", Date)
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(versionCmd)
|
||||
}
|
||||
Reference in New Issue
Block a user