63 lines
6.0 KiB
JavaScript
63 lines
6.0 KiB
JavaScript
/// <reference path="typings/main.d.ts" />
|
|
"use strict";
|
|
require("./smartcli.interfaces");
|
|
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;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0Y2xpLmNoZWNrcy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSwwQ0FBMEM7O0FBRTFDLFFBQU8sdUJBQXVCLENBQUMsQ0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