2015-11-05 20:43:34 +00:00
|
|
|
/// <reference path="./index.ts" />
|
2015-11-08 23:58:40 +00:00
|
|
|
module SmartcliGetters {
|
2015-11-05 20:43:34 +00:00
|
|
|
export function init() {
|
2015-11-08 23:58:40 +00:00
|
|
|
smartcli.get = {};
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param commandString
|
|
|
|
* @returns {{specified: boolean, name: any, arguments: CliCommandArgument}}
|
|
|
|
*/
|
|
|
|
smartcli.get.command = function():CliCommand {
|
2015-11-05 20:43:34 +00:00
|
|
|
var cliCommand = {
|
2015-11-08 23:58:40 +00:00
|
|
|
specified: smartcli.check.commandPresence(),
|
|
|
|
name: plugins.argv._[1],
|
|
|
|
arguments: smartcli.get.commandArguments(1)
|
2015-11-05 20:43:34 +00:00
|
|
|
}
|
|
|
|
return cliCommand;
|
|
|
|
};
|
|
|
|
|
2015-11-08 23:58:40 +00:00
|
|
|
/**
|
|
|
|
* gets the second or higher value of plugins.argv._ if specified and returns it as commandArgument
|
|
|
|
* @param argumentLevel
|
|
|
|
* @returns {{specified: (boolean|boolean), name}}
|
|
|
|
*/
|
|
|
|
smartcli.get.commandArgument = function(argumentLevel):CliCommandArgument {
|
|
|
|
var commandArgument:CliCommandArgument = {
|
|
|
|
specified: false,
|
|
|
|
name: "undefined",
|
|
|
|
level:argumentLevel
|
2015-11-05 20:43:34 +00:00
|
|
|
};
|
2015-11-08 23:58:40 +00:00
|
|
|
if(argumentLevel < 1) {
|
|
|
|
plugins.beautylog.error("smartcli.get.argument cannot be invoked with an argumentLevel smaller than 1");
|
|
|
|
return commandArgument;
|
|
|
|
}
|
|
|
|
if(smartcli.check.commandArgumentPresence(argumentLevel)) {
|
|
|
|
commandArgument.specified = true;
|
|
|
|
commandArgument.name = plugins.argv._[argumentLevel];
|
|
|
|
}
|
2015-11-05 20:43:34 +00:00
|
|
|
return commandArgument;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2015-11-08 23:58:40 +00:00
|
|
|
*
|
|
|
|
* @returns {CliCommandArgument[]}
|
|
|
|
*/
|
|
|
|
smartcli.get.commandArgs = function():CliCommandArgument[] {
|
|
|
|
var commandArgs:CliCommandArgument[] = [];
|
|
|
|
for (var command in plugins.argv._)
|
|
|
|
return commandArgs;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* returns complete command array
|
2015-11-05 20:43:34 +00:00
|
|
|
* @returns {any}
|
|
|
|
*/
|
2015-11-08 23:58:40 +00:00
|
|
|
smartcli.get.commandArray = function ():string[] {
|
2015-11-05 20:43:34 +00:00
|
|
|
return plugins.argv._;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-11-08 23:58:40 +00:00
|
|
|
/**
|
|
|
|
* returns a cli option
|
|
|
|
* @param optionName
|
|
|
|
* @returns {CliOption}
|
|
|
|
*/
|
|
|
|
smartcli.get.option = function(optionName:string):CliOption {
|
|
|
|
var cliOption:CliOption = {
|
2015-11-05 20:43:34 +00:00
|
|
|
name:optionName,
|
|
|
|
specified: false,
|
|
|
|
value: false
|
2015-11-08 23:58:40 +00:00
|
|
|
};
|
|
|
|
if (plugins.argv.hasOwnProperty(optionName)) {
|
|
|
|
cliOption.name = optionName;
|
|
|
|
cliOption.specified = true;
|
|
|
|
cliOption.value = plugins.argv[optionName] //we already know from the "if" above that the value is available.
|
2015-11-05 20:43:34 +00:00
|
|
|
}
|
2015-11-08 23:58:40 +00:00
|
|
|
return cliOption;
|
2015-11-05 20:43:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-11-08 23:58:40 +00:00
|
|
|
smartcli.get.options = function() {
|
2015-11-05 20:43:34 +00:00
|
|
|
var options = {};
|
|
|
|
for (var key in plugins.argv) {
|
|
|
|
if (key != "_") {
|
|
|
|
options['key'] = plugins.argv['key'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return options;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* returns Directory of cwd
|
|
|
|
* @returns {{path: string}}
|
|
|
|
*/
|
2015-11-08 23:58:40 +00:00
|
|
|
smartcli.get.cwd = function():Directory {
|
2015-11-05 20:43:34 +00:00
|
|
|
return {
|
|
|
|
path: process.cwd()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|