pflag icon indicating copy to clipboard operation
pflag copied to clipboard

Ignore ErrHelp with Parse when ExitOnError

Open xjasonlyu opened this issue 4 years ago • 3 comments

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,

https://github.com/spf13/pflag/blob/2e9d26c8c37aae03e3f9d4e90b7116f5accb7cab/flag.go#L1144-L1150

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.🤗

xjasonlyu avatar Feb 10 '21 09:02 xjasonlyu