grype/cmd/db_status.go

55 lines
1.2 KiB
Go
Raw Normal View History

package cmd
import (
"fmt"
"os"
2020-07-24 01:29:05 +00:00
"github.com/anchore/grype/grype/db"
"github.com/spf13/cobra"
)
2020-07-26 12:12:08 +00:00
var showSupportedDbSchema bool
var statusCmd = &cobra.Command{
Use: "status",
Short: "display database status",
Run: func(cmd *cobra.Command, args []string) {
err := runDbStatusCmd(cmd, args)
if err != nil {
log.Errorf(err.Error())
os.Exit(1)
}
},
}
func init() {
2020-07-26 12:12:08 +00:00
// 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)
}
func runDbStatusCmd(_ *cobra.Command, _ []string) error {
dbCurator := db.NewCurator(appConfig.Db.ToCuratorConfig())
status := dbCurator.Status()
2020-07-26 12:12:08 +00:00
if showSupportedDbSchema {
// note: the output for this option cannot change as it supports the nightly DB generation job
fmt.Println(status.RequiredSchemaVersion)
return nil
}
if status.Err != nil {
return status.Err
2020-07-26 12:12:08 +00:00
}
fmt.Println("Location: ", status.Location)
fmt.Println("Built: ", status.Age.String())
fmt.Println("Current DB Version: ", status.CurrentSchemaVersion)
fmt.Println("Require DB Version: ", status.RequiredSchemaVersion)
fmt.Println("Status: Valid")
return nil
}