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.

Parameters must be prefixed with - or --

See original GitHub issue

This is not mentioned in the documentation and the error message isn’t obvious.

Demonstration code:

class P1 {
    @Parameter(names = "hello")
    private int test;
}
P1 p1 = new P1();
JCommander j = new JCommander(p1);
j.parse(new String[]{"hello", "47"});
System.out.printf("command %s, test %d\n", j.getParsedCommand(), p1.test);

Raises:

Exception in thread "main" com.beust.jcommander.ParameterException: Was passed main parameter 'hello' but no main parameter was defined
    at com.beust.jcommander.JCommander.getMainParameter(JCommander.java:914)
    at com.beust.jcommander.JCommander.parseValues(JCommander.java:759)
    at com.beust.jcommander.JCommander.parse(JCommander.java:282)
    at com.beust.jcommander.JCommander.parse(JCommander.java:265)
    at test.main.main(main.java:18)

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
cbeustcommented, Jan 4, 2017

Indeed, feel free to send a PR for the documentation.

Speaking of documentation, I’d also like to update the CSS so we can have the table of contents on the side and in a fixed position instead of at the top where it takes up most of the first screen before your scroll.

0reactions
cbeustcommented, Jan 24, 2017

Fixed in 1.61. Here is a version of your code above that works:

  static class P1 {
    @Parameter(names = "hello")
    private int test;
  }

  public static void main(String[] args) {
    P1 p1 = new P1();
    JCommander j = new JCommander();
    j.addCommand("p1", p1);
    j.parse(new String[]{"p1", "hello", "47"});
    System.out.printf("command %s, test %d\n", j.getParsedCommand(), p1.test);
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Function parameter name with "In" prefix?
I understand the “Out” prefix for parameter name, but what does “In” prefix mean? There is no info about it in Coding Standards...
Read more >
Why am I getting an error when querying SSM parameters via ...
The parameter name must begin with a forward slash "/". It can't be prefixed with "aws" or "ssm" (case-insensitive). It must use only...
Read more >
What are the benefits of prefixing function parameter names ...
Even if you needed such number of variables - they should use meaningful names and the prefix is standing between you and the...
Read more >
CA1715: Identifiers should have correct prefix (code analysis)
Learn about code analysis rule CA1715: Identifiers should have correct prefix.
Read more >
clish / Discussion / Help: Problem with "Prefix" - SourceForge
So rather then just loop from 0 - paramc it should look for all the prefix parameters and do completion on those first....
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