mardi 22 décembre 2020

How to design a cli option combination handler in java?

I have the necessity to execute some functions based on a particular cli combination options (i use the apache commons cli library).

myprogram -a -b -c
myprogram -a -c
myprogram -d

To manage this situation, i have a very long list of "else if" based on a particular combination, all in my main function:

if (line.hasOption('a') && line.hasOption('b') && line.hasOption('c')){
   method1();
   method2();
 }
else if (line.hasOption('a') && line.hasOption('c')){
    method4();
 }
else if (line.hasOption('d')){
    method1();
    method4();
 }
....

There is a better way to design this? (by using some design pattern for example).

I'll appreciate any suggestions people have. Thanks.

Aucun commentaire:

Enregistrer un commentaire