feat: add require no space to argument short version #5489
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix #3030.
This PR enables restricting the short option to the
-oval
syntax with therequire_no_space
argument setting, and changesrequire_equals
to only affect the long option--option=val
(BREAKING CHANGE). This will allow compliance with the POSIX and GNU conventions as mentioned in the issue by setting bothrequire_no_space
andrequire_equals
to true:Here is an example help message that demonstrates this:
A specific real-world application that has motivated this is uutils/coreutils which aims to mirror the GNU version as closely as possible. However, their
date -I/--iso-8601
implementation, for example, accepts values that are not considered valid (e.g.date -I seconds
anddate -I=seconds
), and there is no possible workaround.The changes made to
require_equals
may break current applications that take a positional argument after an optional option-argument, e.g.Currently
cmd
would be treated as the second argument, but after the PR whererequire_equals
no longer works on short option, it will become the associated value to the first.Migration to the new major version (if this is merged) should complement
require_equals
withrequire_no_space
and replace-o=val
usage with-oval
, otherwise the associated value would become=val
as=
is parsed as part of the value.