hubot-command-mapper
Version:
Helps with mapping tools and commands to Hubot.
25 lines (24 loc) • 776 B
JavaScript
/**
* Validates the tool and throws and exception if the
* tool is invalid.
* @param tool The tool.
*/
export default function validateToolAndThrowWhenInvalid(tool) {
if (!tool.name || tool.name === "")
throw "Invalid name for tool.";
if (!tool.commands || !tool.commands.length)
throw `No commands found for "${tool.name}"`;
tool.commands.forEach(cmd => validateCommandAndThrowWhenInvalid(tool, cmd));
}
/**
* Validates the command and throws an exception if
* the command is invalid.
* @param tool The tool.
* @param cmd The command.
*/
export function validateCommandAndThrowWhenInvalid(tool, cmd) {
if (!cmd)
throw "Cannot map empty command.";
if (!cmd.name || cmd.name === "")
throw "Invalid command name.";
}