Custom handling of positional parameters
See original GitHub issueI would like to support some rich syntax with my CLI tool. I would like to allow the user to not only pass in a list of integers as positional arguments, but ranges of integers. I also don’t want to limit them on how these parameters are mixed together with the others.
Example:
foocli 1 2 4 6 8
Passes in the integer array [1,2,4,6,8] as positional arguments
foocli 1 3-5 2, 8
Passes in the integer array [1, 3, 4 5, 2, 8] as positional arguments.
I would ultimately like to support any range of numbers in any positional argument.
I know this is a rather special-purpose feature and that I can implement it myself using a list of string positional parameters, which I convert to integers myself. Any ideas on how to support it using a mix of picocli features and custom code would be nice.
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (8 by maintainers)
I’m thinking the
@Unmatched
idea was also a workaround to begin with. What you really want is to be able to parse input that is a mixture of simple scalars and range expressions. I had another idea: why not use a custom converter?Declare the field as a set of sets:
And flatten the set in the application:
Let me take a look…