Add a version flag (#722)

This commit is contained in:
Sambhav Kothari 2021-12-23 23:56:07 +00:00 committed by GitHub
parent 211b188120
commit 7168dc7473
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4,7 +4,9 @@ import (
"fmt" "fmt"
"os" "os"
"github.com/anchore/syft/internal"
"github.com/anchore/syft/internal/config" "github.com/anchore/syft/internal/config"
"github.com/anchore/syft/internal/version"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/spf13/viper" "github.com/spf13/viper"
) )
@ -22,12 +24,14 @@ var rootCmd = &cobra.Command{
PreRunE: packagesCmd.PreRunE, PreRunE: packagesCmd.PreRunE,
RunE: packagesCmd.RunE, RunE: packagesCmd.RunE,
ValidArgsFunction: packagesCmd.ValidArgsFunction, ValidArgsFunction: packagesCmd.ValidArgsFunction,
Version: version.FromBuild().Version,
} }
func init() { func init() {
// set universal flags // set universal flags
rootCmd.PersistentFlags().StringVarP(&persistentOpts.ConfigPath, "config", "c", "", "application config file") rootCmd.PersistentFlags().StringVarP(&persistentOpts.ConfigPath, "config", "c", "", "application config file")
// setting the version template to just print out the string since we already have a templatized version string
rootCmd.SetVersionTemplate(fmt.Sprintf("%s {{.Version}}\n", internal.ApplicationName))
flag := "quiet" flag := "quiet"
rootCmd.PersistentFlags().BoolP( rootCmd.PersistentFlags().BoolP(
flag, "q", false, flag, "q", false,