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

Mutually-exclusive arguments or options #128

Open
noraj opened this issue Jun 30, 2023 · 0 comments
Open

Mutually-exclusive arguments or options #128

noraj opened this issue Jun 30, 2023 · 0 comments

Comments

@noraj
Copy link

noraj commented Jun 30, 2023

Feature request : In some cases it's required to have mutually-exclusive arguments or options.

For example if I have a program that will convert coordinates to a player name or a player name to its coordinates. I want to either have 1 argument (name) or two arguments (coodinate X and coordinate Y). Pseudo usage: program convert (name | coord_x coord_y).

Same for options, for example for git pull you can't have --ff-only and --no-ff or --ff-only and --rebase at the same time.

Example with docopt:

image

The workaround that is heavy is to provide two sub-sub-commands to the convert sub-command, one that converts from name to coords with one required argument and a second sub-sub-command that converts coords to name with 2 required arguments.

Another workaround is to use one unique and generic array argument name args and then counts the number of entries in it, if only one it's the name if two those are the coords. But the description should explain logic and behavior as well as the description of all three arguments in one, that also wouldn't work if the two mutually exclusive arguments has the same number of entries.

Another workaround is to use three options instead with none as required but of course this will end into errors if none is provided or if only 1 coord is provided or if one corod and a name if provided.

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

1 participant