2015-11-05 20:43:34 +00:00
|
|
|
/// <reference path="./index.ts" />
|
2015-11-08 23:58:40 +00:00
|
|
|
module SmartcliChecks {
|
2015-11-05 20:43:34 +00:00
|
|
|
export function init() {
|
2015-11-08 23:58:40 +00:00
|
|
|
/**
|
|
|
|
* all functions in smartcli.check return a boolean
|
|
|
|
* @type {{}}
|
|
|
|
*/
|
|
|
|
smartcli.check = {};
|
|
|
|
|
2015-11-05 20:43:34 +00:00
|
|
|
/**
|
|
|
|
* checks for a special command string and returns true if found.
|
|
|
|
* @param commandString
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
2015-11-08 23:58:40 +00:00
|
|
|
smartcli.check.command = function(commandString:string):boolean {
|
2015-11-05 20:43:34 +00:00
|
|
|
if (plugins.argv._.indexOf(commandString) == 0) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
2015-11-08 23:58:40 +00:00
|
|
|
/**
|
|
|
|
* checks if a command is present, returns true if yes, false if no.
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
|
|
|
smartcli.check.commandPresence = function():boolean {
|
|
|
|
if(plugins.argv._.length > 0){
|
2015-11-05 20:43:34 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2015-11-08 23:58:40 +00:00
|
|
|
* checks for an special command argument at a certain position, returns true if matches, returns false if not
|
|
|
|
* @param level
|
2015-11-05 20:43:34 +00:00
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
2015-11-08 23:58:40 +00:00
|
|
|
smartcli.check.commandArgument = function(commandArgumentString:string,level:number = 1):boolean {
|
|
|
|
if(smartcli.check.commandArgumentPresence(level) && (plugins.argv._[level] == commandArgumentString )) {
|
2015-11-05 20:43:34 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2015-11-08 23:58:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
smartcli.check.commandArgumentPresence = function(level:number = 1) {
|
|
|
|
if(plugins.argv._.length >= (level + 1)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|
2015-11-05 20:43:34 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* checks for a specific option string, returns true if yes, returns false if no
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
2015-11-08 23:58:40 +00:00
|
|
|
smartcli.check.option = function(optionString):boolean {
|
2015-11-05 20:43:34 +00:00
|
|
|
if(plugins.smartparam.exists(plugins.argv, optionString)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
2015-11-08 23:58:40 +00:00
|
|
|
smartcli.check.optionPresence = function():boolean {
|
2015-11-05 20:43:34 +00:00
|
|
|
if (plugins.argv.indexOf() != -1) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|