Strict command line parser

115 views Asked by At

in connection with this Apache command line parser (Since it is completely out topic). Is there a way to strictly follow the short hand. Like -m and not -multi or for long name it should be --multiply and not --multi?

Since, as per post, commons-cli (Apache) evaluates both -m and -multi as the same. What i was thinking is that only -m or --multiply should be accepted.

I am using Apache's Commons CLI (commons-cli-1.3.1)

1

There are 1 answers

0
lemoncodes On

for the information of everyone, i got an idea on how to go about this problem. take a look at this. I got the idea on the answers.

Basically what you want to do is extend the DefaultParser class and override parse() method, add some of your logic in checking args and process to DefaultParser's parse (via super.parse(...)). In that way you can retain the original behavior of DefaultParser whilst adding logics on top of it.

Hope this helps someone.

Credits to this answer @Artur Skrzydło