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

Possibility to make an "option group" where the user has to use exactly one of the options in the group #66

Closed
pheiberg opened this issue Mar 4, 2013 · 5 comments

Comments

@pheiberg
Copy link

pheiberg commented Mar 4, 2013

When creating an application that has a group of options of which one must be given and only one of them can be given at a time, there is currently no way to do that. MutuallyExclusiveSet and Required can't be used together.

Example: I have an application where the user either can process files using
MyApp --files myfile.txt
or get a list of possible languages to use to process the files
MyApp --list-languages
or get a list of available plugins
MyApp --list-plugins
etc

Using more than one option or none of them would render an error.

A verb based approach could solve it, but seems wrong since the applications only real command is to process files and the rest of the command would just be some sort of help commands.

The Plossum Command Line Parser is using the notion of OptionGroups, where a group can have a setting of:

  • None
    This is the default, and it means that no restrictions are placed on the options in this group (other than those explicitly specified for each option)
  • AtMostOne
    This indicates that at most one of the options contained within this group must be specified. It means that either none of the options in the group, or one of the options in the group may be specified, but no more.
  • AtLeastOne
    This indicates that at least one of the options contained within this group must be specified, i.e. one or more options from this group must be specified.
  • ExactlyOne
    This indicates that exactly one option from this group must be specified, no more and no less.
  • All
    Indicates that all options from this group must be specified on the command line.

This would be a good way to solve it IMO.

Another alternative I can think of - off the top of my head - would be to allow MutuallyExclusiveSet and Required to be combined. An option with Required would then cause it's MutuallyExclusiveSet to be required instead of the option.

A stackoverflow question on this issue is posted here.

@gsscoder
Copy link
Owner

gsscoder commented Mar 4, 2013

Again @pheiberg thanks for posting the issue.

Issue contributes to make the library better (implying that issue will be fixed...) and so are always welcome.

This is issue was filed under enhancement, because this is a known behavior; also if not enough to describe your syntax.

Thanks for the reference, I'll read it. It' always good know what other do...

At glance
As a short reply (if my posts could be categorized this way...), I see in your last proposal a way of doing things perfectly aligned with the current philosophy.

A bit more in depth
Following the the idea to combining two behaviors, I'd say that a problem exists (to be honest). Since you can already combine it, an exception should be thrown to warn that X with Y should not be combined.

This is one of the key reason that have me brought to heavily refactoring the kernel and try to adhere some functional principles; but the second point is in its earliest stages. :))

Going ahead, I'm agree that such behaviour should be semantically supported by the parser (no exception -> we will be implemented).

Conclusion
Required will work as always, but when combined with MutuallyExclusiveSet it will be scoped to the matching set.

C/C: @nemec @mizipzor (main contrib. opinion appreciated)

@gsscoder
Copy link
Owner

gsscoder commented Mar 5, 2013

I want to add one thing, since its an enhancement, fixing will be delayed until some refactorings occur in persing kernel.

Anyway we're a talking of very limited amount of time.

As you can see all enhancement are freezed during this time.

Metrics: we're taliking of days not months!!!

@gsscoder
Copy link
Owner

Work is not stopped, please read https://github.com/gsscoder/commandline/wiki/Official-Roadmap

@gsscoder
Copy link
Owner

@pheiberg Check PRs this should be solved as now.

If you're satisfied, please let me if I can close this issue.

Thanks.

@gsscoder gsscoder removed this from the 2.0.x-beta milestone Aug 7, 2015
@alexanderfast
Copy link
Collaborator

Considering the lack of activity, it's time to close this (just reopen if need be).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants