mirror of
https://github.com/safedep/pmg.git
synced 2026-08-03 07:24:09 +02:00
35 lines
581 B
Go
35 lines
581 B
Go
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
|
|
},
|
|
}
|
|
}
|