Skip to content

Ignore ErrHelp with Parse when ExitOnError #306

@xjasonlyu

Description

@xjasonlyu

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,

pflag/flag.go

Lines 1144 to 1150 in 2e9d26c

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions