2016-03-18 17:08:26 +00:00
|
|
|
"use strict";
|
2016-06-10 01:10:21 +00:00
|
|
|
require("typings-global");
|
2016-03-18 17:08:26 +00:00
|
|
|
var plugins = require("./smartcli.plugins");
|
|
|
|
var SmartcliChecks = require("./smartcli.checks");
|
|
|
|
/**
|
|
|
|
* gets the second or higher value of plugins.argv._ if specified and returns it as commandArgument
|
|
|
|
* @param argumentLevel
|
|
|
|
* @returns {{specified: (boolean|boolean), name}}
|
|
|
|
*/
|
|
|
|
exports.commandArgument = function (argumentLevel) {
|
|
|
|
var commandArgument = {
|
|
|
|
specified: false,
|
|
|
|
name: "undefined",
|
|
|
|
level: argumentLevel
|
|
|
|
};
|
|
|
|
if (argumentLevel < 1) {
|
|
|
|
plugins.beautylog.error("smartcli.get.argument cannot be invoked with an argumentLevel smaller than 1");
|
|
|
|
return commandArgument;
|
|
|
|
}
|
|
|
|
if (SmartcliChecks.commandArgumentPresence(argumentLevel)) {
|
|
|
|
commandArgument.specified = true;
|
|
|
|
commandArgument.name = plugins.argv._[argumentLevel];
|
|
|
|
}
|
|
|
|
return commandArgument;
|
|
|
|
};
|
|
|
|
/**
|
|
|
|
* returns array with commandArgs
|
|
|
|
* @returns {CliCommandArgument[]}
|
|
|
|
*/
|
|
|
|
exports.commandArgs = function () {
|
|
|
|
var commandArgs = [];
|
|
|
|
var argsArray = exports.commandArray().slice(0);
|
|
|
|
argsArray.shift();
|
|
|
|
for (var item in argsArray) {
|
2016-05-11 00:21:30 +00:00
|
|
|
var commandArgument_1 = {
|
2016-03-18 17:08:26 +00:00
|
|
|
specified: true,
|
|
|
|
name: argsArray[item],
|
2016-05-11 00:21:30 +00:00
|
|
|
level: parseInt(item) + 1
|
2016-03-18 17:08:26 +00:00
|
|
|
};
|
2016-05-11 00:21:30 +00:00
|
|
|
commandArgs.push(commandArgument_1);
|
2016-03-18 17:08:26 +00:00
|
|
|
}
|
|
|
|
return commandArgs;
|
|
|
|
};
|
|
|
|
/**
|
|
|
|
* returns complete command array
|
|
|
|
* @returns {any}
|
|
|
|
*/
|
|
|
|
exports.commandArray = function () {
|
|
|
|
var commandArray = plugins.argv._;
|
|
|
|
return commandArray;
|
|
|
|
};
|
|
|
|
/**
|
|
|
|
* returns a cli option
|
|
|
|
* @param optionName
|
|
|
|
* @returns {CliOption}
|
|
|
|
*/
|
|
|
|
exports.option = function (optionName) {
|
|
|
|
var cliOption = {
|
|
|
|
name: optionName,
|
|
|
|
specified: false,
|
|
|
|
value: false
|
|
|
|
};
|
|
|
|
if (plugins.smartparam.exists(plugins.argv, optionName)) {
|
|
|
|
cliOption.name = optionName;
|
|
|
|
cliOption.specified = true;
|
|
|
|
cliOption.value = plugins.argv[optionName]; //we already know from the "if" above that the value is available.
|
|
|
|
}
|
|
|
|
return cliOption;
|
|
|
|
};
|
|
|
|
exports.options = function () {
|
|
|
|
var options = {};
|
|
|
|
for (var key in plugins.argv) {
|
|
|
|
if (key != "_") {
|
|
|
|
options['key'] = plugins.argv['key'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return options;
|
|
|
|
};
|
|
|
|
/**
|
|
|
|
* returns Directory of cwd
|
|
|
|
* @returns {{path: string}}
|
|
|
|
*/
|
|
|
|
exports.cwd = function () {
|
|
|
|
return {
|
|
|
|
path: process.cwd()
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2016-06-10 01:10:21 +00:00
|
|
|
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0Y2xpLmdldHRlcnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sZ0JBQWdCLENBQUMsQ0FBQTtBQUd4QixJQUFPLE9BQU8sV0FBVyxvQkFBb0IsQ0FBQyxDQUFDO0FBQy9DLElBQU8sY0FBYyxXQUFXLG1CQUFtQixDQUFDLENBQUM7QUFHckQ7Ozs7R0FJRztBQUNRLHVCQUFlLEdBQUcsVUFBUyxhQUFhO0lBQy9D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