Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add -v flag to output version #83

Merged
merged 3 commits into from
Nov 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ builds:
- -a
ldflags:
- -extldflags "-static"
- -X main.version={{.Tag}}

archives:
- format: tar.gz
Expand Down Expand Up @@ -58,4 +59,4 @@ changelog:
sort: asc
filters:
exclude:
- '^test:'
- '^test:'
1 change: 1 addition & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ Usage: ./bin/kubeconform [OPTION]... [FILE OR FOLDER]...
disallow additional properties not in schema
-summary
print a summary at the end (ignored for junit output)
-v show version information
-verbose
print results for all resources (ignored for tap and junit output)
```
Expand Down
5 changes: 5 additions & 0 deletions cmd/kubeconform/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (
"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 {
success := true
result := make(chan bool)
Expand Down Expand Up @@ -48,6 +50,9 @@ func realMain() int {
cfg, out, err := config.FromFlags(os.Args[0], os.Args[1:])
if cfg.Help {
return 0
} else if cfg.Version {
fmt.Println(version)
return 0
} else if out != "" {
fmt.Println(out)
return 1
Expand Down
2 changes: 2 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type Config struct {
IgnoreMissingSchemas bool
IgnoreFilenamePatterns []string
Help bool
Version bool
}

type arrayParam []string
Expand Down Expand Up @@ -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.CPUProfileFile, "cpu-prof", "", "debug - log CPU profiling to file")
flags.BoolVar(&c.Help, "h", false, "show help information")
flags.BoolVar(&c.Version, "v", false, "show version information")
flags.Usage = func() {
fmt.Fprintf(os.Stderr, "Usage: %s [OPTION]... [FILE OR FOLDER]...\n", progName)

Expand Down
13 changes: 13 additions & 0 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,19 @@ func TestFromFlags(t *testing.T) {
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"},
Config{
Expand Down