Merge pull request #83 from z0mbix/master

Add -v flag to output version
This commit is contained in:
Yann Hamon 2021-11-16 18:21:53 +01:00 committed by GitHub
commit f2e47c3596
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 23 additions and 1 deletions

View file

@ -20,6 +20,7 @@ builds:
- -a - -a
ldflags: ldflags:
- -extldflags "-static" - -extldflags "-static"
- -X main.version={{.Tag}}
archives: archives:
- format: tar.gz - format: tar.gz
@ -58,4 +59,4 @@ changelog:
sort: asc sort: asc
filters: filters:
exclude: exclude:
- '^test:' - '^test:'

View file

@ -90,6 +90,7 @@ Usage: ./bin/kubeconform [OPTION]... [FILE OR FOLDER]...
disallow additional properties not in schema disallow additional properties not in schema
-summary -summary
print a summary at the end (ignored for junit output) print a summary at the end (ignored for junit output)
-v show version information
-verbose -verbose
print results for all resources (ignored for tap and junit output) print results for all resources (ignored for tap and junit output)
``` ```

View file

@ -15,6 +15,8 @@ import (
"github.com/yannh/kubeconform/pkg/validator" "github.com/yannh/kubeconform/pkg/validator"
) )
var version = "development"
func processResults(cancel context.CancelFunc, o output.Output, validationResults <-chan validator.Result, exitOnError bool) <-chan bool { func processResults(cancel context.CancelFunc, o output.Output, validationResults <-chan validator.Result, exitOnError bool) <-chan bool {
success := true success := true
result := make(chan bool) result := make(chan bool)
@ -48,6 +50,9 @@ func realMain() int {
cfg, out, err := config.FromFlags(os.Args[0], os.Args[1:]) cfg, out, err := config.FromFlags(os.Args[0], os.Args[1:])
if cfg.Help { if cfg.Help {
return 0 return 0
} else if cfg.Version {
fmt.Println(version)
return 0
} else if out != "" { } else if out != "" {
fmt.Println(out) fmt.Println(out)
return 1 return 1

View file

@ -26,6 +26,7 @@ type Config struct {
IgnoreMissingSchemas bool IgnoreMissingSchemas bool
IgnoreFilenamePatterns []string IgnoreFilenamePatterns []string
Help bool Help bool
Version bool
} }
type arrayParam []string type arrayParam []string
@ -79,6 +80,7 @@ func FromFlags(progName string, args []string) (Config, string, error) {
flags.StringVar(&c.Cache, "cache", "", "cache schemas downloaded via HTTP to this folder") flags.StringVar(&c.Cache, "cache", "", "cache schemas downloaded via HTTP to this folder")
flags.StringVar(&c.CPUProfileFile, "cpu-prof", "", "debug - log CPU profiling to file") flags.StringVar(&c.CPUProfileFile, "cpu-prof", "", "debug - log CPU profiling to file")
flags.BoolVar(&c.Help, "h", false, "show help information") flags.BoolVar(&c.Help, "h", false, "show help information")
flags.BoolVar(&c.Version, "v", false, "show version information")
flags.Usage = func() { flags.Usage = func() {
fmt.Fprintf(os.Stderr, "Usage: %s [OPTION]... [FILE OR FOLDER]...\n", progName) fmt.Fprintf(os.Stderr, "Usage: %s [OPTION]... [FILE OR FOLDER]...\n", progName)

View file

@ -70,6 +70,19 @@ func TestFromFlags(t *testing.T) {
RejectKinds: map[string]struct{}{}, RejectKinds: map[string]struct{}{},
}, },
}, },
{
[]string{"-v"},
Config{
Files: []string{},
Version: true,
KubernetesVersion: "master",
NumberOfWorkers: 4,
OutputFormat: "text",
SchemaLocations: nil,
SkipKinds: map[string]struct{}{},
RejectKinds: map[string]struct{}{},
},
},
{ {
[]string{"-skip", "a,b,c"}, []string{"-skip", "a,b,c"},
Config{ Config{