Skip to content

Add support for repeatable array options#159

Open
Drowze wants to merge 1 commit into
dry-rb:mainfrom
Drowze:rg-repeatable-array-options
Open

Add support for repeatable array options#159
Drowze wants to merge 1 commit into
dry-rb:mainfrom
Drowze:rg-repeatable-array-options

Conversation

@Drowze

@Drowze Drowze commented Jul 9, 2026

Copy link
Copy Markdown

Support repeatable :array options (in addition to comma-separated)

E.g.:

# Given that `my_app` has `api` command taking a `--header` array option
# $ my_app api /some/path \
#     --header 'content-type: application-json' \
#     --header 'accept: application/json'

# Before:
options[:header] # => ["accept: application/json"]

# After:
options[:header] # => ["content-type: application-json", "accept: application/json"]

Related:

Support repeatable :array options (in addition to comma-separated)

```
option :deps, type: :array

 # Before
--deps=foo --deps=bar
options[:deps] # => ["bar"]

 # After
--deps=foo --deps=bar
options[:deps] # => ["foo", "bar"]
```
@Drowze Drowze mentioned this pull request Jul 9, 2026
4 tasks
@katafrakt

Copy link
Copy Markdown
Contributor

I very much like the direction and I was missing ability to specify API like curl's multiple -H . However, I have a nit about the semantics here. This can be seen in the example you added in tests:

server --deps=dep42 --deps=dep43

I believe what would be desired in reality is to have either plural and comma-separated, or singular multiple times. So:

server --dep=dep42 --dep=dep43
# or
server --deps=dep42,dep43

This makes me think they are not, in fact, interchangeable. Maybe instead of reusing :array type we should have :multiple flag/type here?

Please, don't take it as a change request straight away. I'd like it to be discussed first.

@Drowze

Drowze commented Jul 21, 2026

Copy link
Copy Markdown
Author

Hey @katafrakt, thanks a lot for the thoughtful feedback! 😄

My intention indeed was to mimic other common CLI tools - so definitely no coincidence that this is very similar to curl. Glad you've noted and liked this direction as well!

believe what would be desired in reality is to have either plural and comma-separated, or singular multiple times

I can see where you're coming from... Indeed the example with repeatable pluralized options is a bit unfortunate.

Also, not sure if that's what you suggested, but having an actual decent pluralization built-into array types would probably be tricky, so my vote would be against that direction (and options already support aliases btw, so I don't see a good reason to have inflection support built into dry-cli).

This makes me think they are not, in fact, interchangeable. Maybe instead of reusing :array type we should have :multiple flag/type here?

Funny you mentioned that :) my initial implementation was using a new :repeatable flag. The main reason me to change the direction and re-use the :array type is that I wasn't sure how to display the description of repeatable options (in the "command banner" e.g. when calling a command with --help).

For context: I didn't want to inadvertently make the description too big (especially since dry-cli does not have any "auto-wrapping" on the banner) so, with that in mind, my solution in that original branch was to simply append a (repeatable) to the description of those options.
I was a bit on the fence about how it turned out though, which is why in the end I've decided to open this pull request simply reusing the :array type (to avoid worrying about descriptions 😅 )

Here's my original solution using a :repeatable flag: main...Drowze:dry-cli:rg-support-repeatable-options
Please let me know your thoughts on it! I have no objections on closing this PR and re-opening from that branch if you prefer to 👍

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants