-
Notifications
You must be signed in to change notification settings - Fork 6
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
Factor out ArgumentDefinition classes and refactor CommandLineArgumentParser. #133
Conversation
For @jonn-smith (or @droazen) or whoever can get to it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few comments / minor changes.
Looks pretty good. There was a lot of code, so I'm a little worried I didn't see into some details.
I found the parts where you grab a base field collection and modify it in place a little confusing, but it makes sense.
src/main/java/org/broadinstitute/barclay/argparser/ArgumentDefinition.java
Outdated
Show resolved
Hide resolved
} | ||
} catch (final Exception ex) { | ||
// Note: I assume this catches Exception to handle the case where the type is not instantiable | ||
// TODO: Can't we just throw when this happens ?? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering the same thing as this TODO
. Should we still try to run if the field can't be set properly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The parser tries to auto-create a collection instance of the declared type if the argument field doesn't already have one. If that fails, it catches Exception and falls back to trying to create an ArrayList. If not for the backward compatibility issue, I would require the coder to create the collection, and just let it throw. But I suspect there is code that relies on this behavior. I'll remove that TODO and fix the comment (I originally added it as a note to myself when I was refactoring).
* @return never {@code null}. | ||
*/ | ||
@SuppressWarnings({"unchecked","rawtypes"}) | ||
protected static String getOptions(final Class<?> clazz) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it maybe worth having a way to include some example options for String
arguments as well? The implementation would need to fill out this example string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That might be a good idea, but I'd prefer not to introduce any additional new features is a separate PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good. Can you add this in as a new issue (if you haven't already)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done #144. For the record, I also changed the getOptions
method from a static method to an instance method to make it easier to implement this request when we do so, and renamed it to getOptionsAsDisplayString
to better reflect what it does.
src/main/java/org/broadinstitute/barclay/argparser/CommandLineArgumentParser.java
Outdated
Show resolved
Hide resolved
src/main/java/org/broadinstitute/barclay/argparser/CommandLineArgumentParser.java
Outdated
Show resolved
Hide resolved
src/main/java/org/broadinstitute/barclay/argparser/NamedArgumentDefinition.java
Show resolved
Hide resolved
src/main/java/org/broadinstitute/barclay/argparser/PositionalArgumentDefinition.java
Outdated
Show resolved
Hide resolved
src/test/java/org/broadinstitute/barclay/argparser/CollectionArgumentUnitTests.java
Outdated
Show resolved
Hide resolved
src/test/java/org/broadinstitute/barclay/argparser/CommandLineArgumentParserTest.java
Show resolved
Hide resolved
src/test/java/org/broadinstitute/barclay/argparser/TaggedArgumentTest.java
Outdated
Show resolved
Hide resolved
Codecov Report
@@ Coverage Diff @@
## master #133 +/- ##
============================================
+ Coverage 76.07% 76.56% +0.49%
- Complexity 593 669 +76
============================================
Files 22 26 +4
Lines 2215 2296 +81
Branches 457 455 -2
============================================
+ Hits 1685 1758 +73
- Misses 352 366 +14
+ Partials 178 172 -6
Continue to review full report at Codecov.
|
@jonn-smith I think I responded to all your comments. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One minor bookkeeping request (adding in an issue if it doesn't already exist for my comment in ArgumentDefinition.java
).
After that it looks good to merge.
* @return never {@code null}. | ||
*/ | ||
@SuppressWarnings({"unchecked","rawtypes"}) | ||
protected static String getOptions(final Class<?> clazz) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good. Can you add this in as a new issue (if you haven't already)?
src/main/java/org/broadinstitute/barclay/argparser/CommandLineArgumentParser.java
Show resolved
Hide resolved
src/main/java/org/broadinstitute/barclay/argparser/LegacyCommandLineArgumentParser.java
Show resolved
Hide resolved
src/main/java/org/broadinstitute/barclay/argparser/NamedArgumentDefinition.java
Show resolved
Hide resolved
@cmnbroad Looks good! Merge away. |
CommandLineArgumentParser refactoring. Extract classes for positional and named argument definitions with common ArgumentDefinition base class. All GATK and Picard tests have passed with these changes (Picard requires no source changes, GATK changes corresponding to the gatherFieldValuesOfType changesr are in broadinstitute/gatk#4523).
Fixes:
Additional fixes:
Prerequisite for:
Existing tests will be refactored is a separate PR.