63 lines
5.8 KiB
JavaScript
63 lines
5.8 KiB
JavaScript
/// <reference path="typings/main.d.ts" />
|
|
/// <reference path="./smartcli.interfaces.ts" />
|
|
"use strict";
|
|
var plugins = require("./smartcli.plugins");
|
|
/**
|
|
* checks for a special command string and returns true if found.
|
|
* @param commandString
|
|
* @returns {boolean}
|
|
*/
|
|
exports.command = function (commandString) {
|
|
if (plugins.argv._.indexOf(commandString) == 0) {
|
|
return true;
|
|
}
|
|
return false;
|
|
};
|
|
/**
|
|
* checks if a command is present, returns true if yes, false if no.
|
|
* @returns {boolean}
|
|
*/
|
|
exports.commandPresence = function () {
|
|
if (plugins.argv._.length > 0) {
|
|
return true;
|
|
}
|
|
return false;
|
|
};
|
|
/**
|
|
* checks for an special command argument at a certain position, returns true if matches, returns false if not
|
|
* @param level
|
|
* @returns {boolean}
|
|
*/
|
|
exports.commandArgument = function (commandArgumentString, level) {
|
|
if (level === void 0) { level = 1; }
|
|
if (exports.commandArgumentPresence(level) && (plugins.argv._[level] == commandArgumentString)) {
|
|
return true;
|
|
}
|
|
return false;
|
|
};
|
|
exports.commandArgumentPresence = function (level) {
|
|
if (level === void 0) { level = 1; }
|
|
if (plugins.argv._.length >= (level + 1)) {
|
|
return true;
|
|
}
|
|
return false;
|
|
};
|
|
/**
|
|
* checks for a specific option string, returns true if yes, returns false if no
|
|
* @returns {boolean}
|
|
*/
|
|
exports.option = function (optionString) {
|
|
if (plugins.smartparam.exists(plugins.argv, optionString)) {
|
|
return true;
|
|
}
|
|
return false;
|
|
};
|
|
exports.optionPresence = function () {
|
|
if (plugins.argv.indexOf() != -1) {
|
|
return true;
|
|
}
|
|
return false;
|
|
};
|
|
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0Y2xpLmNoZWNrcy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSwwQ0FBMEM7QUFDMUMsaURBQWlEOztBQUVqRCxJQUFPLE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