0

I am trying to port a CLI to use JCommander but my application allows for custom parameters to be passed on the command line like this:

 ./App.sh -u myusername -customparam1 customval1

In that case customparam1 is the name of the custom parameter and customval1 is its value. The user can pass an arbitrary number of such parameters and the names can be anything, e.g. customparam2, etc.

Is JCommander capable of parsing those type of parameters? I tried using Dynamic Parameters but there were two problems:

  • they appear to require a prefix before the parameter name, e.g. -Dcustomparam1, where D is the prefix
  • they require an assignment character such as = between the name and the value, and space will not work as the assignment character

Any suggestions about how to use JCommander for parsing these params?

Dave L.
  • 9,595
  • 7
  • 43
  • 69

1 Answers1

0

I found an undocumented configuration option acceptUnknownOptions that can used like so:

JCommander jc = JCommander.newBuilder().addObject(app).acceptUnknownOptions(true).build();
...
List<String> unknowns = jc.getUnknownOptions();

Dave L.
  • 9,595
  • 7
  • 43
  • 69