Package com.zaranux.os.client.commands

Source Code of com.zaranux.os.client.commands.cd

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);
            }
          }
          );
     }
   

  }

}
TOP

Related Classes of com.zaranux.os.client.commands.cd

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.