{"size": 1025, "ext": "js", "max_stars_repo_path": "lib/commands/help.js", "max_stars_repo_name": "shudingbo/egg-pomelo", "max_stars_repo_stars_event_min_datetime": "2020-05-06T09:06:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-26T09:55:43.000Z", "max_issues_repo_path": "lib/commands/help.js", "max_issues_repo_name": "shudingbo/egg-pomelo", "max_issues_repo_issues_event_min_datetime": "2021-03-02T01:02:12.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-08T23:12:35.000Z", "max_forks_repo_path": "lib/commands/help.js", "max_forks_repo_name": "shudingbo/egg-pomelo", "max_forks_repo_forks_event_min_datetime": "2021-05-26T09:55:50.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-26T09:55:50.000Z"}
{"max_stars_count": 2, "max_issues_count": 3, "max_forks_count": 1, "avg_line_length": 19.7115384615, "max_line_length": 50, "alphanum_fraction": 0.5824390244}

'use strict';

const util = require('../util');
const consts = require('../consts');

const CommandBase = require('../commandBase');

class CommandHelp extends CommandBase {
  constructor(cmdMgr) {
    super(cmdMgr);
    this.commandId = 'help';
  }

  handle(comd, argv, msg) {
    if (!comd) {
      this.sendErr(consts.COMANDS_UNKNOWN + argv);
      return;
    }

    const argvs = util.argsFilter(argv);

    if (argvs.length > 2) {
      this.sendErr(consts.COMANDS_UNKNOWN + argv);
      return;
    }

    if (comd === 'help') {
      const szInfo = util.help();
      this.sendOk({ message: szInfo });
      return;
    }

    if (consts.COMANDS_MAP[comd]) {
      const INFOS = consts.COMANDS_MAP[comd];
      let szOut = '';
      for (let i = 0; i < INFOS.length; i++) {
        szOut += util.formatStr(INFOS[i]);
      }
      this.sendOk({ message: szOut });
      return;
    }

    this.sendErr(consts.COMANDS_UNKNOWN + argv);
  }
}

module.exports = function(cmdMgr) {
  return new CommandHelp(cmdMgr);
};

