diff --git a/src/main/java/picocli/CommandLine.java b/src/main/java/picocli/CommandLine.java index 8871e00f3..0f12398fe 100644 --- a/src/main/java/picocli/CommandLine.java +++ b/src/main/java/picocli/CommandLine.java @@ -1821,6 +1821,12 @@ public CommandLine setExpandAtFiles(boolean expandAtFiles) { * @return text to display after the list of options * @see Help#footer(Object...) */ String[] footer() default {}; + + /** + * Set {@code hidden=true} if this command should not be included in the usage documentation. + * @return whether this command should be excluded from the usage message + */ + boolean hidden() default false; } /** *
@@ -2164,6 +2170,7 @@ private static boolean updateCommandAttributes(Class> cls, CommandSpec command
if (!commandSpec.isSortOptionsInitialized() && !cmd.sortOptions()) { commandSpec.sortOptions(cmd.sortOptions()); }
if (!commandSpec.isShowDefaultValuesInitialized() && cmd.showDefaultValues()) { commandSpec.showDefaultValues(cmd.showDefaultValues()); }
if (!commandSpec.isIsHelpCommandInitialized() && cmd.isHelpCommand()) { commandSpec.setHelpCommand(cmd.isHelpCommand()); }
+ if (!commandSpec.isIsHiddenInitialized() && cmd.hidden() ) { commandSpec.setHidden(cmd.hidden()); }
if (!commandSpec.isVersionProviderInitialized() && cmd.versionProvider() != NoVersionProvider.class) {
commandSpec.versionProvider(DefaultFactory.createVersionProvider(factory, cmd.versionProvider()));
}
@@ -2475,6 +2482,7 @@ public static class CommandSpec {
private Boolean sortOptions;
private Boolean showDefaultValues;
private Boolean isHelpCommand;
+ private Boolean isHidden;
private Character requiredOptionMarker;
private String headerHeading;
private String synopsisHeading;
@@ -2790,6 +2798,20 @@ public String[] version() {
* @see Command#isHelpCommand() */
public CommandSpec setHelpCommand(boolean newValue) {isHelpCommand = newValue; return this;}
+ /**
+ * @return {@code true} when the command is annotated with a {@link Command#hidden} attribute, {@code false} otherwise.o
+ */
+ public boolean isHidden() { return isHidden != null ? isHidden : false; }
+
+ /**
+ * Set the hidden flag on this command to prevent to add in the help usage text.
+ * @param value enable or disable the hidden flag
+ * @see {@link Command#hidden()}
+ */
+ public void setHidden( boolean value ) {
+ isHidden = value;
+ }
+
/** Returns the optional heading preceding the subcommand list. Initialized from {@link Command#commandListHeading()}. {@code "Commands:%n"} by default. */
public String commandListHeading() { return commandListHeading; }
@@ -2842,6 +2864,7 @@ public String[] version() {
boolean isFooterHeadingInitialized() { return !empty(footerHeading); }
boolean isParameterListHeadingInitialized() { return !empty(parameterListHeading); }
boolean isOptionListHeadingInitialized() { return !empty(optionListHeading); }
+ boolean isIsHiddenInitialized() { return isHidden != null; }
}
/** Models the shared attributes of {@link OptionSpec} and {@link PositionalParamSpec}.
* @since 3.0 */
@@ -4408,6 +4431,7 @@ public Help(CommandSpec commandSpec, ColorScheme colorScheme) {
public Help addAllSubcommands(Map