PageRenderTime 47ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/src_service/com/ptswitch/material/admcmd/cmds/HelpAdmCmd.java

https://gitlab.com/mstar-hxzon/mstar-mybatis-hxzon
Java | 43 lines | 36 code | 7 blank | 0 comment | 7 complexity | 309e13b034b179212ff7a5664550f66d MD5 | raw file
  1. package com.ptswitch.material.admcmd.cmds;
  2. import io.netty.channel.ChannelHandlerContext;
  3. import java.util.Map;
  4. import com.ptswitch.material.admcmd.AbstractAdmCmdImpl;
  5. import com.ptswitch.material.admcmd.AdmCmd;
  6. import com.ptswitch.material.util.Gs;
  7. public class HelpAdmCmd extends AbstractAdmCmdImpl implements AdmCmd {
  8. public HelpAdmCmd() {
  9. super("help");
  10. }
  11. @Override
  12. public void execute(String cmdLine, ChannelHandlerContext ctx) {
  13. String cmdName = cmdLine.trim();
  14. Map<String, AdmCmd> cmds = Gs.getAdmCmdHandler().getCmds();
  15. if (cmdName.isEmpty()) {
  16. StringBuilder sb = new StringBuilder();
  17. int i = 0;
  18. for (String cmd : cmds.keySet()) {
  19. sb.append(cmd).append(" ");
  20. i++;
  21. if (i % 4 == 0) {
  22. sb.append("\r\n");
  23. }
  24. }
  25. sb.append("\r\n");
  26. ctx.writeAndFlush(sb.toString());
  27. } else {
  28. AdmCmd admCmd = cmds.get(cmdName);
  29. if (admCmd == null) {
  30. ctx.writeAndFlush("can't find cmd\r\n");
  31. return;
  32. }
  33. ctx.writeAndFlush(admCmd.usage() + "\r\n");
  34. }
  35. }
  36. }