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

Parse optional short options like gnu getopt #82

Merged
merged 2 commits into from
May 17, 2019

Conversation

jridgewell
Copy link
Contributor

@jridgewell jridgewell commented May 16, 2019

Similar to #49, this changes the parsing of optional short options to require no space between the option and argument. Now, -aSomething parse as an option with argument, and -a Something will parse as a present flag with a free non-option.

Note that this only changes optional option arguments (when hasarg = Maybe, as in optflagopt). Required option arguments (when hasarg = Yes, as in optopt) still allow a space between the short option and its argument.

This is a breaking change.

Similar to rust-lang#49, this changes the parsing of short options to require no space between the option and argument. Now, `-aSomething` parse as an option with argument, and `-a Something` will parse as a present flag with a free non-option.

This is a breaking change.
It's no longer necessary.
@t-rapp
Copy link
Contributor

t-rapp commented May 16, 2019

As far as I can tell GNU Getopt accepts whitespace between flag and the argument. From the Getopt Manual Example section:

% testopt -c foo
aflag = 0, bflag = 0, cvalue = foo

% testopt -cfoo
aflag = 0, bflag = 0, cvalue = foo

As the non-space-separated variant looks similar to the case where multiple flags are concatenated (i.e. you can write -ab if both -a and -b is defined to as non-argument flags in GNU Getopt) I even prefer using -c foo over -cfoo.

@t-rapp
Copy link
Contributor

t-rapp commented May 16, 2019

On a second thought I recognize that this change is about flags with optional arguments. When I adjust the GNU Getopt example to use a double-colon for the c flag (so the option string becomes "abc::") then C getopt behaves as described in the commit message.

So if this change only affects optional arguments all looks fine for me. The string generated by Options.usage() should be made more clear in this case, though. See #67.

@jridgewell
Copy link
Contributor Author

Ha, yes, I forgot to put that this is only a change to optional option arguments! optopt will still behave the same, only optflagopt changes.

Copy link
Contributor

@KodrAus KodrAus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @jridgewell!

@KodrAus KodrAus merged commit baeaab6 into rust-lang:master May 17, 2019
@jridgewell jridgewell deleted the gnu-optional branch May 17, 2019 01:52
alexcrichton added a commit to alexcrichton/getopts that referenced this pull request Aug 19, 2019
This commit reverts three recent PRs to the `getopts` crate. One of the
main consumers of `getopts` is `rustc`, which isn't allowed to have
breaking changes. In rust-lang#82, however, a breaking change was landed. It
looks like rust-lang#83 builds on this change, and while rust-lang#81 seems unrelated the
diffs were somewhat tangled.
@alexcrichton alexcrichton mentioned this pull request Aug 19, 2019
alexcrichton added a commit that referenced this pull request Aug 19, 2019
alexcrichton added a commit that referenced this pull request Aug 19, 2019
Fixes a git mistake with #84
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.

3 participants