Skip to content

Commit

Permalink
Revert "[remkop#1331] Bugfix for scope = INHERIT:"
Browse files Browse the repository at this point in the history
This reverts commit 01fab04.
  • Loading branch information
MarkoMackic committed Oct 17, 2021
1 parent 7a7e0f1 commit baa057b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 27 deletions.
1 change: 0 additions & 1 deletion RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ Picocli follows [semantic versioning](http://semver.org/).
* [#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.
* [#1316] Bugfix: Avoid `DuplicateOptionAnnotationsException` thrown on `mixinStandardHelpOptions` for subcommands when parent has `scope = INHERIT` by `picocli-codegen` annotation processor. Thanks to [Philippe Charles](https://github.com/charphi) for raising this.
* [#1319] Bugfix: Avoid `DuplicateOptionAnnotationsException` when parent has inherited mixed-in help options and the built-in `HelpCommand` subcommand. Thanks to [Andreas Deininger](https://github.com/deining) for raising this.
* [#1331] Bugfix: Avoid `IllegalArgumentException` when parent has no standard help options and `scope = INHERIT`, while subcommand does have mixed-in standard help options. Thanks to [Andreas Deininger](https://github.com/deining) for raising this.
* [#1320][#1321] Bugfix/Enhancement: Use system properties `sun.stdout.encoding` and `sun.stderr.encoding` when creating the `PrintWriters` returned by `CommandLine::getOut` and `CommandLine::getErr`. Thanks to [Philippe Charles](https://github.com/charphi) for the investigation and the pull request.
* [#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
16 changes: 7 additions & 9 deletions src/main/java/picocli/CommandLine.java
Original file line number Diff line number Diff line change
Expand Up @@ -6425,8 +6425,8 @@ private void inheritAttributesFrom(CommandSpec root) {
updatedSubcommandsToInheritFrom(root);
}
private void updatedSubcommandsToInheritFrom(CommandSpec root) {
if (root != this && root.mixinStandardHelpOptions()) { // #1331 only add, don't remove
mixinStandardHelpOptions(true);
if (root != this) {
mixinStandardHelpOptions(root.mixinStandardHelpOptions());
}
Set<CommandLine> subcommands = new HashSet<CommandLine>(subcommands().values());
for (CommandLine sub : subcommands) {
Expand Down Expand Up @@ -7165,12 +7165,6 @@ public CommandSpec mixinStandardHelpOptions(boolean newValue) {
mixin.inherited = this.inherited();
addMixin(AutoHelpMixin.KEY, mixin);
}
// #1331 if inherit(ed) we also add to subcommands
if (scopeType() == ScopeType.INHERIT || inherited()) {
for (CommandLine sub : new HashSet<CommandLine>(subcommands().values())) {
sub.getCommandSpec().mixinStandardHelpOptions(newValue);
}
}
} else {
CommandSpec helpMixin = mixins.remove(AutoHelpMixin.KEY);
if (helpMixin != null) {
Expand All @@ -7182,7 +7176,11 @@ public CommandSpec mixinStandardHelpOptions(boolean newValue) {
}
}
}
// #1331 we don't remove StandardHelpOptions from subcommands, even if they inherit from us
}
if (scopeType() == ScopeType.INHERIT || inherited()) {
for (CommandLine sub : new HashSet<CommandLine>(subcommands().values())) {
sub.getCommandSpec().mixinStandardHelpOptions(newValue);
}
}
return this;
}
Expand Down
17 changes: 0 additions & 17 deletions src/test/java/picocli/InheritedOptionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -576,21 +576,4 @@ void sub(@Option(names = "-foo") int foo) {
new CommandLine(app).execute("sub", "-foo", "42" );
assertEquals(42, app.subFoo);
}

@Test
public void testIssue1331() {
@Command(scope = CommandLine.ScopeType.INHERIT)
class InheritHelpApp {
int subFoo;

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

0 comments on commit baa057b

Please sign in to comment.