dry-cli icon indicating copy to clipboard operation
dry-cli copied to clipboard

Mutually-exclusive arguments or options

Open noraj opened this issue 1 year ago • 0 comments

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.

noraj avatar Jun 30 '23 18:06 noraj