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

Support multiple option values #1705

Open
jamerst opened this issue Dec 1, 2024 · 0 comments
Open

Support multiple option values #1705

jamerst opened this issue Dec 1, 2024 · 0 comments

Comments

@jamerst
Copy link

jamerst commented Dec 1, 2024

Is your feature request related to a problem? Please describe.
Currently multiple values per option are not supported, e.g. --option value1 value2.

Trying to add an option with a template like this (e.g. [CommandOption("--option <value1> <value2>")]) results in a "Multiple option values are not supported" error.

This is the only thing preventing me from migrating from System.CommandLine, which supports this feature by allowing you to define the arity of an option: https://learn.microsoft.com/en-us/dotnet/standard/commandline/syntax#argument-arity.

Describe the solution you'd like
Allow defining multiple option values via the template. Ideally it would validate/enforce the arity (so with the example template above it would be mandatory to provide two values).

It could also allow repeated values under a single option flag (so you could run --option value1 value2 value3 value4 instead of --option value1 value2 --option value3 value4). This might be problematic though, it could get awkward and create unexpected results for users since you would need to somehow terminate the option so it knows when to stop capturing values.

Describe alternatives you've considered

  • Option arrays - I can't use this because I have an array typed command argument, so that captures the option values instead
  • IDictionary/ILookup typed options - this is my current workaround, but it's not ideal because this creates a breaking change in my application as the values have to be separated with an equals now instead of a space. There also doesn't appear to be a way to escape the equals, so it breaks if you provide a value that contains one.

Additional context
I only found out about the IDictionary/ILookup solution from another issue - it would be good to include this alongside more detail on the template syntax in the documentation!


Please upvote 👍 this issue if you are interested in it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Todo 🕑
Development

No branches or pull requests

1 participant