63 lines
6.0 KiB
JavaScript
63 lines
6.0 KiB
JavaScript
/// <reference path="typings/index.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,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0Y2xpLmNoZWNrcy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSwyQ0FBMkM7O0FBRTNDLFFBQU8sdUJBQXVCLENBQUMsQ0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