feat: add version command (#26)

This commit is contained in:
Hanshal Mehta
2025-05-16 09:41:48 +05:30
committed by GitHub
parent d8d7bda8ca
commit 81d4875b8d
3 changed files with 43 additions and 1 deletions
+34
View File
@@ -0,0 +1,34 @@
package version
import (
"fmt"
"os"
runtimeDebug "runtime/debug"
"github.com/spf13/cobra"
)
var (
version string
commit string
)
func init() {
if version == "" {
buildInfo, _ := runtimeDebug.ReadBuildInfo()
version = buildInfo.Main.Version
}
}
func NewVersionCommand() *cobra.Command {
return &cobra.Command{
Use: "version",
Short: "Show version and build information",
RunE: func(cmd *cobra.Command, args []string) error {
fmt.Fprintf(os.Stdout, "Version: %s\n", version)
fmt.Fprintf(os.Stdout, "CommitSHA: %s\n", commit)
return nil
},
}
}