-
Notifications
You must be signed in to change notification settings - Fork 19
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
Support more argument forms #9
Comments
Explicit options ending and interlacing arguments and options sound useful. As for negative options: the reason they are there are to allow option reset when using setting hierarchies. If for example certain option is set on by default (either in factory defaults or plist files), then there's no means to reset it to off in command line (or other higher priority setting in hierarchy). With that in mind, if they are truly undesirable in certain case, I'd keep negative variant by default and require explicit action to suppress it. As for API, instead of adding additional method, I'd add new GBValueRequirement flag for that. Note that any change on |
Great! I’ll start working on those!
My use case is that I want only the negative flag to couple with another flag. Let’s say I want to build a syntax highlighter that format code blocks with HTML highlighting. I want a option that specifies the theme:
If the option is omitted, I want to default to a factory value, e.g. this
is semantically equal to
But the user can also explicitly disable styling like this:
So there should be a required option But now that I though about this, maybe the right way to do this is to make the requirement a bitmask ( typedef NS_OPTIONS(NSUInteger, GBValueFlags) {
GBValueSwitch = 0, // The positive option should always exist; this is just for readability.
GBValueNegativeSwitch = 1, // The lowest bit is used to set whether a negative flag should exist.
GBValueRequired = 1 << 1,
GBValueOptional = 2 << 1,
GBValueNone = GBValueSwitch | GBValueNegativeSwitch
}; This way the above can be merged into a |
Some proposals about additional argument forms that can be supported:
Syntax to explicitly signal end of options
If a non-option argument needs to start with
-
, we need a way to tell the parser to explicitly treat it that way. To solve this, it is common to use a special option (usually-
or--
) to signal end of options. So for the following:will be parsed as
Interlacing arguments and options
Many applications accept a more permissive argument form, like this:
while GBCli currently requires it to be written as
instead.
I think this can be implemented quite easily. Currently the parser terminates parsing immediately when a non-option argument is met. If this is not the case, interlacing can happen.
Means to add auto-creation of negative variant
The negative variant of
GBValueNone
options is nice, but there are times when that is not really wanted. How about an extra method to let the user specify explicitly whether the negative variant should be created?I’m not sure how this should be implemented though. Maybe something like
Looking forward to hear how you feel about these improvements. I have tried to implement the interlacing feature. Although not thoroughly tested yet, I think it works. If you feel okay with the above I’ll start working on the other parts and submit a pull request afterwards.
The text was updated successfully, but these errors were encountered: