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

NoOptDefVal doesn't work with shorthand #136

Closed
rmasci opened this issue Aug 18, 2017 · 1 comment
Closed

NoOptDefVal doesn't work with shorthand #136

rmasci opened this issue Aug 18, 2017 · 1 comment

Comments

@rmasci
Copy link

rmasci commented Aug 18, 2017

var flagSet flag.FlagSet

flagSet.StringVarP(&creds, "user", "u", "", "Login Credentials: ")
flagSet.StringVarP(&passwd, "password", "p", "", "Password for User.")
flagSet.StringVarP(&lastname, "lastName", "f", "", "First Name"
flagSet.StringVarP(&lastname, "lastName", "l", "", "Last Name"
flagSet.Lookup("silent").NoOptDefVal = "Fred Flintstone"
...
When I run the program:
myProgram --firstName=Barney --lastName=Rubble -u brubble -p b3dr0ck,
it works.
When I run the program:
myProgram -f Barney -lastName Rubble -u brubble -p b3dr0ck,
This breaks things. All options past the -f will not be accepted and a value will not get assigned to firstName or lastName variable.s

@n10v
Copy link
Collaborator

n10v commented Sep 30, 2017

Yes, it's normal and it's documented:

--flag x // only on flags without a default value

Duplicate of #134.

@n10v n10v closed this as completed Sep 30, 2017
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

No branches or pull requests

2 participants