From 319c6418c8a94100c15573d030dc8d10a0284525 Mon Sep 17 00:00:00 2001 From: Remko Popma Date: Thu, 12 Nov 2020 20:08:26 +0900 Subject: [PATCH] [#1183] Bugfix: Prevent `MissingParameterException` thrown when subcommand has required options and help option is specified on parent command Closes #1183 --- RELEASE-NOTES.md | 1 + src/main/java/picocli/CommandLine.java | 8 +++++++- src/test/java/picocli/SubcommandTests.java | 1 - 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index e49b878f..218ff9dd 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -118,6 +118,7 @@ only single-value types, and the values in a `Map` (but not the keys!) can be wr * [#1229] Bugfix: Fix compilation error introduced with fc5ef6de6 (#1184). Thanks to [Andreas Deininger](https://github.com/deining) for the pull request. * [#1225] Bugfix: Error message for unmatched positional argument reports incorrect index when value equals a previously matched argument. Thanks to [Vitaly Shukela](https://github.com/vi) for raising this. * [#1250] Bugfix: Inherited positional parameter should not be overridden by default value if placed after subcommand. Thanks to [Daniel Gray](https://github.com/danielthegray) for the pull request. +* [#1183] Bugfix: Prevent `MissingParameterException` thrown when subcommand has required options and help option is specified on parent command. Thanks to [drkilikil](https://github.com/drkilikil) for raising this. * [#1215] DOC: User manual improvements, including more tabs with Kotlin source code. Thanks to [Andreas Deininger](https://github.com/deining) for the pull request. * [#1219] DOC: User manual improvements: added more tabs with Kotlin code. Thanks to [Andreas Deininger](https://github.com/deining) for the pull request. * [#1220] DOC: User manual improvements: corrections, more Kotlin tabs. Thanks to [Andreas Deininger](https://github.com/deining) for the pull request. diff --git a/src/main/java/picocli/CommandLine.java b/src/main/java/picocli/CommandLine.java index c0f985b1..a06f6d71 100644 --- a/src/main/java/picocli/CommandLine.java +++ b/src/main/java/picocli/CommandLine.java @@ -12619,7 +12619,13 @@ public class CommandLine { } } while (!argumentStack.isEmpty() && continueOnError); - if (!isAnyHelpRequested()) { + boolean anyHelpRequested = isAnyHelpRequested(); + CommandLine parsed = CommandLine.this; + while (parsed.getParent() != null) { + parsed = parsed.getParent(); + anyHelpRequested |= parsed.interpreter.isAnyHelpRequested(); + } + if (!anyHelpRequested) { validateConstraints(argumentStack, required, initialized); } } diff --git a/src/test/java/picocli/SubcommandTests.java b/src/test/java/picocli/SubcommandTests.java index 8a72cba9..414b062d 100644 --- a/src/test/java/picocli/SubcommandTests.java +++ b/src/test/java/picocli/SubcommandTests.java @@ -2736,7 +2736,6 @@ public class SubcommandTests { assertEquals("An inheritable parameter rooted in a subcommand's root was not itself!", subParamRooted, subsubParamFromSub.root()); } - @Ignore("requires #1183") @Test public void testIssue1183_HelpWithSubcommandWithRequiredOptions() { @Command(name = "app", mixinStandardHelpOptions = true)