import java.util.Map;

/**
 * Help Response
 */
public class Helper implements Response
{
   private Map<String, Response> responses;
   private String helpIntro;

   public Helper(Map<String, Response> responses, String helpStr)
   {
      this.responses = responses;
      helpIntro = helpStr;
   }

   /**
     * Print out some help information.
     * Here we print some stupid, cryptic message and a list of the 
     * command words or more specific help given a command name.
     */
   public boolean execute(String[] tokens)
   {
       if (tokens.length == 1)
          System.out.println(helpIntro+ "\n" + help());
       else if (responses.containsKey(tokens[1]))
          System.out.println(responses.get(tokens[1]).help());
       else
          System.out.format("Unknown command %s!\n" +
                            "%s\n", tokens[1],
                            CommandMapper.allCommands());
       return false;
   }

   public String help()
   {
       return "Enter\n   help command\nfor help on the command.\n"+
              CommandMapper.allCommands();
   }

   public String getCommandName()
   {
      return "help";
   }
}
