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

Misleading shorthand flag panic message #1987

Closed
mdhender opened this issue Jun 21, 2023 · 3 comments · May be fixed by spf13/pflag#381
Closed

Misleading shorthand flag panic message #1987

mdhender opened this issue Jun 21, 2023 · 3 comments · May be fixed by spf13/pflag#381
Labels
area/flags-args Changes to functionality around command line flags and args good-first-issue Issues that a new contributor could make a PR for lifecycle/needs-pr Ready for a PR from the community

Comments

@mdhender
Copy link

Adding a BoolVarP with shorthand code of "h" to any flagset generates a misleading panic message:

panic: unable to redefine 'h' shorthand in "mapgen" flagset: it's already used for "flag" flag

The error makes it seem like the issue is with the "mapgen" flagset (in this example) when it's actually from the default help flagset.

To recreate, add a BoolVarP to the root command and then run the command with no arguments.

var flag bool
func init() {
	rootCmd.Flags().BoolVarP(&flag, "flag", "h", false, "flag")
}

This is with v1.0.5.

@marckhouzam
Copy link
Collaborator

This sounds like a good thing to improve. PR welcomed.

@marckhouzam marckhouzam added area/flags-args Changes to functionality around command line flags and args good-first-issue Issues that a new contributor could make a PR for lifecycle/needs-pr Ready for a PR from the community labels Jun 22, 2023
@roshanavand
Copy link

This message is coming from the pflag library, I created a PR here.

@marckhouzam
Copy link
Collaborator

Thanks @roshanavand !
Let's close this one in favor of the other.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/flags-args Changes to functionality around command line flags and args good-first-issue Issues that a new contributor could make a PR for lifecycle/needs-pr Ready for a PR from the community
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants