@sap/cli-core
Version:
Command-Line Interface (CLI) Core Module
32 lines (31 loc) • 1.65 kB
JavaScript
;
/* eslint-disable no-await-in-loop */
Object.defineProperty(exports, "__esModule", { value: true });
exports.create = void 0;
const utils_1 = require("./utils");
const or_1 = require("../or");
const next_1 = require("../next");
const checkOptionsExistence_1 = require("../checkOptionsExistence");
const file_1 = require("./file");
const option_1 = require("./option");
const succeed_1 = require("../succeed");
const fail_1 = require("../fail");
const env_1 = require("./env");
const createHandler = (use, option, handler) => (0, next_1.create)("commands.handler.options", (0, checkOptionsExistence_1.create)(option), use ? handler : (0, succeed_1.create)());
const create = (options, { readEnv, readFile, readOptions } = {
readEnv: true,
readFile: true,
readOptions: true,
}, promptAlways = false, throwIfHandlersFailed = false) => async (command) => {
const intOptions = Array.isArray(options) ? options : [options];
await (0, utils_1.checkOptions)(intOptions, command);
return async () => {
for (const option of intOptions) {
const handler = (0, or_1.create)("commands.handler.options$outer", (0, checkOptionsExistence_1.create)(option, false), (0, or_1.create)("commands.handler.options$inner", createHandler(readEnv, option, (0, env_1.create)(option)), createHandler(readFile, option, (0, file_1.create)(option)), createHandler(readOptions, option, (0, option_1.create)(option, promptAlways))), throwIfHandlersFailed
? (0, fail_1.create)()
: (0, succeed_1.create)());
await (await handler(command))();
}
};
};
exports.create = create;