grype/cmd/db_update.go
Alex Goodman 0f970816a2
add positional argument validation (#150)
Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
2020-09-12 20:04:39 -04:00

44 lines
867 B
Go

package cmd
import (
"fmt"
"os"
"github.com/anchore/grype/grype/db"
"github.com/spf13/cobra"
)
var dbUpdateCmd = &cobra.Command{
Use: "update",
Short: "download the latest vulnerability database",
Args: cobra.ExactArgs(0),
Run: func(cmd *cobra.Command, args []string) {
ret := runDbUpdateCmd(cmd, args)
if ret != 0 {
fmt.Println("Unable to update vulnerability database")
}
os.Exit(ret)
},
}
func init() {
dbCmd.AddCommand(dbUpdateCmd)
}
func runDbUpdateCmd(_ *cobra.Command, _ []string) int {
dbCurator := db.NewCurator(appConfig.Db.ToCuratorConfig())
updated, err := dbCurator.Update()
if err != nil {
log.Errorf("unable to update vulnerability database: %+v", err)
return 1
}
if updated {
fmt.Println("Vulnerability database updated!")
return 0
}
fmt.Println("No vulnerability database update available")
return 0
}