Improve handling of cmdline errors (#91)

Improve handling of cmdline errors
This commit is contained in:
Yann Hamon 2022-01-06 12:39:24 +01:00 committed by GitHub
parent 607c90a0a9
commit 85b30f8c2a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 11 deletions

View file

@ -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
}