add db schema output option

This commit is contained in:
Alex Goodman 2020-07-26 08:12:08 -04:00
parent c61483cb23
commit 6ead045457
No known key found for this signature in database
GPG key ID: 86E2870463D5E890
2 changed files with 23 additions and 8 deletions

View file

@ -9,6 +9,8 @@ import (
"github.com/spf13/cobra"
)
var showSupportedDbSchema bool
var statusCmd = &cobra.Command{
Use: "status",
Short: "display database status",
@ -18,6 +20,9 @@ var statusCmd = &cobra.Command{
}
func init() {
// Note: this option cannot change as it supports the nightly DB generation job
statusCmd.Flags().BoolVar(&showSupportedDbSchema, "schema", false, "show supported DB schema")
dbCmd.AddCommand(statusCmd)
}
@ -29,6 +34,13 @@ func runDbStatusCmd(_ *cobra.Command, _ []string) int {
}
status := dbCurator.Status()
if showSupportedDbSchema {
// Note: the output for this option cannot change as it supports the nightly DB generation job
fmt.Println(status.RequiredSchemeVersion)
return 0
}
fmt.Println("Location: ", status.Location)
fmt.Println("Built: ", status.Age.String())
fmt.Println("Current DB Version: ", status.CurrentSchemaVersion)

View file

@ -3,6 +3,8 @@ package cmd
import (
"fmt"
"github.com/anchore/grype-db/pkg/db"
"github.com/anchore/grype/internal"
"github.com/anchore/grype/internal/version"
"github.com/spf13/cobra"
@ -25,14 +27,15 @@ func init() {
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)
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)
fmt.Println("Supported DB Schema: ", db.SchemaVersion)
} else {
fmt.Printf("%s %s\n", internal.ApplicationName, versionInfo.Version)
}