Selaa lähdekoodia

Change all command error/output to use events.

pull/614/head
Chris Smith 8 vuotta sitten
vanhempi
commit
621a53cf06

+ 3
- 3
src/com/dmdirc/commandparser/aliases/AliasCommandHandler.java Näytä tiedosto

@@ -50,9 +50,9 @@ public class AliasCommandHandler extends Command {
50 50
                 origin.getCommandParser().parseCommand(origin, getSubstituteCommand(line, args));
51 51
             }
52 52
         } else {
53
-            sendLine(origin, args.isSilent(), FORMAT_ERROR, alias.getName() + " requires at least "
53
+            showError(origin, args.isSilent(), alias.getName() + " requires at least "
54 54
                     + alias.getMinArguments() + " argument"
55
-                    + (alias.getMinArguments() == 1 ? "" : "s") + ".");
55
+                    + (alias.getMinArguments() == 1 ? "" : "s") + '.');
56 56
         }
57 57
     }
58 58
 
@@ -72,7 +72,7 @@ public class AliasCommandHandler extends Command {
72 72
 
73 73
         final String[] arguments = args.getArguments();
74 74
         for (int i = 0; i < arguments.length; i++) {
75
-            replaceAll(builder, "$" + (i + 1) + "-", args.getArgumentsAsString(i));
75
+            replaceAll(builder, "$" + (i + 1) + '-', args.getArgumentsAsString(i));
76 76
             replaceAll(builder, "$" + (i + 1), arguments[i]);
77 77
         }
78 78
 

+ 0
- 6
src/com/dmdirc/commandparser/commands/Command.java Näytä tiedosto

@@ -38,12 +38,6 @@ import javax.annotation.Nullable;
38 38
  */
39 39
 public abstract class Command {
40 40
 
41
-    /** The format name used for command output. */
42
-    @Deprecated
43
-    protected static final String FORMAT_OUTPUT = "commandOutput";
44
-    /** The format name used for command errors. */
45
-    @Deprecated
46
-    protected static final String FORMAT_ERROR = "commandError";
47 41
     /** The controller this command is associated with. */
48 42
     private final CommandController controller;
49 43
 

+ 2
- 4
src/com/dmdirc/commandparser/commands/channel/Invite.java Näytä tiedosto

@@ -66,8 +66,7 @@ public class Invite extends Command implements ExternalCommand {
66 66
     public void execute(@Nonnull final WindowModel origin,
67 67
             final CommandArguments args, final CommandContext context) {
68 68
         if (args.getArguments().length < 1) {
69
-            sendLine(origin, args.isSilent(), FORMAT_ERROR,
70
-                    "Insufficient arguments: must specify user");
69
+            showError(origin, args.isSilent(), "Insufficient arguments: must specify user");
71 70
         } else {
72 71
             final GroupChat groupChat = ((ChannelCommandContext) context).getGroupChat();
73 72
             groupChat.getConnection().flatMap(Connection::getParser)
@@ -79,8 +78,7 @@ public class Invite extends Command implements ExternalCommand {
79 78
     public void execute(final WindowModel origin, final Connection connection,
80 79
             final String channel, final boolean isSilent, final CommandArguments args) {
81 80
         if (args.getArguments().length < 1) {
82
-            sendLine(origin, isSilent, FORMAT_ERROR,
83
-                    "Insufficient arguments: must specify user");
81
+            showError(origin, isSilent,  "Insufficient arguments: must specify user");
84 82
         } else {
85 83
             connection.getParser().get().sendInvite(channel, args.getArgumentsAsString());
86 84
         }

+ 3
- 4
src/com/dmdirc/commandparser/commands/global/Echo.java Näytä tiedosto

@@ -97,14 +97,14 @@ public class Echo extends Command implements IntelligentCommand {
97 97
             try {
98 98
                 time = new Date(Long.parseLong(results.getArgumentsAsString(timeStampFlag)));
99 99
             } catch (NumberFormatException ex) {
100
-                sendLine(origin, args.isSilent(), FORMAT_ERROR, "Unable to process timestamp");
100
+                showError(origin, args.isSilent(), "Unable to process timestamp");
101 101
                 return;
102 102
             }
103 103
         }
104 104
 
105 105
         if (results.hasFlag(targetFlag)) {
106 106
             WindowModel frame = null;
107
-            Optional<WindowModel> target = Optional.ofNullable(origin);
107
+            Optional<WindowModel> target = Optional.of(origin);
108 108
 
109 109
             while (frame == null && target.isPresent()) {
110 110
                 frame = windowManager.findCustomWindow(target.get(),
@@ -117,8 +117,7 @@ public class Echo extends Command implements IntelligentCommand {
117 117
             }
118 118
 
119 119
             if (frame == null) {
120
-                sendLine(origin, args.isSilent(), FORMAT_ERROR,
121
-                        "Unable to find target window");
120
+                showError(origin, args.isSilent(), "Unable to find target window");
122 121
             } else if (!args.isSilent()) {
123 122
                 frame.getEventBus().publishAsync(new CommandOutputEvent(frame, time.getTime(),
124 123
                         results.getArgumentsAsString()));

+ 10
- 10
src/com/dmdirc/commandparser/commands/global/Help.java Näytä tiedosto

@@ -87,14 +87,14 @@ public class Help extends Command implements IntelligentCommand {
87 87
 
88 88
         Collections.sort(commands);
89 89
 
90
-        sendLine(origin, isSilent, FORMAT_OUTPUT, Styliser.CODE_FIXED
90
+        showOutput(origin, isSilent, Styliser.CODE_FIXED
91 91
                 + "----------------------- Available commands -------");
92 92
 
93 93
         final StringBuilder builder = new StringBuilder();
94 94
 
95 95
         for (String command : commands) {
96 96
             if (builder.length() + command.length() + 1 > 50) {
97
-                sendLine(origin, isSilent, FORMAT_OUTPUT, Styliser.CODE_FIXED + builder.toString());
97
+                showOutput(origin, isSilent, Styliser.CODE_FIXED + builder.toString());
98 98
                 builder.delete(0, builder.length());
99 99
             } else if (builder.length() > 0) {
100 100
                 builder.append(' ');
@@ -104,10 +104,10 @@ public class Help extends Command implements IntelligentCommand {
104 104
         }
105 105
 
106 106
         if (builder.length() > 0) {
107
-            sendLine(origin, isSilent, FORMAT_OUTPUT, Styliser.CODE_FIXED + builder.toString());
107
+            showOutput(origin, isSilent, Styliser.CODE_FIXED + builder.toString());
108 108
         }
109 109
 
110
-        sendLine(origin, isSilent, FORMAT_OUTPUT, Styliser.CODE_FIXED
110
+        showOutput(origin, isSilent, Styliser.CODE_FIXED
111 111
                 + "--------------------------------------------------");
112 112
     }
113 113
 
@@ -129,17 +129,17 @@ public class Help extends Command implements IntelligentCommand {
129 129
         }
130 130
 
131 131
         if (command == null) {
132
-            sendLine(origin, isSilent, FORMAT_ERROR, "Command '" + name + "' not found.");
132
+            showError(origin, isSilent, "Command '" + name + "' not found.");
133 133
         } else {
134
-            sendLine(origin, isSilent, FORMAT_OUTPUT, Styliser.CODE_FIXED
134
+            showOutput(origin, isSilent, Styliser.CODE_FIXED
135 135
                     + "---------------------- Command information -------");
136
-            sendLine(origin, isSilent, FORMAT_OUTPUT, Styliser.CODE_FIXED
136
+            showOutput(origin, isSilent, Styliser.CODE_FIXED
137 137
                     + " Name: " + name);
138
-            sendLine(origin, isSilent, FORMAT_OUTPUT, Styliser.CODE_FIXED
138
+            showOutput(origin, isSilent, Styliser.CODE_FIXED
139 139
                     + " Type: " + command.getKey().getType());
140
-            sendLine(origin, isSilent, FORMAT_OUTPUT, Styliser.CODE_FIXED
140
+            showOutput(origin, isSilent, Styliser.CODE_FIXED
141 141
                     + "Usage: " + command.getKey().getHelp());
142
-            sendLine(origin, isSilent, FORMAT_OUTPUT, Styliser.CODE_FIXED
142
+            showOutput(origin, isSilent, Styliser.CODE_FIXED
143 143
                     + "--------------------------------------------------");
144 144
         }
145 145
     }

+ 5
- 9
src/com/dmdirc/commandparser/commands/global/LoadPlugin.java Näytä tiedosto

@@ -78,21 +78,17 @@ public class LoadPlugin extends Command implements IntelligentCommand {
78 78
         final PluginInfo plugin = pluginManager.getPluginInfo(args.getArgumentsAsString());
79 79
 
80 80
         if (plugin == null) {
81
-            sendLine(origin, args.isSilent(), FORMAT_ERROR,
82
-                    "Plugin loading failed");
81
+            showError(origin, args.isSilent(), "Plugin loading failed");
83 82
         } else if (plugin.isLoaded()) {
84
-            sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
85
-                    "Plugin already loaded.");
83
+            showError(origin, args.isSilent(), "Plugin already loaded.");
86 84
         } else {
87 85
             plugin.loadPlugin();
88 86
             if (plugin.isLoaded()) {
89
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
90
-                        "Plugin loaded.");
87
+                showOutput(origin, args.isSilent(), "Plugin loaded.");
91 88
                 pluginManager.updateAutoLoad(plugin);
92 89
             } else {
93
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
94
-                        "Loading plugin failed. ("
95
-                        + plugin.getLastError() + ")");
90
+                showOutput(origin, args.isSilent(),
91
+                        "Loading plugin failed. (" + plugin.getLastError() + ')');
96 92
             }
97 93
         }
98 94
     }

+ 2
- 3
src/com/dmdirc/commandparser/commands/global/OpenWindow.java Näytä tiedosto

@@ -91,7 +91,7 @@ public class OpenWindow extends Command implements IntelligentCommand {
91 91
         if (args.getArguments().length > 0 && "--server".equals(args.getArguments()[0])) {
92 92
             final Optional<Connection> connection = origin.getConnection();
93 93
             if (!connection.isPresent()) {
94
-                sendLine(origin, args.isSilent(), FORMAT_ERROR,
94
+                showError(origin, args.isSilent(),
95 95
                         "This window doesn't have an associated server.");
96 96
                 return;
97 97
             }
@@ -130,8 +130,7 @@ public class OpenWindow extends Command implements IntelligentCommand {
130 130
                     windowManager.addWindow(parent, newWindow);
131 131
                 }
132 132
             } else {
133
-                sendLine(origin, args.isSilent(), FORMAT_ERROR,
134
-                        "A custom window by that name already exists.");
133
+                showError(origin, args.isSilent(), "A custom window by that name already exists.");
135 134
             }
136 135
         }
137 136
     }

+ 1
- 2
src/com/dmdirc/commandparser/commands/global/ReloadIdentities.java Näytä tiedosto

@@ -66,8 +66,7 @@ public class ReloadIdentities extends Command implements IntelligentCommand {
66 66
     public void execute(@Nonnull final WindowModel origin,
67 67
             final CommandArguments args, final CommandContext context) {
68 68
         identityController.loadUserIdentities();
69
-
70
-        sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Identities reloaded.");
69
+        showOutput(origin, args.isSilent(), "Identities reloaded.");
71 70
     }
72 71
 
73 72
     @Override

+ 3
- 3
src/com/dmdirc/commandparser/commands/global/ReloadPlugin.java Näytä tiedosto

@@ -74,12 +74,12 @@ public class ReloadPlugin extends Command implements IntelligentCommand {
74 74
 
75 75
         final PluginInfo plugin = pluginManager.getPluginInfoByName(args.getArguments()[0]);
76 76
         if (plugin == null) {
77
-            sendLine(origin, args.isSilent(), FORMAT_ERROR,
77
+            showError(origin, args.isSilent(),
78 78
                     "Plugin Reloading failed - Plugin not loaded");
79 79
         } else if (pluginManager.reloadPlugin(plugin.getMetaData().getRelativeFilename())) {
80
-            sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Plugin Reloaded.");
80
+            showOutput(origin, args.isSilent(), "Plugin Reloaded.");
81 81
         } else {
82
-            sendLine(origin, args.isSilent(), FORMAT_ERROR, "Plugin Reloading failed");
82
+            showError(origin, args.isSilent(), "Plugin Reloading failed");
83 83
         }
84 84
     }
85 85
 

+ 1
- 2
src/com/dmdirc/commandparser/commands/global/SaveConfig.java Näytä tiedosto

@@ -66,8 +66,7 @@ public final class SaveConfig extends Command implements IntelligentCommand {
66 66
     public void execute(@Nonnull final WindowModel origin,
67 67
             final CommandArguments args, final CommandContext context) {
68 68
         identityController.saveAll();
69
-
70
-        sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Configuration file saved.");
69
+        showOutput(origin, args.isSilent(), "Configuration file saved.");
71 70
     }
72 71
 
73 72
     @Override

+ 9
- 13
src/com/dmdirc/commandparser/commands/global/SetCommand.java Näytä tiedosto

@@ -118,8 +118,7 @@ public class SetCommand extends Command implements IntelligentCommand {
118 118
 
119 119
         if (res.hasFlag(serverFlag)) {
120 120
             if (!connection.isPresent()) {
121
-                sendLine(origin, args.isSilent(), FORMAT_ERROR,
122
-                        "Cannot use --server in this context");
121
+                showError(origin, args.isSilent(), "Cannot use --server in this context");
123 122
                 return;
124 123
             }
125 124
 
@@ -129,8 +128,7 @@ public class SetCommand extends Command implements IntelligentCommand {
129 128
 
130 129
         if (res.hasFlag(channelFlag)) {
131 130
             if (!(context instanceof ChannelCommandContext)) {
132
-                sendLine(origin, args.isSilent(), FORMAT_ERROR,
133
-                        "Cannot use --channel in this context");
131
+                showError(origin, args.isSilent(),"Cannot use --channel in this context");
134 132
                 return;
135 133
             }
136 134
 
@@ -193,7 +191,7 @@ public class SetCommand extends Command implements IntelligentCommand {
193 191
             output.append(", ");
194 192
         }
195 193
 
196
-        sendLine(origin, isSilent, FORMAT_OUTPUT, output.substring(0, output.length() - 2));
194
+        showOutput(origin, isSilent, output.substring(0, output.length() - 2));
197 195
     }
198 196
 
199 197
     /**
@@ -221,10 +219,9 @@ public class SetCommand extends Command implements IntelligentCommand {
221 219
         }
222 220
 
223 221
         if (found) {
224
-            sendLine(origin, isSilent, FORMAT_OUTPUT, output.substring(0, output.length() - 2));
222
+            showOutput(origin, isSilent, output.substring(0, output.length() - 2));
225 223
         } else {
226
-            sendLine(origin, isSilent, FORMAT_ERROR,
227
-                    "There are no options in the domain '" + domain + "'.");
224
+            showError(origin, isSilent, "There are no options in the domain '" + domain + "'.");
228 225
         }
229 226
     }
230 227
 
@@ -241,10 +238,10 @@ public class SetCommand extends Command implements IntelligentCommand {
241 238
             final boolean isSilent, final ReadOnlyConfigProvider manager,
242 239
             final String domain, final String option) {
243 240
         if (manager.hasOptionString(domain, option)) {
244
-            sendLine(origin, isSilent, FORMAT_OUTPUT, "The current value of "
241
+            showOutput(origin, isSilent, "The current value of "
245 242
                     + domain + '.' + option + " is: " + manager.getOption(domain, option));
246 243
         } else {
247
-            sendLine(origin, isSilent, FORMAT_ERROR, "Option not found: " + domain + '.' + option);
244
+            showError(origin, isSilent, "Option not found: " + domain + '.' + option);
248 245
         }
249 246
     }
250 247
 
@@ -263,8 +260,7 @@ public class SetCommand extends Command implements IntelligentCommand {
263 260
             final String domain, final String option, final String newvalue) {
264 261
         identity.setOption(domain, option, newvalue);
265 262
 
266
-        sendLine(origin, isSilent, FORMAT_OUTPUT, domain + '.' + option
267
-                + " has been set to: " + newvalue);
263
+        showOutput(origin, isSilent, domain + '.' + option + " has been set to: " + newvalue);
268 264
     }
269 265
 
270 266
     /**
@@ -301,7 +297,7 @@ public class SetCommand extends Command implements IntelligentCommand {
301 297
             final String option) {
302 298
         identity.unsetOption(domain, option);
303 299
 
304
-        sendLine(origin, isSilent, FORMAT_OUTPUT, domain + '.' + option + " has been unset.");
300
+        showOutput(origin, isSilent, domain + '.' + option + " has been unset.");
305 301
     }
306 302
 
307 303
     @Override

+ 3
- 3
src/com/dmdirc/commandparser/commands/global/UnloadPlugin.java Näytä tiedosto

@@ -74,13 +74,13 @@ public class UnloadPlugin extends Command implements IntelligentCommand {
74 74
 
75 75
         final PluginInfo plugin = pluginManager.getPluginInfoByName(args.getArguments()[0]);
76 76
         if (plugin == null) {
77
-            sendLine(origin, args.isSilent(), FORMAT_ERROR,
77
+            showError(origin, args.isSilent(),
78 78
                     "Plugin unloading failed - Plugin not loaded");
79 79
         } else if (pluginManager.delPlugin(plugin.getMetaData().getRelativeFilename())) {
80
-            sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Plugin Unloaded.");
80
+            showOutput(origin, args.isSilent(), "Plugin Unloaded.");
81 81
             pluginManager.updateAutoLoad(plugin);
82 82
         } else {
83
-            sendLine(origin, args.isSilent(), FORMAT_ERROR, "Plugin Unloading failed");
83
+            showError(origin, args.isSilent(), "Plugin Unloading failed");
84 84
         }
85 85
     }
86 86
 

+ 18
- 21
src/com/dmdirc/commandparser/commands/server/Ignore.java Näytä tiedosto

@@ -71,23 +71,22 @@ public class Ignore extends Command implements IntelligentCommand {
71 71
         final Connection connection = ((ServerCommandContext) context).getConnection();
72 72
 
73 73
         if (args.getArguments().length == 0) {
74
-            executeView(origin, connection, args.isSilent(), args, false);
74
+            executeView(origin, connection, args, false);
75 75
         } else if ("--remove".equalsIgnoreCase(args.getArguments()[0])) {
76
-            executeRemove(origin, connection, args.isSilent(), args);
76
+            executeRemove(origin, connection, args);
77 77
         } else if ("--regex".equalsIgnoreCase(args.getArguments()[0])) {
78
-            executeRegex(origin, connection, args.isSilent(), args);
78
+            executeRegex(origin, connection, args);
79 79
         } else {
80
-            executeAdd(origin, connection, args.isSilent(), args);
80
+            executeAdd(origin, connection, args);
81 81
         }
82 82
     }
83 83
 
84 84
     protected void executeView(final WindowModel origin, final Connection connection,
85
-            final boolean isSilent, final CommandArguments args, final boolean forceRegex) {
85
+            final CommandArguments args, final boolean forceRegex) {
86 86
         final IgnoreList ignoreList = connection.getIgnoreList();
87 87
 
88 88
         if (ignoreList.count() == 0) {
89
-            sendLine(origin, args.isSilent(), FORMAT_ERROR,
90
-                    "No ignore list entries for this network.");
89
+            showError(origin, args.isSilent(), "No ignore list entries for this network.");
91 90
             return;
92 91
         }
93 92
 
@@ -96,7 +95,7 @@ public class Ignore extends Command implements IntelligentCommand {
96 95
             entries = ignoreList.getSimpleList();
97 96
         } else {
98 97
             if (!forceRegex) {
99
-                sendLine(origin, args.isSilent(), FORMAT_ERROR,
98
+                showError(origin, args.isSilent(),
100 99
                         "Unable to convert ignore list to simple format");
101 100
             }
102 101
             entries = ignoreList.getRegexList();
@@ -105,24 +104,24 @@ public class Ignore extends Command implements IntelligentCommand {
105 104
         int i = 0;
106 105
         for (String line : entries) {
107 106
             i++;
108
-            sendLine(origin, args.isSilent(), FORMAT_OUTPUT, i + ". " + line);
107
+            showOutput(origin, args.isSilent(), i + ". " + line);
109 108
         }
110 109
     }
111 110
 
112 111
     protected void executeAdd(final WindowModel origin, final Connection connection,
113
-            final boolean isSilent, final CommandArguments args) {
112
+            final CommandArguments args) {
114 113
         final IgnoreList ignoreList = connection.getIgnoreList();
115 114
         final String target = args.getArgumentsAsString();
116 115
 
117 116
         ignoreList.addSimple(target);
118 117
         connection.saveIgnoreList();
119
-        sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Added " + target + " to the ignore list.");
118
+        showOutput(origin, args.isSilent(), "Added " + target + " to the ignore list.");
120 119
     }
121 120
 
122 121
     protected void executeRegex(final WindowModel origin, final Connection connection,
123
-            final boolean isSilent, final CommandArguments args) {
122
+            final CommandArguments args) {
124 123
         if (args.getArguments().length == 1) {
125
-            executeView(origin, connection, args.isSilent(), args, true);
124
+            executeView(origin, connection, args, true);
126 125
             return;
127 126
         }
128 127
 
@@ -133,18 +132,17 @@ public class Ignore extends Command implements IntelligentCommand {
133 132
             //noinspection ResultOfMethodCallIgnored
134 133
             Pattern.compile(target);
135 134
         } catch (PatternSyntaxException ex) {
136
-            sendLine(origin, args.isSilent(), FORMAT_ERROR, "Unable to compile regex: "
137
-                    + ex.getDescription());
135
+            showError(origin, args.isSilent(), "Unable to compile regex: " + ex.getDescription());
138 136
             return;
139 137
         }
140 138
 
141 139
         ignoreList.add(target);
142 140
         connection.saveIgnoreList();
143
-        sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Added " + target + " to the ignore list.");
141
+        showOutput(origin, args.isSilent(), "Added " + target + " to the ignore list.");
144 142
     }
145 143
 
146 144
     protected void executeRemove(final WindowModel origin, final Connection connection,
147
-            final boolean isSilent, final CommandArguments args) {
145
+            final CommandArguments args) {
148 146
         if (args.getArguments().length == 1) {
149 147
             showUsage(origin, args.isSilent(), "ignore", "--remove <host>");
150 148
             return;
@@ -156,7 +154,7 @@ public class Ignore extends Command implements IntelligentCommand {
156 154
         if (ignoreList.canConvert() && ignoreList.getSimpleList().contains(host)) {
157 155
             ignoreList.remove(ignoreList.getSimpleList().indexOf(host));
158 156
             connection.saveIgnoreList();
159
-            sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Removed " + host
157
+            showOutput(origin, args.isSilent(), "Removed " + host
160 158
                     + " from the ignore list.");
161 159
             return;
162 160
         }
@@ -164,13 +162,12 @@ public class Ignore extends Command implements IntelligentCommand {
164 162
         if (ignoreList.getRegexList().contains(host)) {
165 163
             ignoreList.remove(ignoreList.getRegexList().indexOf(host));
166 164
             connection.saveIgnoreList();
167
-            sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Removed " + host
165
+            showOutput(origin, args.isSilent(), "Removed " + host
168 166
                     + " from the ignore list.");
169 167
             return;
170 168
         }
171 169
 
172
-        sendLine(origin, args.isSilent(), FORMAT_ERROR, "Ignore list doesn't contain '" + host
173
-                + "'.");
170
+        showError(origin, args.isSilent(), "Ignore list doesn't contain '" + host + "'.");
174 171
     }
175 172
 
176 173
     @Override

+ 1
- 2
src/com/dmdirc/commandparser/commands/server/Message.java Näytä tiedosto

@@ -94,8 +94,7 @@ public class Message extends Command implements IntelligentCommand,
94 94
                     // This can happen if the server gets disconnected after
95 95
                     // the command manager has checked the @CommandOptions
96 96
                     // annotation. Yay for concurrency.
97
-                    sendLine(origin, args.isSilent(), FORMAT_ERROR,
98
-                            "You must be connected to use this command");
97
+                    showError(origin, args.isSilent(), "You must be connected to use this command");
99 98
                 }
100 99
             }
101 100
         }

+ 1
- 1
src/com/dmdirc/commandparser/commands/server/OpenQuery.java Näytä tiedosto

@@ -75,7 +75,7 @@ public class OpenQuery extends Command implements IntelligentCommand,
75 75
 
76 76
         final Connection connection = ((ServerCommandContext) context).getConnection();
77 77
         if (connection.getParser().get().isValidChannelName(args.getArguments()[0])) {
78
-            sendLine(origin, args.isSilent(), FORMAT_ERROR, "You can't open a query "
78
+            showError(origin, args.isSilent(), "You can't open a query "
79 79
                     + "with a channel; maybe you meant " + Styliser.CODE_FIXED
80 80
                     + Styliser.CODE_BOLD
81 81
                     + getController().getCommandChar()

+ 1
- 1
src/com/dmdirc/commandparser/commands/server/Umode.java Näytä tiedosto

@@ -64,7 +64,7 @@ public class Umode extends Command {
64 64
             final CommandArguments args, final CommandContext context) {
65 65
         final Connection connection = ((ServerCommandContext) context).getConnection();
66 66
         if (connection.getState() != ServerState.CONNECTED) {
67
-            sendLine(origin, args.isSilent(), FORMAT_ERROR, "Not connected");
67
+            showError(origin, args.isSilent(), "Not connected");
68 68
             return;
69 69
         }
70 70
 

+ 1
- 1
src/com/dmdirc/commandparser/commands/server/Whois.java Näytä tiedosto

@@ -63,7 +63,7 @@ public class Whois extends Command {
63 63
             final CommandArguments args, final CommandContext context) {
64 64
         final Connection connection = ((ServerCommandContext) context).getConnection();
65 65
         if (connection.getState() != ServerState.CONNECTED) {
66
-            sendLine(origin, args.isSilent(), FORMAT_ERROR, "Not connected");
66
+            showError(origin, args.isSilent(), "Not connected");
67 67
             return;
68 68
         }
69 69
 

+ 14
- 2
test/com/dmdirc/commandparser/aliases/AliasCommandHandlerTest.java Näytä tiedosto

@@ -22,20 +22,25 @@
22 22
 
23 23
 package com.dmdirc.commandparser.aliases;
24 24
 
25
+import com.dmdirc.DMDircMBassador;
25 26
 import com.dmdirc.commandparser.CommandArguments;
26 27
 import com.dmdirc.commandparser.CommandInfo;
27 28
 import com.dmdirc.commandparser.CommandType;
28 29
 import com.dmdirc.commandparser.commands.context.CommandContext;
29 30
 import com.dmdirc.commandparser.parsers.CommandParser;
31
+import com.dmdirc.events.CommandErrorEvent;
30 32
 import com.dmdirc.interfaces.CommandController;
31 33
 import com.dmdirc.interfaces.WindowModel;
32 34
 
33 35
 import org.junit.Before;
34 36
 import org.junit.Test;
35 37
 import org.junit.runner.RunWith;
38
+import org.mockito.ArgumentCaptor;
39
+import org.mockito.Captor;
36 40
 import org.mockito.Mock;
37 41
 import org.mockito.runners.MockitoJUnitRunner;
38 42
 
43
+import static org.junit.Assert.assertEquals;
39 44
 import static org.mockito.Mockito.verify;
40 45
 import static org.mockito.Mockito.when;
41 46
 
@@ -47,6 +52,8 @@ public class AliasCommandHandlerTest {
47 52
     @Mock private CommandParser commandParser;
48 53
     @Mock private CommandContext context;
49 54
     @Mock private CommandInfo commandInfo;
55
+    @Mock private DMDircMBassador eventbus;
56
+    @Captor private ArgumentCaptor<CommandErrorEvent> errorEventCaptor;
50 57
 
51 58
     @Before
52 59
     public void setup() {
@@ -55,6 +62,7 @@ public class AliasCommandHandlerTest {
55 62
         when(commandController.getSilenceChar()).thenReturn('/');
56 63
         when(context.getSource()).thenReturn(container);
57 64
         when(context.getCommandInfo()).thenReturn(commandInfo);
65
+        when(container.getEventBus()).thenReturn(eventbus);
58 66
     }
59 67
 
60 68
     @Test
@@ -82,7 +90,9 @@ public class AliasCommandHandlerTest {
82 90
         final AliasCommandHandler handler = new AliasCommandHandler(commandController, alias);
83 91
         final CommandArguments arguments = new CommandArguments(commandController, "#test");
84 92
         handler.execute(container, arguments, context);
85
-        verify(container).addLine("commandError", "test requires at least 1 argument.");
93
+        verify(eventbus).publishAsync(errorEventCaptor.capture());
94
+        assertEquals("test requires at least 1 argument.",
95
+                errorEventCaptor.getValue().getMessage());
86 96
     }
87 97
 
88 98
     @Test
@@ -91,7 +101,9 @@ public class AliasCommandHandlerTest {
91 101
         final AliasCommandHandler handler = new AliasCommandHandler(commandController, alias);
92 102
         final CommandArguments arguments = new CommandArguments(commandController, "#test agadoo");
93 103
         handler.execute(container, arguments, context);
94
-        verify(container).addLine("commandError", "test requires at least 2 arguments.");
104
+        verify(eventbus).publishAsync(errorEventCaptor.capture());
105
+        assertEquals("test requires at least 2 arguments.",
106
+                errorEventCaptor.getValue().getMessage());
95 107
     }
96 108
 
97 109
     @Test

Loading…
Peruuta
Tallenna