Help.java 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package eu.oschl.console.commands;
  2. import eu.oschl.console.Console;
  3. import eu.oschl.console.ConsoleColor;
  4. import java.util.ArrayList;
  5. /**
  6. * This command displays a list of all available actions in the console application.
  7. * It provides a way for users to see what commands they can use.
  8. *
  9. * @author Ondřej Schlaichert
  10. */
  11. public class Help implements Command {
  12. private final ArrayList<Command> commands;
  13. public Help(ArrayList<Command> commands) {
  14. this.commands = commands;
  15. }
  16. @Override
  17. public String[] getTriggers() {
  18. return new String[]{
  19. "help",
  20. "actions",
  21. "commands",
  22. "list actions",
  23. "list commands",
  24. };
  25. }
  26. @Override
  27. public String getDescription() {
  28. return "display currently available actions";
  29. }
  30. @Override
  31. public void execute(String[] args) {
  32. if (args.length > 0) {
  33. Console.print("This doesn't make any sense.", ConsoleColor.RED);
  34. return;
  35. }
  36. Console.print("available actions:", ConsoleColor.BG_CYAN);
  37. for (var command : commands) {
  38. if (command == this) {
  39. continue;
  40. }
  41. Console.printLine();
  42. Console.print(" * [" + command.getTriggers()[0] + "]", ConsoleColor.YELLOW);
  43. Console.print(" - " + command.getDescription(), ConsoleColor.WHITE);
  44. }
  45. }
  46. }