Files
gitlocal/cmd/version.go
Daniel Tomlinson d00ffdb37c 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.
2026-04-11 14:55:43 +01:00

32 lines
642 B
Go

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)
}