import config = require("./config"); import jamsglobal = require("./jamsglobal"); import clientparameter = require("./clientparameter"); import jamshelper = require("./jamshelper"); var helper = new jamshelper.Helper(); export class Commands { // #region Properties action: string; command: string; args; config; //noaction = [ "submit", "login", "logout" ]; // #endregion // #region Constructor constructor(args, configuration: any = {}) { this.args = args; this.config = configuration; this.getCommand(); } // #endregion // #region Methods getVerb() { var verb = this.args.length < 3 ? "" : this.args[2]; return verb === undefined ? "" : verb.toLowerCase(); } getNoun() { var noun = this.args.length < 4 ? "" : this.args[3]; return noun === undefined ? "" : noun.toLowerCase(); } isHelp(): Boolean { var command = this.getVerb(); var global = new jamsglobal.Global(this.config.locale, this.config); return (command === "" || command === global.getText("helptag") || command === global.getText("helpcmd")); } getCommand() { var noun = this.getNoun(); var verb = this.getVerb(); if (this.isHelp()) { this.command = verb; this.action = noun; } else { if (this.hasAction(verb)) { this.command = verb; this.action = ""; } else { this.command = noun; this.action = verb; } } } isCommand(commandname: string = "") { var cmd; commandname = helper.isNullOrEmpty(commandname) ? this.command.toLowerCase() : commandname; try { //cmd = require(`./Commands/${this.command.toLowerCase()}`); cmd = require(`./Commands/${commandname}`); } catch (ex) { cmd = undefined; } return cmd !== undefined; } hasCommand(): Boolean { return !helper.isNullOrEmpty(this.command); //return process.argv.length >= 3; } hasAction(cmdname: string) { var foundVerb = false; var global = new jamsglobal.Global(this.config.locale, this.config); var globalcmdname = global.getText(cmdname); if (!helper.isNullOrEmpty(globalcmdname) && globalcmdname != undefined) { var noaction = this.getNoActionList(); if (!helper.isNullOrEmpty(noaction)) { foundVerb = noaction.indexOf(globalcmdname.toLowerCase()) > -1; } } return foundVerb; } getHelpTopic() { var topic = ""; var global = new jamsglobal.Global(this.config.locale, this.config); if (this.isHelp()) { if (this.command === global.getText("helptag") || this.command === global.getText("helpcmd")) { topic = this.action; } } return topic; } getNoActionList(): any { var noactions: any; try { noactions = require("./Commands/commandsnoaction"); } catch (ex) { noactions = {}; } return noactions; } getConfig(): any { var conf = new config.Config(); return conf; } // #endregion }