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 cd extends Command {
@Override
protected void execute(final AsyncCallback<Boolean> callback) {
final String[] args = getArgs();
if(args.length == 0) // cd -> go to home directory
{
getEnvironmentVariables().setValue("PWD", getHomeDirectory());
callback.onSuccess(true);
return;
}else // cd directory
{
final String absolutePath = getAbsolutePath(args[0]);
File f = new File(absolutePath);
Log.debug("File : " +f);
f.isDirectory(new AsyncCallback<Boolean>()
{
public void onSuccess(Boolean b)
{
if(b)
{
getEnvironmentVariables().setValue("PWD", absolutePath);
callback.onSuccess(true);
}else
{
System.out.print(args[0] + ": Not a directory",callback);
}
}
public void onFailure(Throwable t)
{
System.out.print("Failure: " + t ,callback);
}
}
);
}
}
}