Skip to content

Commit

Permalink
[#1741] fix bug
Browse files Browse the repository at this point in the history
Closes #1741
  • Loading branch information
remkop committed Jul 22, 2022
1 parent 1e32ec0 commit 4b9875f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ Picocli 4.7.0 introduced a `sortSynopsis = false` attribute to let the synopsis
* [#1575] Bugfix: Synopsis should not cluster boolean options if `posixClusteredShortOptionsAllowed` is set to false.
* [#1642] Bugfix: Negatable options should negate explicit values. Thanks to [Nat Burns](https://github.com/burnnat) for raising this.
* [#1696][#1697] Bugfix: ManPageGenerator asciidoc output now correctly shows options in nested ArgGroups. Thanks to [Ruud Senden](https://github.com/rsenden) for the pull request.
* [#1741] Bugfix: `@Command`-annotated method parameters are assigned incorrect indices when contained in a `@Command` class that is added as a subcommand to another `@Command` class which has `scope = CommandLine.ScopeType.INHERIT`. Thanks to [Onedy](https://github.com/Onedy) for raising this.
* [#1298] DOC: Publish all-in-one javadoc for all picocli modules.
* [#812] DOC: Document how to test a picocli spring-boot application.
* [#1596] DOC: fix javadoc typos and incorrect links.
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/picocli/CommandLine.java
Original file line number Diff line number Diff line change
Expand Up @@ -6601,10 +6601,18 @@ private void removeAlias(String alias, CommandLine subCommandLine, Tracer t) {
commands.remove(interpolator.interpolate(alias));
}
private void inheritAttributesFrom(CommandSpec root) {
inherited = true;
setInheritedDeep();
initFrom(root);
updatedSubcommandsToInheritFrom(root);
}
// Issue #1741: ensure all commands in the hierarchy downwards have `inherited = true` set
// before mixing in the standard help options
private void setInheritedDeep() {
inherited = true;
for (CommandLine sub : subcommands().values()) {
sub.getCommandSpec().setInheritedDeep();
}
}
private void updatedSubcommandsToInheritFrom(CommandSpec root) {
if (root != this && root.mixinStandardHelpOptions()) { // #1331 only add, don't remove
mixinStandardHelpOptions(true);
Expand Down
2 changes: 0 additions & 2 deletions src/test/java/picocli/Issue1741.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package picocli;

import org.junit.Ignore;
import org.junit.Test;
import picocli.CommandLine.Command;
import picocli.CommandLine.Parameters;
Expand Down Expand Up @@ -32,7 +31,6 @@ void enter(@Parameters(arity = "1") String sentenceType,
}
}

@Ignore
@Test
public void testIssue1741_subcommandAddedProgrammatically() {
CommandLine commandLine = getTestCommandLine(new ParentTestCommand(), new TestCommand(), CommandLine.defaultFactory());
Expand Down

0 comments on commit 4b9875f

Please sign in to comment.