jcommander
jcommander copied to clipboard
expandDynamicArg expands nonDynamicArgs
If you have a parameter called -abc and a dynamic parameter -ab. -abc will be expanded to "-ab" "c"
And behold you'll get an exception since "c" is not a valid argument for dynamic parameter.
Checking if arg should be expanded/split https://github.com/cbeust/jcommander/blob/9f251415677106b683e4bbaf82123f0e5930cdce/src/main/java/com/beust/jcommander/JCommander.java#L472 "-abc".startsWith("-ab") && !"-abc".equals("-ab")
adding a validation that the assigment string exist in the arg should solve the problem.
if (arg.startsWith(name) && !arg.equals(name) && arg.contains(pd.getParameter().getAssignment()) {
But should probably be extracted to a method either in JCommander or a public boolean handlesArg(arg) in WrappedParameter which could handle the name validation and remove some of the nesting in expandDynamicArgs.