jcommander: Accepting a single main parameter doesn't appear to be possible
We only support opening a single case at a time, so I figured I would just use this for accepting the location as the main parameter:
@Parameter(descriptionKey = "DesktopMainArguments.docLocation")
public File docLocation;
Attempting to parse then throws the following exception:
com.beust.jcommander.ParameterException: Main parameter field public java.io.File com.acme.main.MainArguments.docLocation needs to be of type List, not class java.io.File
I’m sure I could change it to a list, but then I would have to put in boilerplate to check that the user hasn’t specified more than one. Is there a proper way to do this directly? Because I can’t seem to find it in the examples or in the API.
I thought validation might be the way to do it, but I suspect I was wrong about that because the validator receives the original command-line string, not the final converted object.
About this issue
- Original URL
- State: closed
- Created 13 years ago
- Comments: 21 (9 by maintainers)
Commits related to this issue
- Support arity for main parameters. Partial fix for https://github.com/cbeust/jcommander/issues/90 — committed to cbeust/jcommander by deleted user 7 years ago
@trejkaz has a valid point.
Intuitively, if I write:
I would expect at most one entry in
foo. That doesn’t happen now (in direct contradiction of the JavaDoc, FWIW.)Even better would be allowing
@Parameter(arity = 1)to apply to any type, not justList.Yes, it is possible to work around this now, but DRY is a valid concern. There’s no good reason to make the caller write the same validation code every time for what is actually a pretty reasonable use case…