Search code examples
javaapache-commons-cli

Getting arbitrary key/value parameters with Apache Commons CLI


A framework I'm using (and can change if necessary, but would rather not) is using Apache Commons CLI. My application needs to acquire a series of well-defined arguments, but also in some cases accept a series of key/value pairs. These will eventually end up being injected into a Spring context that the application starts.

Any suggestions on the best way of getting a series of key/value pairs as one String option using Commons CLI?


Solution

  • i would probably handle them as additional arbitrary strings via CommandLine.getArgs(). You then can still define all the default options and parse the key/value-pairs afterwards.