2016-05-23 02:09:06 +00:00
|
|
|
/// <reference path="typings/index.d.ts" />
|
2016-03-18 17:08:26 +00:00
|
|
|
"use strict";
|
|
|
|
var plugins = require("./smartcli.plugins");
|
|
|
|
var SmartcliChecks = require("./smartcli.checks");
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param commandString
|
|
|
|
* @returns {{specified: boolean, name: any, arguments: CliCommandArgument}}
|
|
|
|
*/
|
|
|
|
exports.command = function () {
|
|
|
|
var cliCommand = {
|
|
|
|
specified: SmartcliChecks.commandPresence(),
|
|
|
|
name: plugins.argv._[0],
|
|
|
|
arguments: exports.commandArgs()
|
|
|
|
};
|
|
|
|
return cliCommand;
|
|
|
|
};
|
|
|
|
/**
|
|
|
|
* 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-05-23 02:09:06 +00:00
|
|
|
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0Y2xpLmdldHRlcnMudHMiXSwibmFt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