Commons CLI : recognize file name *.deca

277 views Asked by At

I'm trying to use Apache Commons CLI to recognize the arguments of my java program. So, there is a bunch of options (such as "-p" as en example) but mostly, there is the name of the file that should be used as an input for the java program. Note that all options have no order restriction.

Example of the launch of the program :

decac -p -r 5 test.deca

I have no problems parsing the -p and -r (with argument "5") options but how do I create an option for "test.deca" knowing that it can be anything. It could also be something like pathTo/anotherTest.deca

1

There are 1 answers

1
DrHopfen On

I think it is not possible out-of-the-box with ApacheCommonsCLI. You could do some tricks according to this answer or you can use an argument option as described in the apache CLI documentation

Option decafile   = OptionBuilder.withArgName( "file.deca" )
                            .hasArg()
                            .withDescription(  "target deca file" )
                            .create( "decafile" );

That can be used later on with -dfile.deca or --decafile=file.deca