grype/cmd/version.go

40 lines
1.1 KiB
Go
Raw Normal View History

2020-05-26 14:37:28 +00:00
package cmd
import (
"fmt"
2020-07-24 01:29:05 +00:00
"github.com/anchore/grype/internal"
"github.com/anchore/grype/internal/version"
2020-05-26 14:37:28 +00:00
"github.com/spf13/cobra"
)
2020-07-21 15:58:00 +00:00
var showVerboseVersionInfo bool
2020-05-26 14:37:28 +00:00
var versionCmd = &cobra.Command{
Use: "version",
Short: "show the version",
2020-07-21 15:58:00 +00:00
Run: printVersion,
2020-05-26 14:37:28 +00:00
}
func init() {
2020-07-21 15:58:00 +00:00
versionCmd.Flags().BoolVarP(&showVerboseVersionInfo, "verbose", "v", false, "show additional version information")
2020-05-26 14:37:28 +00:00
2020-07-21 15:58:00 +00:00
rootCmd.AddCommand(versionCmd)
2020-05-26 14:37:28 +00:00
}
2020-07-21 15:58:00 +00:00
func printVersion(_ *cobra.Command, _ []string) {
versionInfo := version.FromBuild()
if showVerboseVersionInfo {
fmt.Println("Application: ", internal.ApplicationName)
fmt.Println("Version: ", versionInfo.Version)
fmt.Println("BuildDate: ", versionInfo.BuildDate)
fmt.Println("GitCommit: ", versionInfo.GitCommit)
fmt.Println("GitTreeState: ", versionInfo.GitTreeState)
fmt.Println("Platform: ", versionInfo.Platform)
fmt.Println("GoVersion: ", versionInfo.GoVersion)
fmt.Println("Compiler: ", versionInfo.Compiler)
} else {
fmt.Printf("%s %s\n", internal.ApplicationName, versionInfo.Version)
}
2020-05-26 14:37:28 +00:00
}