Add the ability to "hide" commands.

This does not yet change how commands are treated, but allows for this to be implemented in the future.
This commit is contained in:
Alexander Söderberg 2020-09-25 02:31:20 +02:00
parent c980adac3b
commit 64fa3430a9
No known key found for this signature in database
GPG key ID: C0207FF7EA146678
5 changed files with 82 additions and 2 deletions

View file

@ -226,6 +226,15 @@ public class Command<C> {
return this.arguments.get(argument).getDescription();
}
/**
* Check whether or not the command is hidden
*
* @return {@code true} if the command is hidden, {@code false} if not
*/
public boolean isHidden() {
return this.getCommandMeta().getOrDefault("hidden", "true").equals("true");
}
/**
* Builder for {@link Command} instances. The builder is immutable, and each
@ -437,6 +446,17 @@ public class Command<C> {
return builder.handler(command.commandExecutionHandler);
}
/**
* Indicate that the command should be hidden from help menus
* and other places where commands are exposed to users
*
* @return New builder instance that indicates that the constructed command should be hidden
*/
@Nonnull
public Builder<C> hidden() {
return this.meta("hidden", "true");
}
/**
* Build a command using the builder instance
*

View file

@ -52,6 +52,10 @@ public final class StandardParameters {
* Command completions
*/
public static final ParserParameter<String[]> COMPLETIONS = create("completions", TypeToken.of(String[].class));
/**
* The command should be hidden from help menus, etc
*/
public static final ParserParameter<Boolean> HIDDEN = create("hidden", TypeToken.of(Boolean.class));
private StandardParameters() {
}