I would recommend writing it in a more reusable way. The fact that all parameters must be set must not be hardcoded into the logic of the parameter parser. You should just check it out at the end, just before you โcontinue your restโ.
In such cases, I usually do the following:
First of all, for each of the possible arguments, I have some variables that contain reasonable default values โโ(so that the argument can be omitted), a trivial example of which would be bool argument_x_given = false;
So, I loop around the given arguments, and inside the loop I check the current argument against each of the possible arguments to find what it is. If not found, we have an error. If a suitable argument is found, I analyze the rest of the argument (the material after the ":"), and I set the variables associated with the argument. By doing this, I verify that the argument does not duplicate. In this trivial example, it will be if( argument_x_given ) { --error-- } else { argument_x_given = true; ... } if( argument_x_given ) { --error-- } else { argument_x_given = true; ... } .
Finally, as soon as the loop is finished, I make sure that all the necessary arguments have been specified.
So, Iโm trying to say that you wonโt gain anything by comparing arrays of strings, because you still have to understand each of your arguments, and also comparing string arrays is like trying to take advantage of a situation that is very specific to this problem and cannot reused.
source share