103 lines
10 KiB
JavaScript
103 lines
10 KiB
JavaScript
/// <reference path="typings/index.d.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_1 = {
|
|
specified: true,
|
|
name: argsArray[item],
|
|
level: parseInt(item) + 1
|
|
};
|
|
commandArgs.push(commandArgument_1);
|
|
}
|
|
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;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0Y2xpLmdldHRlcnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsMkNBQTJDOztBQUczQyxJQUFPLE9BQU8sV0FBVyxvQkFBb0IsQ0FBQyxDQUFDO0FBQy9DLElBQU8sY0FBYyxXQUFXLG1CQUFtQixDQUFDLENBQUM7QUFFckQ7Ozs7R0FJRztBQUNRLGVBQU8sR0FBRztJQUNqQixJQUFJLFVBQVUsR0FBRztRQUNiLFNBQVMsRUFBRSxjQUFjLENBQUMsZUFBZSxFQUFFO1FBQzNDLElBQUksRUFBRSxPQUFPLENBQUMsSUFBSSxDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUM7UUFDdkIsU0FBUyxFQUFFLG1CQUFXLEVBQUU7S0FDM0IsQ0FBQTtJQUNELE1BQU0sQ0FBQyxVQUFVLENBQUM7QUFDdEIsQ0FBQyxDQUFDO0FBRUY7Ozs7R0FJRztBQUNRLHVCQUFlLEdBQUcsVUFBUyxhQUFhO0lBQy9DLElBQUksZUFBZSxHQUFpQztRQUNoRCxTQUFTLEVBQUUsS0FBSztRQUNoQix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