Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore ErrHelp with Parse when ExitOnError #306

Open
xjasonlyu opened this issue Feb 10, 2021 · 3 comments · May be fixed by #407
Open

Ignore ErrHelp with Parse when ExitOnError #306

xjasonlyu opened this issue Feb 10, 2021 · 3 comments · May be fixed by #407

Comments

@xjasonlyu
Copy link

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

@cornfeedhobo
Copy link

@xjasonlyu There is a PR for this somewhere, but this repo is completely neglected. This has been fixed on my fork, which has instructions for how to get working with cobra.

@xjasonlyu
Copy link
Author

@cornfeedhobo Thanks.👍

@tmc
Copy link

tmc commented Jun 12, 2024

@xjasonlyu please reopen this issue.

@tmc tmc linked a pull request Jun 12, 2024 that will close this issue
@xjasonlyu xjasonlyu reopened this Jun 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants