Open twwwt opened 2 years ago
This is reproducible even if the arity is left at the default of -1
. The logic keeps flipping the boolean. Seems like this should either:
If this bug still exists on JCommander 1.83 please post a unit test here which proofs your claim. Thanks.
Consider the following argument definition:
Current Behavior
If the Boolean argument is used repeatedly on the command line (i.e., more than once), its effective Boolean value flips with every repetition:
While the first two lines work as expected, starting from the third line (where
-y
occurs twice), the effective value ofdryRun
flips with every repetition of-y
. This is independent of whether the argument is repeated in direct succession (as is done in the example) or whether other arguments occur in-between repetitions.Expected Behavior
As an immediate remedy, jCommand should consider arguments to be non-repeatable by default and thus reject repeated use of the same argument by throwing an exception when parsing the command line.
Looking at the problem more generally, it occurs to me that the
@Parameter
annotation of jCommand needs to be extended with a Boolean parameter, let's call itrepeatable
, that allows to specify whether an argument can occur repeatedly on the command line. The default of that parameter should befalse
(i.e. it may not be repeated).