appcenter-cli
Version:
Command line tool for Visual Studio App Center
31 lines (30 loc) • 1.22 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.loader = void 0;
const category_command_1 = require("./category-command");
const debug = require("debug")("appcenter-cli:util:commandline:command-loader");
function loader(commandFinder) {
return function commandLoader(command) {
const findResult = commandFinder(command);
if (!findResult.found) {
return null;
}
let commandFactory;
const commandParts = findResult.commandParts;
const args = findResult.unusedArgs;
const commandPath = findResult.commandPath;
if (!findResult.isCategory) {
// Turn off lint warning - string is sufficiently validated
// eslint-disable-next-line security/detect-non-literal-require
commandFactory = require(findResult.commandPath).default;
}
else {
commandFactory = category_command_1.CategoryCommand;
}
if (commandFactory === null) {
debug(`Loaded command from ${findResult.commandPath} but module has no default export`);
}
return { commandFactory, commandParts, args, commandPath };
};
}
exports.loader = loader;