@sap/cli-core
Version:
Command-Line Interface (CLI) Core Module
26 lines (25 loc) • 939 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getOptionValueFromConfigGracefully = exports.getOptionValueFromConfig = void 0;
const config_1 = require("../config");
const getOptionValueFromConfig = (option, defaultValue) => {
const config = (0, config_1.get)();
if (!config.options[option.longName] &&
typeof defaultValue !== "string" &&
!defaultValue) {
throw new Error(`no value found for option ${option.longName}`);
}
return config.options[option.longName]
? config.options[option.longName]
: defaultValue;
};
exports.getOptionValueFromConfig = getOptionValueFromConfig;
const getOptionValueFromConfigGracefully = (option) => {
try {
return (0, exports.getOptionValueFromConfig)(option);
}
catch (err) {
return undefined;
}
};
exports.getOptionValueFromConfigGracefully = getOptionValueFromConfigGracefully;