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

Single dash long options if no shorthand defined. #146

Closed
wants to merge 2 commits into from

Conversation

b1v1r
Copy link

@b1v1r b1v1r commented Oct 24, 2017

I have had issues migrating from https://github.com/koding/multiconfig or other https://golang.org/pkg/flag/ based configuration to pflag. This is because existing users were using the long options with a single dash (-option vs --option). The pflag package does not seem to support this and just errors trying to interpret these as shorthand options (e.g., -option => -o -p -t -i -o -n).

To allow easier migration when not using the shorthand option feature, I made a small change to interpret single dash options as double dash options when no shorthand options are defined. This seemed the least intrusive and did not seem to mess up anyone using shorthand options while truly making this a drop-in replacement for the flag package which it was not really before due to this.

  This allows more backwards compatibility with the flag package
  and easier switching from packages like multiconfig.
@b1v1r
Copy link
Author

b1v1r commented Feb 14, 2018

Just a ping on this. Any comments?

@moorereason
Copy link

Your PR literally breaks the whole point of this package, and I can't imagine why the maintainers would merge it. Drop-in replacement for the flag package is talking about the API, not the argument parsing algorithm.

@stevenroose
Copy link

I agree with @moorereason that this is not a desired feature.

@b1v1r b1v1r closed this Mar 7, 2018
@NDagestad
Copy link

NDagestad commented Jan 28, 2022

Digging up a very old and closed PR to say that the README should be updated.
It explicitly states that

pflag is a drop-in replacement of Go's native flag package. If you import pflag under the name "flag" then all code should continue to function with no changes.

Which it clearly does not since options aren't parsed as they were with flag.
I am not saying pflag need to support this, but things need to be clear.

Edit:
And to moorereason the readme states that the package is a drop in replacement adding POSIX style --options, not that it follows the POSIX behaviour only and rigorously

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 this pull request may close these issues.

4 participants