Przeglądaj źródła

Update all plugin commands to use the new arguments

tags/0.6.3m1rc1
Chris Smith 15 lat temu
rodzic
commit
a48c5c00ee

+ 5
- 9
src/com/dmdirc/addons/audio/AudioCommand.java Wyświetl plik

@@ -22,6 +22,7 @@
22 22
 
23 23
 package com.dmdirc.addons.audio;
24 24
 
25
+import com.dmdirc.commandparser.CommandArguments;
25 26
 import com.dmdirc.commandparser.CommandManager;
26 27
 import com.dmdirc.commandparser.commands.GlobalCommand;
27 28
 import com.dmdirc.ui.interfaces.InputWindow;
@@ -43,16 +44,11 @@ public final class AudioCommand extends GlobalCommand {
43 44
 		CommandManager.registerCommand(this);
44 45
 	}
45 46
 		
46
-	/**
47
-	 * Executes this command.
48
-	 *
49
-	 * @param origin The frame in which this command was issued
50
-	 * @param isSilent Whether this command is silenced or not
51
-	 * @param args The user supplied arguments
52
-	 */
47
+	/** {@inheritDoc} */
53 48
     @Override
54
-	public void execute(final InputWindow origin, final boolean isSilent, final String... args) {
55
-		final String filename = implodeArgs(args);
49
+	public void execute(final InputWindow origin, final boolean isSilent,
50
+            final CommandArguments args) {
51
+		final String filename = args.getArgumentsAsString();
56 52
 		final File file = new File(filename);
57 53
 		if (file.exists()) {
58 54
 			if (AudioPlayer.isValid(file)) {

+ 4
- 8
src/com/dmdirc/addons/audio/BeepCommand.java Wyświetl plik

@@ -22,6 +22,7 @@
22 22
 
23 23
 package com.dmdirc.addons.audio;
24 24
 
25
+import com.dmdirc.commandparser.CommandArguments;
25 26
 import com.dmdirc.commandparser.CommandManager;
26 27
 import com.dmdirc.commandparser.commands.GlobalCommand;
27 28
 import com.dmdirc.ui.interfaces.InputWindow;
@@ -43,15 +44,10 @@ public final class BeepCommand extends GlobalCommand {
43 44
 		CommandManager.registerCommand(this);
44 45
 	}
45 46
 		
46
-	/**
47
-	 * Executes this command.
48
-	 *
49
-	 * @param origin The frame in which this command was issued
50
-	 * @param isSilent Whether this command is silenced or not
51
-	 * @param args The user supplied arguments
52
-	 */
47
+	/** {@inheritDoc} */
53 48
     @Override
54
-	public void execute(final InputWindow origin, final boolean isSilent, final String... args) {
49
+	public void execute(final InputWindow origin, final boolean isSilent,
50
+            final CommandArguments args) {
55 51
 		Toolkit.getDefaultToolkit().beep();
56 52
 	}
57 53
 

+ 12
- 16
src/com/dmdirc/addons/dcc/DCCCommand.java Wyświetl plik

@@ -37,6 +37,7 @@ import com.dmdirc.actions.ActionManager;
37 37
 import com.dmdirc.addons.dcc.kde.KFileChooser;
38 38
 import com.dmdirc.addons.dcc.actions.DCCActions;
39 39
 
40
+import com.dmdirc.commandparser.CommandArguments;
40 41
 import javax.swing.JFileChooser;
41 42
 import javax.swing.JFrame;
42 43
 import javax.swing.JOptionPane;
@@ -66,19 +67,13 @@ public final class DCCCommand extends ServerCommand implements IntelligentComman
66 67
 		CommandManager.registerCommand(this);
67 68
 	}
68 69
 		
69
-	/**
70
-	 * Executes this command.
71
-	 *
72
-	 * @param origin The frame in which this command was issued
73
-	 * @param server The server instance that this command is being executed on
74
-	 * @param isSilent Whether this command is silenced or not
75
-	 * @param args The user supplied arguments
76
-	 */
70
+	/** {@inheritDoc} */
77 71
 	@Override
78
-	public void execute(final InputWindow origin, final Server server, final boolean isSilent, final String... args) {
79
-		if (args.length > 1) {
80
-			final String type = args[0];
81
-			final String target = args[1];
72
+	public void execute(final InputWindow origin, final Server server,
73
+            final boolean isSilent, final CommandArguments args) {
74
+		if (args.getArguments().length > 1) {
75
+			final String type = args.getArguments()[0];
76
+			final String target = args.getArguments()[1];
82 77
 			final IRCParser parser = server.getParser();
83 78
 			final String myNickname = parser.getMyNickname();
84 79
 				
@@ -112,7 +107,7 @@ public final class DCCCommand extends ServerCommand implements IntelligentComman
112 107
 					sendLine(origin, isSilent, "DCCChatError", "Unable to start chat with "+target+" - unable to create listen socket");
113 108
 				}
114 109
 			} else if (type.equalsIgnoreCase("send")) {
115
-				sendFile(target, origin, server, isSilent, args);
110
+				sendFile(target, origin, server, isSilent, args.getArgumentsAsString(2));
116 111
 			} else {
117 112
 				sendLine(origin, isSilent, FORMAT_ERROR, "Unknown DCC Type: '"+type+"'");
118 113
 			}
@@ -128,11 +123,12 @@ public final class DCCCommand extends ServerCommand implements IntelligentComman
128 123
 	 * @param origin The InputWindow this command was issued on
129 124
 	 * @param server The server instance that this command is being executed on
130 125
 	 * @param isSilent Whether this command is silenced or not
131
-	 * @param args Arguments passed.
126
+	 * @param filename The file to send
127
+     * @since 0.6.3
132 128
 	 */
133
-	public void sendFile(final String target, final InputWindow origin, final Server server, final boolean isSilent, final String... args) {
129
+	public void sendFile(final String target, final InputWindow origin, final Server server, final boolean isSilent, final String filename) {
134 130
 		// New thread to ask the user what file to send
135
-		final File givenFile = new File(implodeArgs(2, args));
131
+		final File givenFile = new File(filename);
136 132
 		final Thread dccThread = new Thread(new Runnable() {
137 133
 			/** {@inheritDoc} */
138 134
 			@Override

+ 6
- 11
src/com/dmdirc/addons/dcop/DcopCommand.java Wyświetl plik

@@ -23,6 +23,7 @@
23 23
 package com.dmdirc.addons.dcop;
24 24
 
25 25
 import com.dmdirc.Server;
26
+import com.dmdirc.commandparser.CommandArguments;
26 27
 import com.dmdirc.commandparser.CommandManager;
27 28
 import com.dmdirc.commandparser.commands.ServerCommand;
28 29
 import com.dmdirc.ui.interfaces.InputWindow;
@@ -43,23 +44,17 @@ public final class DcopCommand extends ServerCommand {
43 44
         
44 45
         CommandManager.registerCommand(this);
45 46
     }
46
-    
47
-    /**
48
-     * Executes this command.
49
-     * @param origin The frame in which this command was issued
50
-     * @param server The server object that this command is associated with
51
-     * @param isSilent Whether this command is silenced or not
52
-     * @param args The user supplied arguments
53
-     */
47
+
48
+    /** {@inheritDoc} */
54 49
     @Override
55 50
     public void execute(final InputWindow origin, final Server server,
56
-            final boolean isSilent, final String... args) {
57
-        if (args.length != 3) {
51
+            final boolean isSilent, final CommandArguments args) {
52
+        if (args.getArguments().length != 3) {
58 53
             showUsage(origin, isSilent, "dcop", "<app> <object> <function>");
59 54
             return;
60 55
         }
61 56
         
62
-        final List<String> res = DcopPlugin.getDcopResult("dcop " + implodeArgs(args));
57
+        final List<String> res = DcopPlugin.getDcopResult("dcop " + args.getArgumentsAsString());
63 58
         for (String line : res) {
64 59
             sendLine(origin, isSilent, FORMAT_OUTPUT, line);
65 60
         }

+ 11
- 6
src/com/dmdirc/addons/dns/DNSCommand.java Wyświetl plik

@@ -22,6 +22,7 @@
22 22
 
23 23
 package com.dmdirc.addons.dns;
24 24
 
25
+import com.dmdirc.commandparser.CommandArguments;
25 26
 import com.dmdirc.commandparser.CommandManager;
26 27
 import com.dmdirc.commandparser.commands.GlobalCommand;
27 28
 import com.dmdirc.ui.interfaces.InputWindow;
@@ -44,21 +45,25 @@ public final class DNSCommand extends GlobalCommand {
44 45
     /** {@inheritDoc} */
45 46
     @Override
46 47
     public void execute(final InputWindow origin, final boolean isSilent,
47
-            final String... args) {
48
-        if (args.length == 0) {
48
+            final CommandArguments args) {
49
+        if (args.getArguments().length == 0) {
49 50
             showUsage(origin, isSilent, "dns", "<IP|hostname>");
50 51
             return;
51 52
         }
52 53
         
53
-        sendLine(origin, isSilent, FORMAT_OUTPUT, "Resolving: " + args[0]);
54
+        sendLine(origin, isSilent, FORMAT_OUTPUT, "Resolving: " + args.getArguments()[0]);
54 55
         new Timer("DNS Command Timer").schedule(new TimerTask() {
55 56
             /** {@inheritDoc} */
56 57
             @Override
57 58
             public void run() {
58
-                if (args[0].matches("\\b(?:\\d{1,3}\\.){3}\\d{1,3}\\b")) {
59
-                    sendLine(origin, isSilent, FORMAT_OUTPUT, "Resolved: " + args[0] + ": " + DNSPlugin.getHostname(args[0]));
59
+                if (args.getArguments()[0].matches("\\b(?:\\d{1,3}\\.){3}\\d{1,3}\\b")) {
60
+                    sendLine(origin, isSilent, FORMAT_OUTPUT, "Resolved: "
61
+                            + args.getArguments()[0] + ": "
62
+                            + DNSPlugin.getHostname(args.getArguments()[0]));
60 63
                 } else {
61
-                    sendLine(origin, isSilent, FORMAT_OUTPUT, "Resolved: " + args[0] + ": " + DNSPlugin.getIPs(args[0]));
64
+                    sendLine(origin, isSilent, FORMAT_OUTPUT, "Resolved: "
65
+                            + args.getArguments()[0] + ": "
66
+                            + DNSPlugin.getIPs(args.getArguments()[0]));
62 67
                 }
63 68
             }
64 69
         }, 0);

+ 9
- 14
src/com/dmdirc/addons/logging/LoggingCommand.java Wyświetl plik

@@ -23,6 +23,7 @@
23 23
 package com.dmdirc.addons.logging;
24 24
 
25 25
 import com.dmdirc.Server;
26
+import com.dmdirc.commandparser.CommandArguments;
26 27
 import com.dmdirc.commandparser.CommandManager;
27 28
 import com.dmdirc.commandparser.commands.IntelligentCommand;
28 29
 import com.dmdirc.commandparser.commands.ServerCommand;
@@ -48,16 +49,10 @@ public final class LoggingCommand extends ServerCommand implements IntelligentCo
48 49
 		CommandManager.registerCommand(this);
49 50
 	}
50 51
 		
51
-	/**
52
-	 * Executes this command.
53
-	 *
54
-	 * @param origin The frame in which this command was issued
55
-	 * @param server The server object that this command is associated with
56
-	 * @param isSilent Whether this command is silenced or not
57
-	 * @param args The user supplied arguments
58
-	 */
52
+    /** {@inheritDoc} */
59 53
     @Override
60
-	public void execute(final InputWindow origin, final Server server, final boolean isSilent, final String... args) {
54
+	public void execute(final InputWindow origin, final Server server,
55
+            final boolean isSilent, final CommandArguments args) {
61 56
 		final PluginInfo pluginInfo = PluginManager.getPluginManager().getPluginInfoByName("logging");
62 57
 		if (pluginInfo == null) { 
63 58
 			sendLine(origin, isSilent, FORMAT_ERROR, "Logging Plugin is not loaded.");
@@ -72,23 +67,23 @@ public final class LoggingCommand extends ServerCommand implements IntelligentCo
72 67
 		
73 68
 		final LoggingPlugin plugin = (LoggingPlugin) gotPlugin;
74 69
 		
75
-		if (args.length > 0) {
76
-			if (args[0].equalsIgnoreCase("reload")) {
70
+		if (args.getArguments().length > 0) {
71
+			if (args.getArguments()[0].equalsIgnoreCase("reload")) {
77 72
 				if (PluginManager.getPluginManager().reloadPlugin(pluginInfo.getFilename())) {
78 73
 					sendLine(origin, isSilent, FORMAT_OUTPUT, "Plugin reloaded.");
79 74
 				} else {
80 75
 					sendLine(origin, isSilent, FORMAT_ERROR, "Plugin failed to reload.");
81 76
 				}
82
-			} else if (args[0].equalsIgnoreCase("history")) {
77
+			} else if (args.getArguments()[0].equalsIgnoreCase("history")) {
83 78
 				if (!plugin.showHistory(origin)) {
84 79
 					sendLine(origin, isSilent, FORMAT_ERROR, "Unable to open history for this window.");
85 80
     		}
86
-			} else if (args[0].equalsIgnoreCase("help")) {
81
+			} else if (args.getArguments()[0].equalsIgnoreCase("help")) {
87 82
 				sendLine(origin, isSilent, FORMAT_OUTPUT, getName() + " reload           - Reload the logging plugin.");
88 83
 				sendLine(origin, isSilent, FORMAT_OUTPUT, getName() + " history          - Open the history of this window, if available.");
89 84
 				sendLine(origin, isSilent, FORMAT_OUTPUT, getName() + " help             - Show this help.");
90 85
 			} else {
91
-				sendLine(origin, isSilent, FORMAT_ERROR, "Unknown command '" + args[0] + "'. Use " + getName() + " help for a list of commands.");
86
+				sendLine(origin, isSilent, FORMAT_ERROR, "Unknown command '" + args.getArguments()[0] + "'. Use " + getName() + " help for a list of commands.");
92 87
 			}
93 88
 		} else {
94 89
 			sendLine(origin, isSilent, FORMAT_ERROR, "Use " + getName() + " help for a list of commands.");

+ 8
- 5
src/com/dmdirc/addons/nowplaying/NowPlayingCommand.java Wyświetl plik

@@ -24,6 +24,7 @@ package com.dmdirc.addons.nowplaying;
24 24
 
25 25
 import com.dmdirc.MessageTarget;
26 26
 import com.dmdirc.Server;
27
+import com.dmdirc.commandparser.CommandArguments;
27 28
 import com.dmdirc.commandparser.commands.ChatCommand;
28 29
 import com.dmdirc.commandparser.CommandManager;
29 30
 import com.dmdirc.commandparser.commands.IntelligentCommand;
@@ -59,12 +60,14 @@ public final class NowPlayingCommand extends ChatCommand implements IntelligentC
59 60
     /** {@inheritDoc} */
60 61
     @Override
61 62
     public void execute(final InputWindow origin, final Server server,
62
-            final MessageTarget target, final boolean isSilent, final String ... args) {
63
-        if (args.length > 0 && args[0].equalsIgnoreCase("--sources")) {
63
+            final MessageTarget target, final boolean isSilent, final CommandArguments args) {
64
+        if (args.getArguments().length > 0 && args.getArguments()[0]
65
+                .equalsIgnoreCase("--sources")) {
64 66
             doSourceList(origin, isSilent);
65
-        } else if (args.length > 0 && args[0].equalsIgnoreCase("--source")) {
66
-            if (args.length > 1) {
67
-                final String sourceName = args[1];
67
+        } else if (args.getArguments().length > 0 && args.getArguments()[0]
68
+                .equalsIgnoreCase("--source")) {
69
+            if (args.getArguments().length > 1) {
70
+                final String sourceName = args.getArguments()[1];
68 71
                 final MediaSource source = parent.getSource(sourceName);
69 72
                 
70 73
                 if (source == null) {

+ 5
- 3
src/com/dmdirc/addons/osd/OsdCommand.java Wyświetl plik

@@ -22,6 +22,7 @@
22 22
 
23 23
 package com.dmdirc.addons.osd;
24 24
 
25
+import com.dmdirc.commandparser.CommandArguments;
25 26
 import com.dmdirc.commandparser.CommandManager;
26 27
 import com.dmdirc.commandparser.commands.GlobalCommand;
27 28
 import com.dmdirc.commandparser.commands.IntelligentCommand;
@@ -49,11 +50,12 @@ public final class OsdCommand extends GlobalCommand implements IntelligentComman
49 50
     /** {@inheritDoc} */
50 51
     @Override
51 52
     public void execute(final InputWindow origin, final boolean isSilent,
52
-            final String... args) {
53
-        if (args.length > 0 && "--close".equalsIgnoreCase(args[0])) {
53
+            final CommandArguments args) {
54
+        if (args.getArguments().length > 0
55
+                && "--close".equalsIgnoreCase(args.getArguments()[0])) {
54 56
             OsdWindow.closeAll();
55 57
         } else {
56
-            new OsdWindow(Styliser.stipControlCodes(implodeArgs(args)), false);
58
+            new OsdWindow(Styliser.stipControlCodes(args.getArgumentsAsString()), false);
57 59
         }
58 60
     }
59 61
     

+ 3
- 2
src/com/dmdirc/addons/redirect/RedirectCommand.java Wyświetl plik

@@ -24,6 +24,7 @@ package com.dmdirc.addons.redirect;
24 24
 
25 25
 import com.dmdirc.MessageTarget;
26 26
 import com.dmdirc.Server;
27
+import com.dmdirc.commandparser.CommandArguments;
27 28
 import com.dmdirc.commandparser.commands.ChatCommand;
28 29
 import com.dmdirc.commandparser.commands.IntelligentCommand;
29 30
 import com.dmdirc.ui.input.AdditionalTabTargets;
@@ -46,9 +47,9 @@ public class RedirectCommand extends ChatCommand implements IntelligentCommand {
46 47
     /** {@inheritDoc} */
47 48
     @Override
48 49
     public void execute(final InputWindow origin, final Server server,
49
-            final MessageTarget target, final boolean isSilent, final String... args) {
50
+            final MessageTarget target, final boolean isSilent, final CommandArguments args) {
50 51
         target.getFrame().getCommandParser().parseCommand(new FakeInputWindow(target),
51
-                implodeArgs(args));
52
+                args.getArgumentsAsString());
52 53
     }
53 54
     
54 55
     /** {@inheritDoc} */

+ 3
- 2
src/com/dmdirc/addons/systray/PopupCommand.java Wyświetl plik

@@ -23,6 +23,7 @@
23 23
 package com.dmdirc.addons.systray;
24 24
 
25 25
 import com.dmdirc.Server;
26
+import com.dmdirc.commandparser.CommandArguments;
26 27
 import com.dmdirc.commandparser.CommandManager;
27 28
 import com.dmdirc.commandparser.commands.ServerCommand;
28 29
 import com.dmdirc.ui.interfaces.InputWindow;
@@ -52,8 +53,8 @@ public final class PopupCommand extends ServerCommand {
52 53
     /** {@inheritDoc} */
53 54
     @Override
54 55
     public void execute(final InputWindow origin, final Server server,
55
-            final boolean isSilent, final String ... args) {
56
-        parent.notify("DMDirc", implodeArgs(args));
56
+            final boolean isSilent, final CommandArguments args) {
57
+        parent.notify("DMDirc", args.getArgumentsAsString());
57 58
     }
58 59
 
59 60
     /** {@inheritDoc} */

+ 6
- 5
src/com/dmdirc/addons/time/TimerCommand.java Wyświetl plik

@@ -22,6 +22,7 @@
22 22
 
23 23
 package com.dmdirc.addons.time;
24 24
 
25
+import com.dmdirc.commandparser.CommandArguments;
25 26
 import com.dmdirc.commandparser.CommandManager;
26 27
 import com.dmdirc.commandparser.commands.GlobalCommand;
27 28
 import com.dmdirc.commandparser.commands.IntelligentCommand;
@@ -47,17 +48,17 @@ public final class TimerCommand extends GlobalCommand implements IntelligentComm
47 48
     /** {@inheritDoc} */
48 49
     @Override
49 50
     public void execute(final InputWindow origin, final boolean isSilent, 
50
-            final String... args) {
51
-        if (args.length < 3) {
51
+            final CommandArguments args) {
52
+        if (args.getArguments().length < 3) {
52 53
             doUsage(origin, isSilent);
53 54
         } else {
54 55
             int repetitions = 0;
55 56
             int interval = 0;
56
-            final String command = implodeArgs(2, args);
57
+            final String command = args.getArgumentsAsString(2);
57 58
             
58 59
             try {
59
-                repetitions = Integer.parseInt(args[0]);
60
-                interval = Integer.parseInt(args[1]);
60
+                repetitions = Integer.parseInt(args.getArguments()[0]);
61
+                interval = Integer.parseInt(args.getArguments()[1]);
61 62
             } catch (NumberFormatException ex) {
62 63
                 doUsage(origin, isSilent);
63 64
                 return;

+ 2
- 1
src/com/dmdirc/addons/urlcatcher/UrlListCommand.java Wyświetl plik

@@ -22,6 +22,7 @@
22 22
 
23 23
 package com.dmdirc.addons.urlcatcher;
24 24
 
25
+import com.dmdirc.commandparser.CommandArguments;
25 26
 import com.dmdirc.commandparser.commands.GlobalCommand;
26 27
 import com.dmdirc.commandparser.commands.IntelligentCommand;
27 28
 import com.dmdirc.ui.input.AdditionalTabTargets;
@@ -44,7 +45,7 @@ public class UrlListCommand extends GlobalCommand implements IntelligentCommand
44 45
     /** {@inheritDoc} */
45 46
     @Override
46 47
     public void execute(final InputWindow origin, final boolean isSilent,
47
-            final String... args) {
48
+            final CommandArguments args) {
48 49
         final String[] headers = {"URL", "Count"};
49 50
         final Map<String, Integer> map = plugin.getURLS();
50 51
         final String[][] data = new String[map.size()][];

+ 15
- 1
src/com/dmdirc/commandparser/CommandArguments.java Wyświetl plik

@@ -108,7 +108,21 @@ public class CommandArguments {
108 108
     public String getArgumentsAsString() {
109 109
         parse();
110 110
         
111
-        return getWordsAsString(1);
111
+        return getArgumentsAsString(0);
112
+    }
113
+
114
+    /**
115
+     * Retrieves arguments to the command (i.e., not including the
116
+     * command name) starting with the specified argument, with their original
117
+     * whitespace separation preserved.
118
+     *
119
+     * @param start The index of the first argument to include
120
+     * @return A String representation of the command arguments
121
+     */
122
+    public String getArgumentsAsString(final int start) {
123
+        parse();
124
+
125
+        return getWordsAsString(start + 1);
112 126
     }
113 127
 
114 128
     /**

Ładowanie…
Anuluj
Zapisz