Skip to content

Commit

Permalink
Added and removed some
Browse files Browse the repository at this point in the history
  • Loading branch information
Mqzn committed Sep 17, 2024
1 parent e9a1460 commit 5840ac2
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 4 deletions.
6 changes: 6 additions & 0 deletions core/src/main/java/dev/velix/imperat/Imperat.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,10 @@ <A extends Annotation> void registerAnnotationReplacer(
*/
List<String> autoComplete(Command<S> command, S sender, String[] args);

/**
* Debugs all registered commands and their usages.
*
* @param treeVisualizing whether to display them in the form of tree
*/
void debug(boolean treeVisualizing);
}
13 changes: 13 additions & 0 deletions core/src/main/java/dev/velix/imperat/command/BaseImperat.java
Original file line number Diff line number Diff line change
Expand Up @@ -715,4 +715,17 @@ public void handleThrowable(
ImperatDebugger.error(owning, methodName, throwable);
}

@Override
public void debug(boolean treeVisualizing) {
for (var cmd : commands.values()) {
if (treeVisualizing) {
cmd.visualizeTree();
} else {
ImperatDebugger.debug("Debugging command '%s'", cmd.name());
for (CommandUsage<S> usage : cmd.getUsages()) {
ImperatDebugger.debug(" - '%s'", usage);
}
}
}
}
}
2 changes: 1 addition & 1 deletion core/src/main/java/dev/velix/imperat/command/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ default boolean hasName(String name) {
* If the command is not a root command,
* nothing will be visualized.
*/
void visualize();
void visualizeTree();

/**
* Sets a pre-processor for the command
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public List<String> tabComplete(Imperat<S> dispatcher, SuggestionContext<S> cont
}

@Override
public void visualize() {
public void visualizeTree() {
ImperatDebugger.debug("Visualizing %s's tree", this.name);
visualizer.visualize();
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/test/java/dev/velix/imperat/TestImperat.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ public void shutdownPlatform() {
@Override
public void registerCommand(Command<TestSource> command) {
super.registerCommand(command);
command.visualize();
command.visualizeTree();
}
}
2 changes: 1 addition & 1 deletion core/src/test/java/dev/velix/imperat/TestRun.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private static UsageMatchResult testCmdTreeExecution(String cmdName, String inpu
}

private static void debugCommand(Command<TestSource> command) {
command.visualize();
command.visualizeTree();

System.out.println("Debugging sub commands: ");
System.out.println("Command '" + command.name() + "' has usages: ");
Expand Down

0 comments on commit 5840ac2

Please sign in to comment.