// joi/7/juno/ListCommand.java                         
//                                                            
//                                                            
// Copyright 2003, Bill Campbell and Ethan Bolker                         
// Exception handling deleted for Juno 6.5, Spring 2004, Ethan Bolker                                                            
import java.util.*;

/**
 * The Juno shell command to list contents of the current directory.
 * Usage:
 * <pre>
 *     list
 * </pre>
 *
 * @version 7
 */

public class ListCommand extends ShellCommand 
{
    // The constructor adds this object to the global table.

    ListCommand() 
    {
        super( "list contents of current directory" );
    }

    /**
     * List contents of the current working directory.
     *
     * @param args the remainder of the command line.
     * @param sh   the current shell
     */

    public void doIt( StringTokenizer args, Shell sh )
    {
        Terminal terminal = sh.getConsole();
        Directory dir     = sh.getDot();
        String[] fileNames = dir.getFileNames();

        for ( int i = 0; i < fileNames.length; i++ ) {
            String fileName = fileNames[i];
            JFile  jfile    = dir.retrieveJFile( fileName );
            terminal.println( jfile.toString() ); 
        }
    }
}

