mirror of
https://github.com/yannh/kubeconform.git
synced 2026-02-17 08:57:02 +00:00
Add -v to output version number
This commit is contained in:
parent
d536a659bd
commit
d63de52458
4 changed files with 25 additions and 1 deletions
|
|
@ -20,6 +20,7 @@ builds:
|
||||||
- -a
|
- -a
|
||||||
ldflags:
|
ldflags:
|
||||||
- -extldflags "-static"
|
- -extldflags "-static"
|
||||||
|
- -X github.com/yannh/kubeconform/pkg/config.version={{.Tag}}
|
||||||
|
|
||||||
archives:
|
archives:
|
||||||
- format: tar.gz
|
- format: tar.gz
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,8 @@ 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 {
|
||||||
|
return 0
|
||||||
} else if out != "" {
|
} else if out != "" {
|
||||||
fmt.Println(out)
|
fmt.Println(out)
|
||||||
return 1
|
return 1
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,8 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var version = "development"
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Cache string
|
Cache string
|
||||||
CPUProfileFile string
|
CPUProfileFile string
|
||||||
|
|
@ -26,6 +28,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 +82,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)
|
||||||
|
|
||||||
|
|
@ -98,5 +102,9 @@ func FromFlags(progName string, args []string) (Config, string, error) {
|
||||||
flags.Usage()
|
flags.Usage()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if c.Version {
|
||||||
|
fmt.Println(version)
|
||||||
|
}
|
||||||
|
|
||||||
return c, buf.String(), err
|
return c, buf.String(), err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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{
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue