/*
 * $Id: dir.java,v 1.2 2005/09/07 13:38:06 rampil Exp $
 * Copyright (c) 2004 LOGICAL-PARADOX.ORG
 */
package org.logical_paradox.vsan.tools.console.command;

import java.io.File;
import java.io.OutputStream;
import java.io.PrintStream;

import org.logical_paradox.shell.Argument;
import org.logical_paradox.shell.Command;
import org.logical_paradox.shell.ResultCode;
import org.logical_paradox.shell.ShellEnv;
import org.logical_paradox.shell.exception.CommandExecutionException;
import org.logical_paradox.shell.exception.TerminationException;

/**
 * <pre>
 * ■dir
 * 
 * 【動作仕様】
 * カレントディレクトリの内容を出力ストリームへリスト出力します。
 * 
 * 【書式】
 * dir
 * </pre>
 * 
 * @author satoshi akabane@logical-paradox.org
 * @version $Revision: 1.2 $
 */
public class dir implements Command {
	public static final String USAGE = "dir";

	public ResultCode execute(OutputStream ostream, ShellEnv env, Argument arg1) throws CommandExecutionException, TerminationException {
		PrintStream doc = new PrintStream(ostream);

		File file = new File(".");
		String[] filename = file.list();

		for(int i = 0; i < filename.length; i++) {
			doc.println(filename[i]);
		}

		return new ResultCode(ResultCode.STATUS_OK);
	}
	public String usage() {
		return USAGE;
	}

}
