Repository: doitintl/kube-no-trouble (go)
Issue: Add a version command
Hi,

would it be possible to add a `kubent --version` or `kubent version` command to check the current version?

I'd like to use that command to verify that the installation was correctly. Currently, when running `kubent version` it'll start `kubent` without any error or waning :D

Pull request description: feat: Version flag
Closes #259 

Patch:
diff --git a/README.md b/README.md
index d6a0334..9724b96 100644
--- a/README.md
+++ b/README.md
@@ -87,6 +87,7 @@ Usage of ./kubent:
   -l, --log-level string          set log level (trace, debug, info, warn, error, fatal, panic, disabled) (default "info")
   -o, --output string             output format - [text|json] (default "text")
   -t, --target-version string     target K8s version in SemVer format (autodetected by default)
+  -v, --version                   prints the version of kubent and exits
 ```
 
 - *`-a, --additional-kind`*
diff --git a/cmd/kubent/main.go b/cmd/kubent/main.go
index cd6a921..093a180 100644
--- a/cmd/kubent/main.go
+++ b/cmd/kubent/main.go
@@ -102,6 +102,11 @@ func main() {
 		log.Fatal().Err(err).Msg("failed to parse config flags")
 	}
 
+	if config.KubentVersion {
+		log.Info().Msgf("version %s (git sha %s)", version, gitSha)
+		os.Exit(EXIT_CODE_SUCCESS)
+	}
+
 	zerolog.SetGlobalLevel(zerolog.Level(config.LogLevel))
 
 	log.Info().Msg(">>> Kube No Trouble `kubent` <<<")
diff --git a/pkg/config/config.go b/pkg/config/config.go
index 759ecc4..3ba7418 100644
--- a/pkg/config/config.go
+++ b/pkg/config/config.go
@@ -24,6 +24,7 @@ type Config struct {
 	LogLevel        ZeroLogLevel
 	Output          string
 	TargetVersion   *judge.Version
+	KubentVersion   bool
 }
 
 func NewFromFlags() (*Config, error) {
@@ -36,6 +37,7 @@ func NewFromFlags() (*Config, error) {
 	flag.BoolVarP(&config.Cluster, "cluster", "c", true, "enable Cluster collector")
 	flag.StringVarP(&config.Context, "context", "x", "", "kubeconfig context")
 	flag.BoolVarP(&config.ExitError, "exit-error", "e", false, "exit with non-zero code when issues are found")
+	flag.BoolVarP(&config.KubentVersion, "version", "v", false, "prints the version of kubent and exits")
 	flag.BoolVar(&config.Helm2, "helm2", true, "enable Helm v2 collector")
 	flag.BoolVar(&config.Helm3, "helm3", true, "enable Helm v3 collector")
 	flag.StringSliceVarP(&config.Filenames, "filename", "f", []string{}, "manifests to check, use - for stdin")


Test patch:
diff --git a/cmd/kubent/main_test.go b/cmd/kubent/main_test.go
index 363d998..25f210f 100644
--- a/cmd/kubent/main_test.go
+++ b/cmd/kubent/main_test.go
@@ -109,6 +109,8 @@ func TestMainExitCodes(t *testing.T) {
 		{"successFound", []string{"-c=false", "--helm2=false", "--helm3=false", "-f=" + filepath.Join(FIXTURES_DIR, "deployment-v1beta1.yaml")}, 0},
 		{"exitErrorFlagNone", []string{"-c=false", "--helm2=false", "--helm3=false", "-e"}, 0},
 		{"exitErrorFlagFound", []string{"-c=false", "--helm2=false", "--helm3=false", "-e", "-f=" + filepath.Join(FIXTURES_DIR, "deployment-v1beta1.yaml")}, 200},
+		{"version short flag set", []string{"-v"}, 0},
+		{"version long flag set", []string{"--version"}, 0},
 	}
 
 	if os.Getenv("TEST_EXIT_CODE") == "1" {