- Notifications
You must be signed in to change notification settings - Fork 18.5k
Open
Labels
NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
Description
Version: go1.13.5
I have a code snippet with a series of flags:
var ( flag1 string flag2 string ) func init() { flag.StringVar(&flag1, "flag1", "", "value for flag 1") flag.StringVar(&flag2, "flag2", "", "value for flag 2") } func main () { ... } After building, if this is executed in a bash shell:
./script "-flag1 value1" "-flag2 value2"
the output I see is this:
flag provided but not defined: -flag1 value1 Usage of ./script: -flag1 string value for flag1 -flag2 string value for flag2 Now, this code doesn't work because of the quotes in the bash command and removing the quotes makes this work exactly as expected. This took me a while to debug as I wasn't able to initially interpret from flag provided but not defined: -flag1 value1 that the program was interpreting -flag1 value1 as the literal flag, as opposed to the flag and the value.
I might suggest one of two fixes:
-
Slightly modify the error message from
flag provided but not defined: FLAG
to
flag "FLAG" provided but not defined -
Add logic to detect common potential mistakes such as:
flag provided but not defined: FLAG Did you mean to include <detected mistake such as space / equals sign etc>? dmitshur, AlfredBroda, brianonn, shved, 123BLiN and 11 more
Metadata
Metadata
Assignees
Labels
NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.