package commons.cmd;
import basics.unexpected.Problem;
import basics.utl.Empty;
import commons.application.GLOBAL;
import commons.application.Application;
import commons.application.core.Command;
public class cc extends Command
{

private static final String ARGS = "ARGS: /|..|<subctx>. ";

public void process () throws Exception
{
   String shift = ctx.consume(GLOBAL.CTX_ENVKEY_ARG0, "");
   if (Empty.is(shift)) throw new Problem(description() + " Missing argument.");
   if (shift.equals("/"))
   {
      ctx = ctx.getRoot();
   }
   else if (shift.equals(".."))
   {
      if (ctx.getParent() != null) ctx = ctx.getParent();
   }
   else
   {
      if (!ctx.containsKey(shift) && !ctx.containsAlias(shift)) throw new Problem(description() + "No such sub-context: (" + shift + ").");
      else ctx = ctx.getChildCtxByName(shift);
   }
   
   Application.cc(ctx);
   // Manager.ui().put(ctx.toString());
}

public void signContract ()
{}

public String description ()
{
   return implName() + " changes into another context which must already be loaded (see " + pl.class.getSimpleName() + "). " + ARGS;
}
}
