You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
1.1 KiB
Go

package cmd
import (
"fmt"
"runtime/debug"
"github.com/spf13/cobra"
)
// These variables are set at build time using ldflags
var (
Version = "dev" // Represents the version of the application
BuildTime = "unknown" // The time the binary was built
GitCommit = "unknown" // The git commit hash
)
// versionCmd represents the version command
var versionCmd = &cobra.Command{
Use: "version",
Short: "Print the version number, build time, and git commit",
Long: `Displays the application's version, the time it was built, the git commit it was built from, and the Go version used.`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("Version: %s\n", Version)
fmt.Printf("Build Time: %s\n", BuildTime)
fmt.Printf("Git Commit: %s\n", GitCommit)
// Print Go version and other build info if available
if info, ok := debug.ReadBuildInfo(); ok {
fmt.Printf("Go Version: %s\n", info.GoVersion)
}
},
}
// init function is called by Go when the package is initialized.
// We use it to add the 'version' command to our root command.
func init() {
rootCmd.AddCommand(versionCmd)
}