# HG changeset patch
# User cli
# Date 1272397872 -7200
# Node ID 407c428adb5b31638397d458d2548591c2262886
# Parent  dd05c3f2fa24cdaf391f4a46d367a27fe0376e49
Introduce more advanced help system (#565).

diff -r dd05c3f2fa24 -r 407c428adb5b helpers/helptext
--- a/helpers/helptext	Fri Dec 25 15:42:46 2009 +0100
+++ b/helpers/helptext	Tue Apr 27 21:51:12 2010 +0200
@@ -1,12 +1,6 @@
 Welcome to sonews help system
 
-Here is a short overview of supported NNTP commands of this newsserver:
+Here is a list of the supported NNTP commands of this newsserver.
+Use HELP <command> to retrieve detailed help information of a
+specific command.
 
-ARTICLE <article-number|message-id>
-  Retrieve article including its head
-
-GROUP <groupname>
-  Change currently selected group
-
-POST
-  Post an article to a newsgroup
\ No newline at end of file
diff -r dd05c3f2fa24 -r 407c428adb5b org/sonews/daemon/CommandSelector.java
--- a/org/sonews/daemon/CommandSelector.java	Fri Dec 25 15:42:46 2009 +0100
+++ b/org/sonews/daemon/CommandSelector.java	Tue Apr 27 21:51:12 2010 +0200
@@ -20,6 +20,7 @@
 
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 import org.sonews.daemon.command.Command;
 import org.sonews.daemon.command.UnsupportedCommand;
@@ -81,6 +82,11 @@
     }
   }
 
+  public static Set<String> getCommandNames()
+  {
+    return commandClassesMapping.keySet();
+  }
+
   public static CommandSelector getInstance()
   {
     CommandSelector csel = instances.get(Thread.currentThread());
diff -r dd05c3f2fa24 -r 407c428adb5b org/sonews/daemon/command/HelpCommand.java
--- a/org/sonews/daemon/command/HelpCommand.java	Fri Dec 25 15:42:46 2009 +0100
+++ b/org/sonews/daemon/command/HelpCommand.java	Tue Apr 27 21:51:12 2010 +0200
@@ -19,12 +19,14 @@
 package org.sonews.daemon.command;
 
 import java.io.IOException;
+import java.util.Set;
+import org.sonews.daemon.CommandSelector;
 import org.sonews.daemon.NNTPConnection;
 import org.sonews.util.io.Resource;
 
 /**
  * This command provides a short summary of the commands that are
- * understood by this implementation of the server.  The help text will
+ * understood by this implementation of the server. The help text will
  * be presented as a multi-line data block following the 100 response
  * code (taken from RFC).
  * @author Christian Lins
@@ -61,13 +63,35 @@
   public void processLine(NNTPConnection conn, final String line, byte[] raw)
     throws IOException
   {
+    final String[] command = line.split(" ");
     conn.println("100 help text follows");
-    
-    final String[] help = Resource
-      .getAsString("helpers/helptext", true).split("\n");
-    for(String hstr : help)
+
+    if(line.length() <= 1)
     {
-      conn.println(hstr);
+      final String[] help = Resource
+        .getAsString("helpers/helptext", true).split("\n");
+      for(String hstr : help)
+      {
+        conn.println(hstr);
+      }
+
+      Set<String> commandNames = CommandSelector.getCommandNames();
+      for(String cmdName : commandNames)
+      {
+        conn.println(cmdName);
+      }
+    }
+    else
+    {
+      Command cmd = CommandSelector.getInstance().get(command[1]);
+      if(cmd instanceof HelpfulCommand)
+      {
+        conn.println(((HelpfulCommand)cmd).getHelpString());
+      }
+      else
+      {
+        conn.println("No further help information available.");
+      }
     }
     
     conn.println(".");
diff -r dd05c3f2fa24 -r 407c428adb5b org/sonews/daemon/command/HelpfulCommand.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/org/sonews/daemon/command/HelpfulCommand.java	Tue Apr 27 21:51:12 2010 +0200
@@ -0,0 +1,35 @@
+/*
+ *   SONEWS News Server
+ *   see AUTHORS for the list of contributors
+ *
+ *   This program is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation, either version 3 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package org.sonews.daemon.command;
+
+/**
+ *
+ * @since sonews/1.1
+ * @author Christian Lins
+ */
+public interface HelpfulCommand extends Command
+{
+
+  /**
+   * @return A short description of this command, that is
+   * used within the output of the HELP command.
+   */
+  String getHelpString();
+
+}