Skip to content

Conversation

@roelandschoukens
Copy link

Add an option terminator to option styles. If not empty, this changes the parsing in the following ways:

  • Initially, arguments are not allowed to start with an option prefix;
  • unknown options will trigger a parse error;
  • after the specified terminator is encountered, all remaining tokens will be plain arguments;
  • the parser still tolerates "--" prefixes as option values. It has this in common with Python's argparse, but POSIX parsers tend to also error out with a "no option value provided" error.

Having this terminator is not entirely backwards compatible, in particular it becomes cumbersome to pass in negative numbers as arguments. This is a known problem for POSIX style parsers. This commit therefore defines a new style for POSIX with terminator.

The detection of the "--" token is implemented in the token iterator, after encountering this token it will no longer return valid tokens from its option() function.

Add an option terminator to option styles. If not empty, this changes the parsing in the following ways:
 - Initially, arguments are not allowed to start with an option prefix;
 - unknown options will trigger a parse error;
 - after the specified terminator is encountered, all remaining tokens will be plain arguments;
 - the parser still tolerates "--" prefixes as option values. It has this in common with Python's
   argparse, but POSIX parsers tend to also error out with a "no option value provided" error.

Other change:
 - Unnamed arguments must be separated from a group of short options: the "abc" token in "-vabc" cannot be interpreted as an unnamed argument, unless -a, -b and -c options are defined this will now result in an error.

Having this terminator is not entirely backwards compatible, in particular it becomes cumbersome to pass in negative numbers as arguments. This is a known problem for POSIX style parsers.
This commit therefore defines a new style for POSIX with terminator.
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.

1 participant