You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DebugCommand.java 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * Copyright (c) 2006-2017 DMDirc Developers
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
  5. * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
  6. * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
  7. * permit persons to whom the Software is furnished to do so, subject to the following conditions:
  8. *
  9. * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
  10. * Software.
  11. *
  12. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  13. * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
  14. * OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  15. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  16. */
  17. package com.dmdirc.addons.debug;
  18. import com.dmdirc.commandparser.CommandArguments;
  19. import com.dmdirc.commandparser.commands.context.CommandContext;
  20. import com.dmdirc.interfaces.WindowModel;
  21. import javax.annotation.Nonnull;
  22. import javax.inject.Provider;
  23. /**
  24. * Debug command, serves as a proxy between debug commands and normal commands.
  25. */
  26. public abstract class DebugCommand {
  27. /** Parent debug command. */
  28. private final Provider<Debug> commandProvider;
  29. /**
  30. * Creates a new debug command.
  31. *
  32. * @param commandProvider Provider of the {@link Debug} command which owns this subcommand.
  33. */
  34. public DebugCommand(final Provider<Debug> commandProvider) {
  35. this.commandProvider = commandProvider;
  36. }
  37. /**
  38. * Returns this command's name.
  39. *
  40. * @return The name of this command
  41. */
  42. public abstract String getName();
  43. /**
  44. * Returns a string representing the help message for this command.
  45. * <p>
  46. * The help text should generally be one line, and must start with the name of the command. It
  47. * should then summarise the arguments of that command, using <code>&lt;angled&gt;</code>
  48. * brackets for required arguments, and <code>[square]</code> brackets for optional arguments.
  49. * Where multiple possibilities exist, they are typically separated by a pipe ( <code>|</code>),
  50. * for example: <code>command [--arg1|--arg2]</code>. The usage summary should then be followed
  51. * by a dash and a brief summary of the purpose of the command.
  52. * <p>
  53. * A typical help message would look similar to:
  54. * <p>
  55. * <code>command [--arg &lt;param_for_arg&gt;] [someparam] - does x, y and z</code>
  56. *
  57. * @return the help message for this command
  58. */
  59. public abstract String getUsage();
  60. /**
  61. * Executes this command.
  62. * @param origin The container which received the command
  63. * @param args Arguments passed to this command
  64. * @param context The context the command was executed in
  65. */
  66. public abstract void execute(@Nonnull final WindowModel origin,
  67. final CommandArguments args, final CommandContext context);
  68. /**
  69. * Shows output, if appropriate, in the specified target.
  70. *
  71. * @param target The command window to send the line to
  72. * @param isSilent Whether this command is being silenced or not
  73. * @param message The message to be sent
  74. */
  75. public void showOutput(final WindowModel target, final boolean isSilent, final String message) {
  76. commandProvider.get().proxyShowOutput(target, isSilent, message);
  77. }
  78. /**
  79. * Shows an error, if appropriate, in the specified target.
  80. *
  81. * @param target The command window to send the line to
  82. * @param isSilent Whether this command is being silenced or not
  83. * @param message The message to be sent
  84. */
  85. public void showError(final WindowModel target, final boolean isSilent, final String message) {
  86. commandProvider.get().proxyShowError(target, isSilent, message);
  87. }
  88. /**
  89. * Sends a usage line, if appropriate, to the specified target.
  90. *
  91. * @param target The command window to send the line to
  92. * @param isSilent Whether this command is being silenced or not
  93. * @param name The name of the command that's raising the error
  94. * @param args The arguments that the command accepts or expects
  95. */
  96. public void showUsage(final WindowModel target,
  97. final boolean isSilent, final String name, final String args) {
  98. commandProvider.get().proxyShowUsage(target, isSilent, name, args);
  99. }
  100. /**
  101. * Formats the specified data into a table suitable for output in the textpane. It is expected
  102. * that each String[] in data has the same number of elements as the headers array.
  103. *
  104. * @param headers The headers of the table.
  105. * @param data The contents of the table.
  106. *
  107. * @return A string containing an ASCII table
  108. */
  109. public String doTable(final String[] headers, final String[][] data) {
  110. return commandProvider.get().proxyDoTable(headers, data);
  111. }
  112. }