Browse Source

Add identities debug command

Fixes CLIENT-95

Change-Id: I272b975270a1642167a06d740bd5e77b742cf796
Reviewed-on: http://gerrit.dmdirc.com/1708
Reviewed-by: Greg Holmes <greg@dmdirc.com>
Automatic-Compile: DMDirc Local Commits <dmdirc@googlemail.com>
tags/0.6.5
Chris Smith 13 years ago
parent
commit
c6b01725b1

+ 6
- 3
src/com/dmdirc/addons/debug/DebugPlugin.java View File

@@ -27,6 +27,7 @@ import com.dmdirc.commandparser.CommandManager;
27 27
 import com.dmdirc.logger.ErrorLevel;
28 28
 import com.dmdirc.logger.Logger;
29 29
 import com.dmdirc.plugins.Plugin;
30
+
30 31
 import java.util.ArrayList;
31 32
 import java.util.HashMap;
32 33
 import java.util.List;
@@ -41,9 +42,10 @@ public class DebugPlugin extends Plugin {
41 42
     private static final Class[] CLASSES = {
42 43
         Benchmark.class, ColourSpam.class, ConfigInfo.class, ConfigStats.class,
43 44
         com.dmdirc.addons.debug.commands.Error.class, FirstRun.class,
44
-        ForceUpdate.class, GlobalConfigInfo.class, MemInfo.class,
45
-        Notify.class, RunGC.class, ServerInfo.class, ServerState.class,
46
-        Services.class, ShowRaw.class, Threads.class, Time.class,
45
+        ForceUpdate.class, GlobalConfigInfo.class, Identities.class,
46
+        MemInfo.class, Notify.class, RunGC.class, ServerInfo.class,
47
+        ServerState.class, Services.class, ShowRaw.class, Threads.class,
48
+        Time.class,
47 49
     };
48 50
     /** List of registered debug commands. */
49 51
     private final Map<String, DebugCommand> commands;
@@ -61,6 +63,7 @@ public class DebugPlugin extends Plugin {
61 63
 
62 64
     /** {@inheritDoc} */
63 65
     @Override
66
+    @SuppressWarnings("unchecked")
64 67
     public void onLoad() {
65 68
         CommandManager.registerCommand(debugCommand);
66 69
         for (Class<DebugCommand> type : CLASSES) {

+ 86
- 0
src/com/dmdirc/addons/debug/commands/Identities.java View File

@@ -0,0 +1,86 @@
1
+/*
2
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.addons.debug.commands;
24
+
25
+import com.dmdirc.FrameContainer;
26
+import com.dmdirc.addons.debug.Debug;
27
+import com.dmdirc.addons.debug.DebugCommand;
28
+import com.dmdirc.commandparser.CommandArguments;
29
+import com.dmdirc.commandparser.commands.context.CommandContext;
30
+import com.dmdirc.config.Identity;
31
+import com.dmdirc.config.IdentityManager;
32
+import java.util.List;
33
+
34
+/**
35
+ * Outputs a table of all known identities.
36
+ */
37
+public class Identities extends DebugCommand {
38
+
39
+    /**
40
+     * Creates a new instance of the command.
41
+     *
42
+     * @param command Parent command
43
+     */
44
+    public Identities(final Debug command) {
45
+        super(command);
46
+    }
47
+
48
+    /** {@inheritDoc} */
49
+    @Override
50
+    public String getName() {
51
+        return "identities";
52
+    }
53
+
54
+    /** {@inheritDoc} */
55
+    @Override
56
+    public String getUsage() {
57
+        return "[type] - Outputs all known identities";
58
+    }
59
+
60
+    /** {@inheritDoc} */
61
+    @Override
62
+    public void execute(final FrameContainer<?> origin,
63
+            final CommandArguments args, final CommandContext context) {
64
+        final String type;
65
+
66
+        if (args.getArguments().length == 0) {
67
+            type = null;
68
+        } else {
69
+            type = args.getArgumentsAsString();
70
+        }
71
+
72
+        final List<Identity> identities = IdentityManager.getCustomIdentities(type);
73
+        final String[][] data = new String[identities.size()][4];
74
+
75
+        int i = 0;
76
+        for (Identity source : identities) {
77
+            data[i++] = new String[]{source.getName(),
78
+            source.getTarget().getTypeName(), source.getTarget().getData(),
79
+            String.valueOf(source.getTarget().getOrder())};
80
+        }
81
+
82
+        sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
83
+                doTable(new String[]{"Name", "Target", "Data", "Priority"}, data));
84
+    }
85
+
86
+}

Loading…
Cancel
Save