mirror of
https://github.com/yannh/kubeconform.git
synced 2026-02-11 05:59:22 +00:00
Improve handling of cmdline errors (#91)
Improve handling of cmdline errors
This commit is contained in:
parent
607c90a0a9
commit
85b30f8c2a
2 changed files with 16 additions and 11 deletions
|
|
@ -48,15 +48,23 @@ func processResults(cancel context.CancelFunc, o output.Output, validationResult
|
|||
|
||||
func realMain() int {
|
||||
cfg, out, err := config.FromFlags(os.Args[0], os.Args[1:])
|
||||
if cfg.Help {
|
||||
return 0
|
||||
} else if cfg.Version {
|
||||
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
|
||||
} else if out != "" {
|
||||
fmt.Println(out)
|
||||
return 1
|
||||
} else if err != nil {
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "failed parsing command line: %s\n", err.Error())
|
||||
return 1
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import (
|
|||
"bytes"
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
|
|
@ -82,9 +81,7 @@ func FromFlags(progName string, args []string) (Config, string, error) {
|
|||
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)
|
||||
|
||||
flags.SetOutput(os.Stderr)
|
||||
fmt.Fprintf(&buf, "Usage: %s [OPTION]... [FILE OR FOLDER]...\n", progName)
|
||||
flags.PrintDefaults()
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue