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.2KB

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