Kaynağa Gözat

Improved the /help command, although I'm not sure I like it

Fixes issue 864

git-svn-id: http://svn.dmdirc.com/trunk@3414 00569f92-eb28-0410-84fd-f71c24880f
tags/0.6
Chris Smith 16 yıl önce
ebeveyn
işleme
7e213d56f2

+ 18
- 0
src/com/dmdirc/commandparser/CommandType.java Dosyayı Görüntüle

@@ -70,4 +70,22 @@ public enum CommandType {
70 70
         }
71 71
     }
72 72
 
73
+    /** {@inheritDoc} */
74
+    @Override
75
+    public String toString() {
76
+        switch (this) {
77
+            case TYPE_CHANNEL:
78
+                return "Channel";
79
+            case TYPE_CHAT:
80
+                return "Chat";
81
+            case TYPE_GLOBAL:
82
+                return "Global";
83
+            case TYPE_QUERY:
84
+                return "Query";
85
+            case TYPE_SERVER:
86
+                return "Server";
87
+            default:
88
+                return "Unknown";
89
+        }
90
+    }
73 91
 }

+ 61
- 28
src/com/dmdirc/commandparser/commands/global/Help.java Dosyayı Görüntüle

@@ -32,6 +32,8 @@ import com.dmdirc.ui.interfaces.InputWindow;
32 32
 import com.dmdirc.ui.interfaces.QueryWindow;
33 33
 import com.dmdirc.ui.interfaces.ServerWindow;
34 34
 
35
+import com.dmdirc.ui.messages.Styliser;
36
+import java.util.ArrayList;
35 37
 import java.util.Collections;
36 38
 import java.util.List;
37 39
 
@@ -61,42 +63,73 @@ public final class Help extends ServerCommand {
61 63
      */
62 64
     public void execute(final InputWindow origin, final Server server,
63 65
             final boolean isSilent, final String... args) {
64
-        sendLine(origin, isSilent, FORMAT_OUTPUT, "-- Global commands ----------------------------------");
65
-        showCommands(CommandManager.getCommands(CommandType.TYPE_GLOBAL), origin, isSilent);
66
-        
67
-        if (origin instanceof ServerWindow || origin instanceof ChannelWindow
68
-                || origin instanceof QueryWindow) {
69
-            sendLine(origin, isSilent, FORMAT_OUTPUT, "-- Server commands ----------------------------------");
70
-            showCommands(CommandManager.getCommands(CommandType.TYPE_SERVER), origin, isSilent);
66
+        if (args.length == 0) {
67
+            showAllCommands(origin, isSilent);
68
+        } else {
69
+            showCommand(origin, isSilent, args[0]);
71 70
         }
71
+    }
72
+    
73
+    private void showAllCommands(final InputWindow origin, final boolean isSilent) {
74
+        final List<Command> commands = new ArrayList<Command>();
75
+
76
+        commands.addAll(CommandManager.getCommands(CommandType.TYPE_GLOBAL));
72 77
         
73
-            if (origin instanceof ChannelWindow) {
74
-            sendLine(origin, isSilent, FORMAT_OUTPUT, "-- Channel commands ---------------------------------");
75
-            showCommands(CommandManager.getCommands(CommandType.TYPE_CHANNEL), origin, isSilent);
78
+        if (origin instanceof ServerWindow) {
79
+            commands.addAll(CommandManager.getCommands(CommandType.TYPE_SERVER));
80
+        } else if (origin instanceof ChannelWindow) {
81
+            commands.addAll(CommandManager.getCommands(CommandType.TYPE_CHANNEL));
82
+            commands.addAll(CommandManager.getCommands(CommandType.TYPE_CHAT));
83
+            commands.addAll(CommandManager.getCommands(CommandType.TYPE_SERVER));
84
+        } else if (origin instanceof QueryWindow) {
85
+            commands.addAll(CommandManager.getCommands(CommandType.TYPE_QUERY));
86
+            commands.addAll(CommandManager.getCommands(CommandType.TYPE_CHAT));
87
+            commands.addAll(CommandManager.getCommands(CommandType.TYPE_SERVER));
76 88
         }
77 89
         
78
-        if (origin instanceof QueryWindow) {
79
-            sendLine(origin, isSilent, FORMAT_OUTPUT, "-- Query commands -----------------------------------");
80
-            showCommands(CommandManager.getCommands(CommandType.TYPE_QUERY), origin, isSilent);
90
+        Collections.sort(commands);
91
+        
92
+        sendLine(origin, isSilent, FORMAT_OUTPUT, Styliser.CODE_FIXED
93
+                + "----------------------- Available commands -------");
94
+        
95
+        final StringBuilder builder = new StringBuilder();
96
+        
97
+        for (Command command : commands) {
98
+            if (builder.length() + command.getName().length() + 1 > 50) {
99
+                sendLine(origin, isSilent, FORMAT_OUTPUT, Styliser.CODE_FIXED + builder.toString());
100
+                builder.delete(0, builder.length());
101
+            } else if (builder.length() > 0) {
102
+                builder.append(' ');
103
+            }
81 104
             
105
+            builder.append(command.getName());
106
+        }
107
+        
108
+        if (builder.length() > 0) {
109
+            sendLine(origin, isSilent, FORMAT_OUTPUT, Styliser.CODE_FIXED + builder.toString());
82 110
         }
83 111
         
84
-        sendLine(origin, isSilent, FORMAT_OUTPUT, "-----------------------------------------------------");
112
+        sendLine(origin, isSilent, FORMAT_OUTPUT, Styliser.CODE_FIXED
113
+                + "--------------------------------------------------");
85 114
     }
86 115
     
87
-    /**
88
-     * Shows the user the commands from the specified list.
89
-     * @param commands The commands to be displayed
90
-     * @param origin The window to output to
91
-     * @param isSilent Whether this command is silent or not
92
-     */
93
-    private void showCommands(final List<Command> commands,
94
-            final InputWindow origin, final boolean isSilent) {
95
-        Collections.sort(commands);
96
-        for (Command com : commands) {
97
-            if (com.showInHelp()) {
98
-                sendLine(origin, isSilent, FORMAT_OUTPUT, com.getHelp());
99
-            }
116
+    private void showCommand(final InputWindow origin, final boolean isSilent,
117
+            final String name) {
118
+        final Command command = CommandManager.getCommand(name);
119
+        
120
+        if (command == null) {
121
+            sendLine(origin, isSilent, FORMAT_ERROR, "Command '" + name + "' not found.");
122
+        } else {
123
+            sendLine(origin, isSilent, FORMAT_OUTPUT, Styliser.CODE_FIXED
124
+                    + "---------------------- Command information -------");            
125
+            sendLine(origin, isSilent, FORMAT_OUTPUT, Styliser.CODE_FIXED
126
+                    + " Name: " + name);
127
+            sendLine(origin, isSilent, FORMAT_OUTPUT, Styliser.CODE_FIXED
128
+                    + " Type: " + command.getType());
129
+            sendLine(origin, isSilent, FORMAT_OUTPUT, Styliser.CODE_FIXED
130
+                    + "Usage: " + command.getHelp());
131
+            sendLine(origin, isSilent, FORMAT_OUTPUT, Styliser.CODE_FIXED
132
+                    + "--------------------------------------------------");            
100 133
         }
101 134
     }
102 135
     
@@ -112,7 +145,7 @@ public final class Help extends ServerCommand {
112 145
     
113 146
     /** {@inheritDoc}. */
114 147
     public String getHelp() {
115
-        return "help - shows all available client commands";
148
+        return "help [command] - shows client command help";
116 149
     }
117 150
     
118 151
 }

Loading…
İptal
Kaydet