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