mirror of
https://github.com/yannh/kubeconform.git
synced 2026-02-19 09:57:02 +00:00
Move cfg parsing out of realmain, rename realmain to kubeconform
This commit is contained in:
parent
ad935b7e32
commit
ce2f6de185
1 changed files with 25 additions and 24 deletions
|
|
@ -46,29 +46,8 @@ func processResults(cancel context.CancelFunc, o output.Output, validationResult
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
func realMain() int {
|
func kubeconform(cfg config.Config) int {
|
||||||
cfg, out, err := config.FromFlags(os.Args[0], os.Args[1:])
|
var err error
|
||||||
if out != "" {
|
|
||||||
o := os.Stderr
|
|
||||||
errCode := 1
|
|
||||||
if cfg.Help {
|
|
||||||
o = os.Stdout
|
|
||||||
errCode = 0
|
|
||||||
}
|
|
||||||
fmt.Fprintln(o, out)
|
|
||||||
return errCode
|
|
||||||
}
|
|
||||||
|
|
||||||
if cfg.Version {
|
|
||||||
fmt.Println(version)
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
fmt.Fprintf(os.Stderr, "failed parsing command line: %s\n", err.Error())
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
|
|
||||||
cpuProfileFile := os.Getenv("KUBECONFORM_CPUPROFILE_FILE")
|
cpuProfileFile := os.Getenv("KUBECONFORM_CPUPROFILE_FILE")
|
||||||
if cpuProfileFile != "" {
|
if cpuProfileFile != "" {
|
||||||
f, err := os.Create(cpuProfileFile)
|
f, err := os.Create(cpuProfileFile)
|
||||||
|
|
@ -178,5 +157,27 @@ func realMain() int {
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
os.Exit(realMain())
|
cfg, out, err := config.FromFlags(os.Args[0], os.Args[1:])
|
||||||
|
if out != "" {
|
||||||
|
o := os.Stderr
|
||||||
|
errCode := 1
|
||||||
|
if cfg.Help {
|
||||||
|
o = os.Stdout
|
||||||
|
errCode = 0
|
||||||
|
}
|
||||||
|
fmt.Fprintln(o, out)
|
||||||
|
os.Exit(errCode)
|
||||||
|
}
|
||||||
|
|
||||||
|
if cfg.Version {
|
||||||
|
fmt.Println(version)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "failed parsing command line: %s\n", err.Error())
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
os.Exit(kubeconform(cfg))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue