question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Accepting a single main parameter doesn't appear to be possible

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 12 years ago
  • Comments:21 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
rtomsickcommented, Apr 6, 2017

@trejkaz has a valid point.

Intuitively, if I write:

@Parameter(arity = 1)
public List<String> foo;

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 just List.

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…

0reactions
wallescommented, May 16, 2017

Thanks for fixing this @cbeust!

I just tried this in 1.72 and it works like a charm 😃

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found