Accepting a single main parameter doesn't appear to be possible
See original GitHub issueWe 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.
Issue Analytics
- State:
- Created 12 years ago
- Comments:21 (9 by maintainers)
Top Results From Across the Web
What happens if I don't pass a parameter in a Javascript ...
If you pass more parameters than are in the signature, you can use arguments . function myfunction(x) { alert(x); console.log(arguments); ...
Read more >Resolve the "Parameter validation failed" error in AWS ...
How do I resolve the "Parameter validation failed: parameter value 'abc' for parameter name 'ABC' does not exist" error in CloudFormation?
Read more >Use parameters to ask for input when running a query
You can set the parameter to accept only a certain type of data. It is especially important to specify the data type for...
Read more >Using Python Optional Arguments When Defining Functions
In this tutorial, you'll explore the techniques you have available for defining Python functions that take optional arguments. When you master Python ...
Read more >Create Parameters - Tableau Help
A parameter is a workbook variable such as a number, date, or string that can replace a constant value in a calculation, filter,...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@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…
Thanks for fixing this @cbeust!
I just tried this in 1.72 and it works like a charm 😃