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,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0Y2xpLmdldHRlcnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsMENBQTBDO0FBQzFDLGlEQUFpRDs7QUFFakQsSUFBTyxPQUFPLFdBQVcsb0JBQW9CLENBQUMsQ0FBQztBQUMvQyxJQUFPLGNBQWMsV0FBVyxtQkFBbUIsQ0FBQyxDQUFDO0FBRXJEOzs7O0dBSUc7QUFDUSxlQUFPLEdBQUc7SUFDakIsSUFBSSxVQUFVLEdBQUc7UUFDYixTQUFTLEVBQUUsY0FBYyxDQUFDLGVBQWUsRUFBRTtRQUMzQyxJQUFJLEVBQUUsT0FBTyxDQUFDLElBQUksQ0FBQyxDQ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