Added optional boolean to get all command usage text
This commit is contained in:
parent
08b183588f
commit
e85f4a9f11
3 changed files with 9 additions and 9 deletions
|
@ -162,14 +162,14 @@ public class CommandDispatcher<S> {
|
|||
return new ParseResults<>(rootContext, reader, errors);
|
||||
}
|
||||
|
||||
public String[] getAllUsage(final CommandNode<S> node, final S source) {
|
||||
public String[] getAllUsage(final CommandNode<S> node, final S source, final boolean restricted) {
|
||||
final ArrayList<String> result = Lists.newArrayList();
|
||||
getAllUsage(node, source, result, "");
|
||||
getAllUsage(node, source, result, "", restricted);
|
||||
return result.toArray(new String[result.size()]);
|
||||
}
|
||||
|
||||
private void getAllUsage(final CommandNode<S> node, final S source, final ArrayList<String> result, final String prefix) {
|
||||
if (!node.canUse(source)) {
|
||||
private void getAllUsage(final CommandNode<S> node, final S source, final ArrayList<String> result, final String prefix, final boolean restricted) {
|
||||
if (restricted && !node.canUse(source)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -182,7 +182,7 @@ public class CommandDispatcher<S> {
|
|||
result.add(prefix.isEmpty() ? node.getUsageText() + ARGUMENT_SEPARATOR + redirect : prefix + ARGUMENT_SEPARATOR + redirect);
|
||||
} else if (!node.getChildren().isEmpty()) {
|
||||
for (final CommandNode<S> child : node.getChildren()) {
|
||||
getAllUsage(child, source, result, prefix.isEmpty() ? child.getUsageText() : prefix + ARGUMENT_SEPARATOR + child.getUsageText());
|
||||
getAllUsage(child, source, result, prefix.isEmpty() ? child.getUsageText() : prefix + ARGUMENT_SEPARATOR + child.getUsageText(), restricted);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,8 +39,8 @@ public class FloatArgumentType implements ArgumentType<Float> {
|
|||
return new FloatArgumentType(min, max, suffix);
|
||||
}
|
||||
|
||||
public static int getInteger(final CommandContext<?> context, final String name) {
|
||||
return context.getArgument(name, int.class);
|
||||
public static float getFloat(final CommandContext<?> context, final String name) {
|
||||
return context.getArgument(name, Float.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -109,7 +109,7 @@ public class CommandDispatcherUsagesTest {
|
|||
@Test
|
||||
public void testAllUsage_noCommands() throws Exception {
|
||||
subject = new CommandDispatcher<>();
|
||||
final String[] results = subject.getAllUsage(subject.getRoot(), source);
|
||||
final String[] results = subject.getAllUsage(subject.getRoot(), source, true);
|
||||
assertThat(results, is(emptyArray()));
|
||||
}
|
||||
|
||||
|
@ -122,7 +122,7 @@ public class CommandDispatcherUsagesTest {
|
|||
|
||||
@Test
|
||||
public void testAllUsage_root() throws Exception {
|
||||
final String[] results = subject.getAllUsage(subject.getRoot(), source);
|
||||
final String[] results = subject.getAllUsage(subject.getRoot(), source, true);
|
||||
assertThat(results, equalTo(new String[]{
|
||||
"a 1 i",
|
||||
"a 1 ii",
|
||||
|
|
Loading…
Reference in a new issue