123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- /*
- * Copyright (c) 2006-2017 DMDirc Developers
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
- * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
- * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
- * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
- * OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
- * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
- package com.dmdirc.addons.debug;
-
- import com.dmdirc.commandparser.CommandArguments;
- import com.dmdirc.commandparser.commands.context.CommandContext;
- import com.dmdirc.interfaces.WindowModel;
-
- import javax.annotation.Nonnull;
- import javax.inject.Provider;
-
- /**
- * Debug command, serves as a proxy between debug commands and normal commands.
- */
- public abstract class DebugCommand {
-
- /** Parent debug command. */
- private final Provider<Debug> commandProvider;
-
- /**
- * Creates a new debug command.
- *
- * @param commandProvider Provider of the {@link Debug} command which owns this subcommand.
- */
- public DebugCommand(final Provider<Debug> commandProvider) {
- this.commandProvider = commandProvider;
- }
-
- /**
- * Returns this command's name.
- *
- * @return The name of this command
- */
- public abstract String getName();
-
- /**
- * Returns a string representing the help message for this command.
- * <p>
- * The help text should generally be one line, and must start with the name of the command. It
- * should then summarise the arguments of that command, using <code><angled></code>
- * brackets for required arguments, and <code>[square]</code> brackets for optional arguments.
- * Where multiple possibilities exist, they are typically separated by a pipe ( <code>|</code>),
- * for example: <code>command [--arg1|--arg2]</code>. The usage summary should then be followed
- * by a dash and a brief summary of the purpose of the command.
- * <p>
- * A typical help message would look similar to:
- * <p>
- * <code>command [--arg <param_for_arg>] [someparam] - does x, y and z</code>
- *
- * @return the help message for this command
- */
- public abstract String getUsage();
-
- /**
- * Executes this command.
- * @param origin The container which received the command
- * @param args Arguments passed to this command
- * @param context The context the command was executed in
- */
- public abstract void execute(@Nonnull final WindowModel origin,
- final CommandArguments args, final CommandContext context);
-
- /**
- * Shows output, if appropriate, in the specified target.
- *
- * @param target The command window to send the line to
- * @param isSilent Whether this command is being silenced or not
- * @param message The message to be sent
- */
- public void showOutput(final WindowModel target, final boolean isSilent, final String message) {
- commandProvider.get().proxyShowOutput(target, isSilent, message);
- }
-
- /**
- * Shows an error, if appropriate, in the specified target.
- *
- * @param target The command window to send the line to
- * @param isSilent Whether this command is being silenced or not
- * @param message The message to be sent
- */
- public void showError(final WindowModel target, final boolean isSilent, final String message) {
- commandProvider.get().proxyShowError(target, isSilent, message);
- }
-
- /**
- * Sends a usage line, if appropriate, to the specified target.
- *
- * @param target The command window to send the line to
- * @param isSilent Whether this command is being silenced or not
- * @param name The name of the command that's raising the error
- * @param args The arguments that the command accepts or expects
- */
- public void showUsage(final WindowModel target,
- final boolean isSilent, final String name, final String args) {
- commandProvider.get().proxyShowUsage(target, isSilent, name, args);
- }
-
- /**
- * Formats the specified data into a table suitable for output in the textpane. It is expected
- * that each String[] in data has the same number of elements as the headers array.
- *
- * @param headers The headers of the table.
- * @param data The contents of the table.
- *
- * @return A string containing an ASCII table
- */
- public String doTable(final String[] headers, final String[][] data) {
- return commandProvider.get().proxyDoTable(headers, data);
- }
-
- }
|