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