104 lines
9.7 KiB
JavaScript
104 lines
9.7 KiB
JavaScript
/// <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()
|
|
};
|
|
};
|
|
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0Y2xpLmdldHRlcnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsMENBQTBDO0FBQzFDLGlEQUFpRDs7QUFFakQsSUFBTyxPQUFPLFdBQVcsb0JBQW9CLENBQUMsQ0FBQztBQUMvQyxJQUFPLGNBQWMsV0FBVyxtQkFBbUIsQ0FBQyxDQUFDO0FBRXJEOzs7O0dBSUc7QUFDUSxlQUFPLEdBQUc7SUFDakIsSUFBSSxVQUFVLEdBQUc7UUFDYixTQUFTLEVBQUUsY0FBYyxDQUFDLGVBQWUsRUFBRTtRQUMzQyxJQUFJLEVBQUUsT0FBTyxDQUFDLElBQUksQ0FBQyxDQUFDLENBQUMsQ0FBQyxDQUFDO1FBQ3ZCLFNBQVMsRUFBRSxtQkFBVyxFQUFFO0tBQzNCLENBQUE7SUFDRCxNQUFNLENBQUMsVUFBVSxDQUFDO0FBQ3RCLENBQUMsQ0FBQztBQUVGOzs7O0dBSUc7QUFDUSx1QkFBZSxHQUFHLFVBQVMsYUFBYTtJQUMvQyxJQUFJLGVBQWUsR0F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