javaapachecommand-line-interfaceapache-commons-cli

Apache Commons CLI : Getting array of string values for an option


got a problem with Commons CLI 1.4 I need to parse unlimited values string Option like exmpl :

-fe .magnet .torrent (paramenter value starts with dot)

i create this Option via Option.builder()

Option fe = Option.builder().argName("fe").desc("bla bla").hasArgs().longOpt("fileextensions").build();

and next i add this to my Options object

options.addOption(fe);

then i parse this,i get a Exception

org.apache.commons.cli.UnrecognizedOptionException: Unrecognized option: -fe

how to make right way to parse two or more this parameters,separate via space-symbol?


Solution

  • it was easy, when we use a Option.builder(), we need to pass him a arg with 'opt' , my code works on :

    Option.builder("fe").desc("blabla").hasArgs().longOpt("fileextensions").build();