package com.zaranux.os.client.commands;
import com.zaranux.client.api.AsyncCallback;
import com.zaranux.client.java.io.File;
import com.zaranux.os.client.util.Log;
public class ls extends Command {
private final String[] header ={"Type","Size", "Modefied", "Name"};
@Override
protected void execute(final AsyncCallback<Boolean> callback) {
String[] args = getArgs();
String dir = "/";
Log.debug("" + args.length);
if(args.length == 0)
dir = getCurrentDirectory(); // current directory
else
dir = getAbsolutePath(args[0]);
File d = new File(dir);
d.list(new AsyncCallback<String[]>()
{
public void onSuccess(final String[] l)
{
StringBuffer result = new StringBuffer();
if(l!=null)
{
setHeader(result);
for(String fd : l)
{
addRow(fd,result);
}
}
System.out.print(result.toString(),callback);
}
private void addRow(String fd, StringBuffer result) {
Log.debug("" + fd);
String[] list = fd.split(" \\| ");
Log.debug("" + list.length );
result.append(list[0]+"\t");//size
result.append(list[3]+"\t");//size
String[] date = list[2].split(" ");
result.append(date[1]+" "+date[2]+" "+date[5]+"\t"); //date: Month Day Year
result.append(list[1]+"\n");//name
}
private void setHeader(StringBuffer result) {
for (String h : header) {
result.append(h + "\t");
}
result.append("\n");
}
public void onFailure(Throwable t)
{
callback.onFailure(t);
}
}
);
}
}