package commons.cmd;
import basics.unexpected.Problem;
import basics.utl.Empty;
import commons.application.GLOBAL;
import commons.application.core.Command;
import commons.application.ctx.Context;
import commons.utl.CtxUtl;
public class ps extends Command
{

private static final String ARGS = "[sub-ctx-name] or empty to save main context. ";

public void process () throws Exception
{
   String args = ctx.consume(GLOBAL.CTX_ENVKEY_ARG0, "");
   boolean main = Empty.is(args);
   if (main) CtxUtl.saveProfile(CtxUtl.mainProfileFile(ctx), ctx.getRoot());
   else
   {
      Context subCtx = ctx.getChildCtxByName(args);
      if (subCtx == null) throw new Problem("No such context: " + args);
      String profilefile = CtxUtl.subProfileFile(ctx, args);
      CtxUtl.saveProfile(profilefile, subCtx);
   }
}

public void signContract ()
{}

public String description ()
{
   return implName() + " saves a profile in the workspace: " + ARGS;
}
}
