Skip to content

Commit d63de52

Browse files
committedNov 16, 2021
Add -v to output version number
1 parent d536a65 commit d63de52

File tree

4 files changed

+25
-1
lines changed

4 files changed

+25
-1
lines changed
 

‎.goreleaser.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ builds:
2020
- -a
2121
ldflags:
2222
- -extldflags "-static"
23+
- -X github.com/yannh/kubeconform/pkg/config.version={{.Tag}}
2324

2425
archives:
2526
- format: tar.gz
@@ -58,4 +59,4 @@ changelog:
5859
sort: asc
5960
filters:
6061
exclude:
61-
- '^test:'
62+
- '^test:'

‎cmd/kubeconform/main.go

+2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ func realMain() int {
4848
cfg, out, err := config.FromFlags(os.Args[0], os.Args[1:])
4949
if cfg.Help {
5050
return 0
51+
} else if cfg.Version {
52+
return 0
5153
} else if out != "" {
5254
fmt.Println(out)
5355
return 1

‎pkg/config/config.go

+8
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import (
88
"strings"
99
)
1010

11+
var version = "development"
12+
1113
type Config struct {
1214
Cache string
1315
CPUProfileFile string
@@ -26,6 +28,7 @@ type Config struct {
2628
IgnoreMissingSchemas bool
2729
IgnoreFilenamePatterns []string
2830
Help bool
31+
Version bool
2932
}
3033

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

@@ -98,5 +102,9 @@ func FromFlags(progName string, args []string) (Config, string, error) {
98102
flags.Usage()
99103
}
100104

105+
if c.Version {
106+
fmt.Println(version)
107+
}
108+
101109
return c, buf.String(), err
102110
}

‎pkg/config/config_test.go

+13
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,19 @@ func TestFromFlags(t *testing.T) {
7070
RejectKinds: map[string]struct{}{},
7171
},
7272
},
73+
{
74+
[]string{"-v"},
75+
Config{
76+
Files: []string{},
77+
Version: true,
78+
KubernetesVersion: "master",
79+
NumberOfWorkers: 4,
80+
OutputFormat: "text",
81+
SchemaLocations: nil,
82+
SkipKinds: map[string]struct{}{},
83+
RejectKinds: map[string]struct{}{},
84+
},
85+
},
7386
{
7487
[]string{"-skip", "a,b,c"},
7588
Config{

0 commit comments

Comments
 (0)
Please sign in to comment.