Skip to content

[CLI-312] Inconsistent behaviour in key/value pairs (Java property style)#233

Merged
garydgregory merged 12 commits into
apache:masterfrom
Claudenw:CLI-312_fix
Feb 16, 2024
Merged

[CLI-312] Inconsistent behaviour in key/value pairs (Java property style)#233
garydgregory merged 12 commits into
apache:masterfrom
Claudenw:CLI-312_fix

Conversation

@Claudenw

@Claudenw Claudenw commented Feb 14, 2024

Copy link
Copy Markdown
Contributor

Fix for CLI-312 https://issues.apache.org/jira/browse/CLI-312

Solves issue where java property type option has a single value separated from the -D flag e.g "-D y" as was illustrated in pull request #189

closes #189

*/
private void checkRequiredArgs() throws ParseException {
if (currentOption != null && currentOption.requiresArg()) {
if (isJavaProperty(currentOption.getKey()) && currentOption.getValues().length == 1) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Claudenw
I think you are missing a test case to account for Option#getValues() returning null.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added test, and modified code to handle the case. Good catch.

@codecov-commenter

codecov-commenter commented Feb 15, 2024

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.94%. Comparing base (9f6b23b) to head (3e4c33c).
Report is 420 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master     #233      +/-   ##
============================================
+ Coverage     91.90%   91.94%   +0.04%     
- Complexity      575      582       +7     
============================================
  Files            22       22              
  Lines          1247     1254       +7     
  Branches        210      212       +2     
============================================
+ Hits           1146     1153       +7     
  Misses           63       63              
  Partials         38       38              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Claudenw Claudenw self-assigned this Feb 15, 2024

@garydgregory garydgregory left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Claudenw
TY for your update.
Please see my comments.

* @return the number of values this option has.
* @since 1.7.0
*/
int numberOfValues() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary IMO, especially since it is not public and only used once. See above.

*/
private void checkRequiredArgs() throws ParseException {
if (currentOption != null && currentOption.requiresArg()) {
if (isJavaProperty(currentOption.getKey()) && currentOption.numberOfValues() == 1) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of adding a method that's only used once, you can say instead currentOption.getValue() != null or currentOption.getValuesList().size() == 1

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I missed getValuesList() when I was implementing. I saw that getValues() would return null and that threw me off. Good catch.

@garydgregory garydgregory left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Claudenw
TY for your update.
One more comment...

}

@Test
public void testNoOptionValues() throws ParseException {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ParseException is not thrown by this method, please remove it from the method signature.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@garydgregory garydgregory changed the title CLI-312 fix [CLI-312] Inconsistent behaviour in key/value pairs (Java property style) Feb 16, 2024
@garydgregory garydgregory merged commit ce86213 into apache:master Feb 16, 2024
@Claudenw Claudenw deleted the CLI-312_fix branch February 19, 2024 08:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants