diff --git a/cmd/kubehound/root.go b/cmd/kubehound/root.go index 1c57dede8..da2a954c9 100644 --- a/cmd/kubehound/root.go +++ b/cmd/kubehound/root.go @@ -2,17 +2,20 @@ package main import ( "fmt" + "os" "github.com/DataDog/KubeHound/pkg/backend" "github.com/DataDog/KubeHound/pkg/cmd" + "github.com/DataDog/KubeHound/pkg/config" "github.com/DataDog/KubeHound/pkg/kubehound/core" "github.com/DataDog/KubeHound/pkg/telemetry/log" "github.com/spf13/cobra" ) var ( - cfgFile = "" - skipBackend = false + cfgFile = "" + skipBackend = false + printVersion = false ) var ( @@ -21,6 +24,11 @@ var ( Short: "A local Kubehound instance", Long: `A local instance of Kubehound - a Kubernetes attack path generator`, PreRunE: func(cobraCmd *cobra.Command, args []string) error { + if printVersion { + log.I.Infof("kubehound version: %s", config.BuildVersion) + os.Exit(0) + } + return cmd.InitializeKubehoundConfig(cobraCmd.Context(), cfgFile, true, false) }, RunE: func(cobraCmd *cobra.Command, args []string) error { @@ -60,6 +68,8 @@ var ( ) func init() { + rootCmd.Flags().BoolVarP(&printVersion, "version", "v", printVersion, "print the current version of Kubehound") + rootCmd.Flags().StringVarP(&cfgFile, "config", "c", cfgFile, "application config file") rootCmd.Flags().BoolVar(&skipBackend, "skip-backend", skipBackend, "skip the auto deployment of the backend stack (janusgraph, mongodb, and UI)")