UNPKG

@sap/cli-core

Version:

Command-Line Interface (CLI) Core Module

29 lines (28 loc) 1.01 kB
import { kebabCase } from "lodash-es"; import { get as getConfig } from "../../config/index.js"; import { OPTION_FORCE } from "../../constants.js"; import { create as createOptionsHandler } from "./options/index.js"; const PARAM_REGEX = /{.*}/; const replacer = (toBeReplaced) => { const param = toBeReplaced.slice(1, -1); return `{${kebabCase(param)}}`; }; export const create = (message) => createOptionsHandler([ { ...OPTION_FORCE, required: true, prompts: { type: "confirm", initial: false, message: () => { const config = getConfig(); let intMessage = message.replace(PARAM_REGEX, replacer); Object.entries(config.options).forEach((option) => { intMessage = intMessage.replace(`{${option[0]}}`, option[1]); }); return intMessage; }, inputValidator: (value) => value, }, }, ], undefined, false, true);