Skip to content

Misleading shorthand flag panic message #1987

@mdhender

Description

@mdhender

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/flags-argsChanges to functionality around command line flags and argsgood-first-issueIssues that a new contributor could make a PR forlifecycle/needs-prReady for a PR from the community

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions