Introduce more advanced help system (#565).
authorcli
Tue, 27 Apr 2010 21:51:12 +0200
changeset 26407c428adb5b
parent 25 dd05c3f2fa24
child 27 d879bab39600
Introduce more advanced help system (#565).
helpers/helptext
org/sonews/daemon/CommandSelector.java
org/sonews/daemon/command/HelpCommand.java
org/sonews/daemon/command/HelpfulCommand.java
     1.1 --- a/helpers/helptext	Fri Dec 25 15:42:46 2009 +0100
     1.2 +++ b/helpers/helptext	Tue Apr 27 21:51:12 2010 +0200
     1.3 @@ -1,12 +1,6 @@
     1.4  Welcome to sonews help system
     1.5  
     1.6 -Here is a short overview of supported NNTP commands of this newsserver:
     1.7 +Here is a list of the supported NNTP commands of this newsserver.
     1.8 +Use HELP <command> to retrieve detailed help information of a
     1.9 +specific command.
    1.10  
    1.11 -ARTICLE <article-number|message-id>
    1.12 -  Retrieve article including its head
    1.13 -
    1.14 -GROUP <groupname>
    1.15 -  Change currently selected group
    1.16 -
    1.17 -POST
    1.18 -  Post an article to a newsgroup
    1.19 \ No newline at end of file
     2.1 --- a/org/sonews/daemon/CommandSelector.java	Fri Dec 25 15:42:46 2009 +0100
     2.2 +++ b/org/sonews/daemon/CommandSelector.java	Tue Apr 27 21:51:12 2010 +0200
     2.3 @@ -20,6 +20,7 @@
     2.4  
     2.5  import java.util.HashMap;
     2.6  import java.util.Map;
     2.7 +import java.util.Set;
     2.8  import java.util.concurrent.ConcurrentHashMap;
     2.9  import org.sonews.daemon.command.Command;
    2.10  import org.sonews.daemon.command.UnsupportedCommand;
    2.11 @@ -81,6 +82,11 @@
    2.12      }
    2.13    }
    2.14  
    2.15 +  public static Set<String> getCommandNames()
    2.16 +  {
    2.17 +    return commandClassesMapping.keySet();
    2.18 +  }
    2.19 +
    2.20    public static CommandSelector getInstance()
    2.21    {
    2.22      CommandSelector csel = instances.get(Thread.currentThread());
     3.1 --- a/org/sonews/daemon/command/HelpCommand.java	Fri Dec 25 15:42:46 2009 +0100
     3.2 +++ b/org/sonews/daemon/command/HelpCommand.java	Tue Apr 27 21:51:12 2010 +0200
     3.3 @@ -19,12 +19,14 @@
     3.4  package org.sonews.daemon.command;
     3.5  
     3.6  import java.io.IOException;
     3.7 +import java.util.Set;
     3.8 +import org.sonews.daemon.CommandSelector;
     3.9  import org.sonews.daemon.NNTPConnection;
    3.10  import org.sonews.util.io.Resource;
    3.11  
    3.12  /**
    3.13   * This command provides a short summary of the commands that are
    3.14 - * understood by this implementation of the server.  The help text will
    3.15 + * understood by this implementation of the server. The help text will
    3.16   * be presented as a multi-line data block following the 100 response
    3.17   * code (taken from RFC).
    3.18   * @author Christian Lins
    3.19 @@ -61,13 +63,35 @@
    3.20    public void processLine(NNTPConnection conn, final String line, byte[] raw)
    3.21      throws IOException
    3.22    {
    3.23 +    final String[] command = line.split(" ");
    3.24      conn.println("100 help text follows");
    3.25 -    
    3.26 -    final String[] help = Resource
    3.27 -      .getAsString("helpers/helptext", true).split("\n");
    3.28 -    for(String hstr : help)
    3.29 +
    3.30 +    if(line.length() <= 1)
    3.31      {
    3.32 -      conn.println(hstr);
    3.33 +      final String[] help = Resource
    3.34 +        .getAsString("helpers/helptext", true).split("\n");
    3.35 +      for(String hstr : help)
    3.36 +      {
    3.37 +        conn.println(hstr);
    3.38 +      }
    3.39 +
    3.40 +      Set<String> commandNames = CommandSelector.getCommandNames();
    3.41 +      for(String cmdName : commandNames)
    3.42 +      {
    3.43 +        conn.println(cmdName);
    3.44 +      }
    3.45 +    }
    3.46 +    else
    3.47 +    {
    3.48 +      Command cmd = CommandSelector.getInstance().get(command[1]);
    3.49 +      if(cmd instanceof HelpfulCommand)
    3.50 +      {
    3.51 +        conn.println(((HelpfulCommand)cmd).getHelpString());
    3.52 +      }
    3.53 +      else
    3.54 +      {
    3.55 +        conn.println("No further help information available.");
    3.56 +      }
    3.57      }
    3.58      
    3.59      conn.println(".");
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/org/sonews/daemon/command/HelpfulCommand.java	Tue Apr 27 21:51:12 2010 +0200
     4.3 @@ -0,0 +1,35 @@
     4.4 +/*
     4.5 + *   SONEWS News Server
     4.6 + *   see AUTHORS for the list of contributors
     4.7 + *
     4.8 + *   This program is free software: you can redistribute it and/or modify
     4.9 + *   it under the terms of the GNU General Public License as published by
    4.10 + *   the Free Software Foundation, either version 3 of the License, or
    4.11 + *   (at your option) any later version.
    4.12 + *
    4.13 + *   This program is distributed in the hope that it will be useful,
    4.14 + *   but WITHOUT ANY WARRANTY; without even the implied warranty of
    4.15 + *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    4.16 + *   GNU General Public License for more details.
    4.17 + *
    4.18 + *   You should have received a copy of the GNU General Public License
    4.19 + *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
    4.20 + */
    4.21 +
    4.22 +package org.sonews.daemon.command;
    4.23 +
    4.24 +/**
    4.25 + *
    4.26 + * @since sonews/1.1
    4.27 + * @author Christian Lins
    4.28 + */
    4.29 +public interface HelpfulCommand extends Command
    4.30 +{
    4.31 +
    4.32 +  /**
    4.33 +   * @return A short description of this command, that is
    4.34 +   * used within the output of the HELP command.
    4.35 +   */
    4.36 +  String getHelpString();
    4.37 +
    4.38 +}