Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Legacy parser should throw on optional List argument if not provided. #99

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

cmnbroad
Copy link
Collaborator

@cmnbroad cmnbroad commented Oct 5, 2017

@nh13
Copy link

nh13 commented Oct 5, 2017

@cmnbroad can the optional annotation just be removed?

@@ -423,13 +423,16 @@ private boolean checkNumArguments() {
}
if (optionDefinition.isCollection) {
final Collection<?> c = (Collection<?>) optionDefinition.field.get(optionDefinition.parent);
if (c.size() == 0 && !optionDefinition.optional) {
messageStream.print("ERROR: Option '" + fullName + "' is required");
return false;
Copy link

Choose a reason for hiding this comment

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

code not covered by tests

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed.

@@ -423,13 +423,16 @@ private boolean checkNumArguments() {
}
if (optionDefinition.isCollection) {
final Collection<?> c = (Collection<?>) optionDefinition.field.get(optionDefinition.parent);
if (c.size() == 0 && !optionDefinition.optional) {
messageStream.print("ERROR: Option '" + fullName + "' is required");
Copy link

Choose a reason for hiding this comment

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

instead of c.size() == 0, use c.isEmpty()

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed.

if (c.size() < optionDefinition.minElements) {
messageStream.println("ERROR: Option '" + fullName + "' must be specified at least " +
optionDefinition.minElements + " times.");
return false;
}
} else if (!optionDefinition.optional && !optionDefinition.hasBeenSet &&
!optionDefinition.hasBeenSetFromParent && mutextOptionNames.length() == 0) {
} else if (!optionDefinition.optional && !optionDefinition.hasBeenSet && mutextOptionNames.length() == 0) {
Copy link

Choose a reason for hiding this comment

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

length() -> isEmpty()

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

mutextOptionNames isn't a collection, its a StringBuilder. No isEmpty on that one.

@yfarjoun
Copy link
Contributor

yfarjoun commented Oct 5, 2017

@nh13 and make everything required? I don't understand the suggestion.

@nh13
Copy link

nh13 commented Oct 5, 2017

For non-collections, it's required if no value is set in the class. For collections, you use min/max elements anyhow. For options, you it's always optional (duh).

@nh13
Copy link

nh13 commented Oct 5, 2017

@yfarjoun see a similar implementation that does away the need for the optional annotation: https://github.com/fulcrumgenomics/sopt/blob/master/src/main/java/com/fulcrumgenomics/sopt/cmdline/ArgAnnotation.java

@cmnbroad
Copy link
Collaborator Author

cmnbroad commented Oct 5, 2017

There are still a couple of problems with these changes - pls hold off reviewing until its ready (I made the PR a bit prematurely - I didn't think it would get reviewed so fast!).

@codecov-io
Copy link

codecov-io commented Oct 5, 2017

Codecov Report

Merging #99 into master will increase coverage by 0.01%.
The diff coverage is 83.33%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master      #99      +/-   ##
============================================
+ Coverage     75.68%   75.69%   +0.01%     
  Complexity      576      576              
============================================
  Files            22       22              
  Lines          2159     2160       +1     
  Branches        447      447              
============================================
+ Hits           1634     1635       +1     
- Misses          350      351       +1     
+ Partials        175      174       -1
Impacted Files Coverage Δ Complexity Δ
...lay/argparser/LegacyCommandLineArgumentParser.java 75.31% <83.33%> (+0.05%) 123 <0> (ø) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e2320da...668253c. Read the comment docs.

@cmnbroad
Copy link
Collaborator Author

cmnbroad commented Oct 5, 2017

@nh13 We could get rid of the annotation, but then we'd have to propagate those changes to two parsers and all of the downstream projects....

@nh13
Copy link

nh13 commented Oct 5, 2017

@cmnbroad too bad we can't get rid of it, since it seems redundant. Your call, thanks for thinking about it.

@magicDGS
Copy link
Contributor

magicDGS commented Oct 6, 2017

@nh13 - I think that the optional field cannot be removed at the moment also because of #23

@cmnbroad cmnbroad added the 2.0 label Oct 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants