Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

LoggingCommand.java 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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.logging;
  23. import com.dmdirc.commandparser.BaseCommandInfo;
  24. import com.dmdirc.commandparser.CommandArguments;
  25. import com.dmdirc.commandparser.CommandType;
  26. import com.dmdirc.commandparser.commands.Command;
  27. import com.dmdirc.commandparser.commands.IntelligentCommand;
  28. import com.dmdirc.commandparser.commands.context.CommandContext;
  29. import com.dmdirc.interfaces.CommandController;
  30. import com.dmdirc.interfaces.WindowModel;
  31. import com.dmdirc.ui.input.AdditionalTabTargets;
  32. import javax.annotation.Nonnull;
  33. import javax.inject.Inject;
  34. /**
  35. * The logging command retrieves information from a dcop application.
  36. */
  37. public class LoggingCommand extends Command implements IntelligentCommand {
  38. /** Command name. */
  39. private static final String LOGGING = "logging";
  40. /** A command info object for this command. */
  41. public static final BaseCommandInfo INFO = new BaseCommandInfo(LOGGING,
  42. "logging <history|help> - view logging related information",
  43. CommandType.TYPE_SERVER);
  44. /** Logging manager. */
  45. private final LoggingManager manager;
  46. /**
  47. * Creates a new instance of this command.
  48. *
  49. * @param controller The controller to use for command information.
  50. * @param manager The manager providing logging services.
  51. */
  52. @Inject
  53. public LoggingCommand(final CommandController controller, final LoggingManager manager) {
  54. super(controller);
  55. this.manager = manager;
  56. }
  57. @Override
  58. public void execute(@Nonnull final WindowModel origin,
  59. final CommandArguments args, final CommandContext context) {
  60. if (args.getArguments().length > 0) {
  61. if ("history".equalsIgnoreCase(args.getArguments()[0])) {
  62. if (!manager.showHistory(origin)) {
  63. showError(origin, args.isSilent(), "Unable to open history for this window.");
  64. }
  65. } else if ("help".equalsIgnoreCase(args.getArguments()[0])) {
  66. showOutput(origin, args.isSilent(), LOGGING
  67. + " history - Open the history of this window, if available.");
  68. showOutput(origin, args.isSilent(), LOGGING
  69. + " help - Show this help.");
  70. } else {
  71. showError(origin, args.isSilent(), "Unknown command '"
  72. + args.getArguments()[0] + "'. Use " + LOGGING
  73. + " help for a list of commands.");
  74. }
  75. } else {
  76. showError(origin, args.isSilent(), "Use " + LOGGING + " help for a list of commands.");
  77. }
  78. }
  79. @Override
  80. public AdditionalTabTargets getSuggestions(final int arg,
  81. final IntelligentCommandContext context) {
  82. final AdditionalTabTargets res = new AdditionalTabTargets();
  83. if (arg == 0) {
  84. res.add("history");
  85. res.add("help");
  86. res.excludeAll();
  87. }
  88. return res;
  89. }
  90. }