@sap/cli-core
Version:
Command-Line Interface (CLI) Core Module
20 lines (19 loc) • 782 B
JavaScript
import { get } from "../../../logger/index.js";
import { promptForValue, setOption } from "./utils.js";
function assertPromptsAreDefined(option) {
if (!option.prompts) {
throw new Error(`inconsistent option ${option.longName}, no prompts configuration available`);
}
}
export const create = (option, promptAlways = false) => async () => async () => {
const { debug } = get("commands.handler.options.option");
debug(`reading option ${option.longName} from options`);
if (option.required || promptAlways) {
assertPromptsAreDefined(option);
const value = await promptForValue(option);
setOption(option, value);
}
else {
throw new Error(`option ${option.longName} is not required and promptAlways is false`);
}
};