dry-rb / dry-rb/dry-cli

Mutually-exclusive arguments or options

Open
#128 0 comments 0 reactions 0 assignees View on GitHub
bug help wanted
Dominant language
Ruby
Stars
358
Forks
40
Avg merge
4d 12h
Merged PRs (30d)
1

Description

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](https://github.com/dry-rb/dry-cli/assets/16578570/bf9d4de6-5b15-4bb8-9e32-4ee197a73cae)

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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.