Currently when we use -h or --help flag to print help message, it would add additional pflag: help requested to the end of message; or when some other errors occurred, it would print the error message twice (front and end).
It was caused by those codes,
|
case ContinueOnError: |
|
return err |
|
case ExitOnError: |
|
fmt.Println(err) |
|
os.Exit(2) |
|
case PanicOnError: |
|
panic(err) |
And in go's official flag package, it would explicitly ignore the ErrHelp error.
switch f.errorHandling {
case ContinueOnError:
return err
case ExitOnError:
if err == ErrHelp {
os.Exit(0)
}
os.Exit(2)
case PanicOnError:
panic(err)
}
I don't know if this was some kind of bug, but a little fixes might be better.🤗
Currently when we use
-hor--helpflag to print help message, it would add additionalpflag: help requestedto the end of message; or when some other errors occurred, it would print the error message twice (front and end).It was caused by those codes,
pflag/flag.go
Lines 1144 to 1150 in 2e9d26c
And in go's official
flagpackage, it would explicitly ignore theErrHelperror.I don't know if this was some kind of bug, but a little fixes might be better.🤗