Search code examples
javacommand-line-interfaceapache-commonsapache-commons-cli

Apache CLI Argument and Options set up?


I'm having an issue properly setting up some options in Apache CLI.

I'm trying for something like this...

usage: ViewReport -r <file> -d <name> [-rp [arg1] [arg2] [arg3] ... ] [OPTIONS]
 -r <file>                Report path
 -d <name>                DB Config Name
 -rp <name|class|value>   list of report parameters
OPTIONS
-preview
....

I need the -rp option to have unlimited amount of args and each arg would be a comma delimited list of name,className,objectValue.

I can't figure how to configure my options to handle something similar to this for CLI to handle a list as input.

EDIT Lets say Args need to be a list item pair name=value


Solution

  • See my answer to unlimited option arguments here

    This is possible using

    Option.setArgs(Option.UNLIMITED_VALUES)
    

    Where the parameters to the options must be space separated. The rest (e.g. splitting up the args) is up to you