2016-03-18 17:08:26 +00:00
|
|
|
/// <reference path="typings/main.d.ts" />
|
|
|
|
/// <reference path="./smartcli.interfaces.ts" />
|
|
|
|
"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) {
|
|
|
|
var commandArgument = {
|
|
|
|
specified: true,
|
|
|
|
name: argsArray[item],
|
|
|
|
level: item + 1
|
|
|
|
};
|
|
|
|
commandArgs.push(commandArgument);
|
|
|
|
}
|
|
|
|
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-11 00:11:40 +00:00
|
|
|
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0Y2xpLmdldHRlcnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsMENBQTBDO0FBQzFDLGlEQUFpRDs7QUFFakQsSUFBTyxPQUFPLFdBQVcsb0JBQW9CLENBQUMsQ0FBQ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