mirror of
https://github.com/safedep/vet.git
synced 2025-12-10 00:22:08 -06:00
46 lines
1011 B
Go
46 lines
1011 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
runtimeDebug "runtime/debug"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/safedep/vet/internal/command"
|
|
)
|
|
|
|
// When building with CI or Make, version is set using `ldflags`
|
|
var (
|
|
version string
|
|
commit string
|
|
)
|
|
|
|
func init() {
|
|
// Only use buildInfo if version wasn't set by ldflags, that is its being build by `go install`
|
|
if version == "" {
|
|
// Main.Version is based on the version control system tag or commit.
|
|
// This useful when app is build with `go install`
|
|
// See: https://antonz.org/go-1-24/#main-modules-version
|
|
buildInfo, _ := runtimeDebug.ReadBuildInfo()
|
|
version = buildInfo.Main.Version
|
|
}
|
|
|
|
command.SetVersion(version)
|
|
}
|
|
|
|
func newVersionCommand() *cobra.Command {
|
|
cmd := &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
|
|
},
|
|
}
|
|
|
|
return cmd
|
|
}
|