package commons.cmd;
import basics.utl.Empty;
import basics.utl.FormatterUtl;
import commons.application.GLOBAL;
import commons.application.Application;
import commons.application.core.Command;
public class dir extends Command
{

private static final String ARGS = "ARGS: [<service>]. ";

public void process () throws Exception
{
   String cmd = ctx.consume(GLOBAL.CTX_ENVKEY_ARG0, "");
   int maxlen = 0;
   for (String id : engine.getList())
   {
      if (Empty.is(cmd) || cmd.equalsIgnoreCase(id))
      {
         Command s = engine.lookup(id);
         int l = s.getId().length();
         maxlen = l > maxlen ? l : maxlen;
      }
   }
   maxlen += 2;
   for (String id : engine.getList())
   {
      if (Empty.is(cmd) || cmd.equalsIgnoreCase(id))
      {
         Command s = engine.lookup(id);
         String desc = s.description();
         Application.ui().print("_" + FormatterUtl.padr(s.getId(), "_", maxlen) + " " + desc);
      }
   }
}

public void signContract ()
{}

public String description ()
{
   return implName() + " lists either one or all of the commands (sevices) this engine can access. " + ARGS;
}
}
