cbeust / jcommander

Command line parsing framework for Java
Apache License 2.0
1.96k stars 334 forks source link

List parameter overwrite not as expected #443

Open cristiantoader opened 6 years ago

cristiantoader commented 6 years ago

Hello,

Thank you for your awesome library! It fits almost perfect all the use cases that I need, but unfortunately I came across a small inconsistency that I cannot work around.

I am not sure if this is intended behavior or not, but the issue is that I cannot overwrite list parameters. What happens instead is that the values that should overwrite are instead appended to the list.

For example "-bars", "b1,b2,b3", "-bars", "b4" would result in the list containing [b1, b2, b3, b4] instead of the expected b4.

I created a small junit test for this case in the following repo link.

Is this intended behaviour? Can you please provide feedback if this needs to be fixed?

Best regards, Cristian

zentol commented 6 years ago

The behavior seems to be in line with the documentation: http://jcommander.org/#_lists

cebaa commented 6 years ago

@zentol On the flip side, that does not mention the case where allowParameterOverwriting is set to true. In fact, there's not a single mention of allowParameterOverwriting in the docs...

@cristiantoader It seems to me that allowParameterOverwriting parameter is a bit of an afterthought and doesn't really play well with other things for that reason. For example, forceNonOverwritable struck me as a bit strange: using force and non together in a variable name just begs for the question whether it should be designed somewhat differently. As is always the case, it probably seemed like the best idea at the time :)

I guess the solution for now is to take in a String and split it manually...