Skip to content

Commit

Permalink
Revert "[remkop#1303] Bugfix: Prevent `IllegalArgumentException: argu…
Browse files Browse the repository at this point in the history
…ment type mismatch` error in method subcommands with inherited mixed-in standard help options"

This reverts commit e5b6320.
  • Loading branch information
MarkoMackic committed Oct 17, 2021
1 parent 2d3c959 commit 8e0e017
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 22 deletions.
1 change: 0 additions & 1 deletion RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ Picocli follows [semantic versioning](http://semver.org/).


## <a name="4.6.2-fixes"></a> Fixed issues
* [#1303] Bugfix: Prevent `IllegalArgumentException: argument type mismatch` error in method subcommands with inherited mixed-in standard help options. Thanks to [Andreas Deininger](https://github.com/deining) for raising this.
* [#1300] Bugfix: Avoid spurious warning "Could not set initial value for field boolean" when reusing `CommandLine` with ArgGroup. Thanks to [Yashodhan Ghadge](https://github.com/codexetreme) for raising this.
* [#1296] DOC: add Kotlin code samples to user manual; other user manual improvements. Thanks to [Andreas Deininger](https://github.com/deining) for the pull request.
* [#1299] DOC: Link to `IParameterPreprocessor` from `IParameterConsumer` javadoc. Thanks to [Andreas Deininger](https://github.com/deining) for the pull request.
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/picocli/CommandLine.java
Original file line number Diff line number Diff line change
Expand Up @@ -6937,8 +6937,7 @@ public Set<String> names() {
public List<ArgSpec> args() { return Collections.unmodifiableList(args); }
Object[] commandMethodParamValues() {
Object[] values = new Object[methodParams.length];
CommandSpec autoHelpMixin = mixins.get(AutoHelpMixin.KEY);
int argIndex = autoHelpMixin == null || autoHelpMixin.inherited() ? 0 : 2;
int argIndex = mixins.containsKey(AutoHelpMixin.KEY) ? 2 : 0;
for (int i = 0; i < methodParams.length; i++) {
if (methodParams[i].isAnnotationPresent(Mixin.class)) {
String name = methodParams[i].getAnnotation(Mixin.class).name();
Expand Down Expand Up @@ -7157,7 +7156,6 @@ public CommandSpec negatableOptionTransformer(INegatableOptionTransformer newVal
public CommandSpec mixinStandardHelpOptions(boolean newValue) {
if (newValue) {
CommandSpec mixin = CommandSpec.forAnnotatedObject(new AutoHelpMixin(), new DefaultFactory());
mixin.inherited = this.inherited();
addMixin(AutoHelpMixin.KEY, mixin);
} else {
CommandSpec helpMixin = mixins.remove(AutoHelpMixin.KEY);
Expand Down
18 changes: 0 additions & 18 deletions src/test/java/picocli/InheritedOptionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -525,22 +525,4 @@ public void testIssue1159ParseResult() {
assertFalse("Not matched on the parent command",
parseResult.hasMatchedOption("--xxx-yyy"));
}


@Test
public void testIssue1303InheritCommandWithMethodSubcommands() {
@Command(scope = INHERIT, mixinStandardHelpOptions = true)
class InheritApp {
int subCalled;

@Command()
void sub(@Option(names = "-foo") int foo) {
subCalled = foo;
//System.out.printf("Foo: %d", foo);
}
}
InheritApp app = new InheritApp();
new CommandLine(app).execute("sub", "-foo", "42" );
assertEquals(42, app.subCalled);
}
}

0 comments on commit 8e0e017

Please sign in to comment.