// joi/7/juno/HelpCommand.java                         
//                                                            
//                                                            
// Copyright 2003, Bill Campbell and Ethan Bolker                         
                                                            
import java.util.*;

/**
 * The Juno shell command to display help on the shell commands.
 * Usage:
 * <pre>
 *     help
 * </pre>
 *
 * @version 7
 */

public class HelpCommand extends ShellCommand 
{
    HelpCommand() 
    {
	super( "display ShellCommands" );
    }

    /**
     * Print out help for all commands.
     *
     * @param args the remainder of the command line.
     * @param sh   the current shell
     *
     * @exception JunoException for reporting errors
     */

    public void doIt( StringTokenizer args, Shell sh )
	 throws JunoException 
    {
	// Get command keys from global table, print them out.
	
	sh.getConsole().println( "shell commands" );
	ShellCommandTable table = sh.getSystem().getCommandTable();
	String[] names = table.getCommandNames();
	for (int i = 0; i < names.length; i++ ) {
	    String cmdname = names[i];
	    ShellCommand cmd = 
		(ShellCommand) table.lookup( cmdname );
	    sh.getConsole().
		println( "  " + cmdname + ": " + cmd.getHelpString() );
	}
    }
}
