UNPKG

@cloud-copilot/cli

Version:

A standardized library for CLI building TypeScript CLI applications

35 lines 1.47 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.enumArgument = enumArgument; function enumArgument(options) { return { description: options.description + `. One value required, valid values are: ${options.validValues.join(', ')}`, validateValues: (currentValue, values, isCurrentlyDefaulted) => { if (values.length == 0) { return { valid: false, message: 'a value is required' }; } if (currentValue != options.defaultValue) { return { valid: false, message: 'expects a single value but was set multiple times' }; } if (values.length > 1) { return { valid: false, message: 'expects a single value but received ' + values.join(', ') }; } const value = values[0]; const match = options.validValues.find((v) => v.toLowerCase() === value.toLowerCase()); if (!match) { return { valid: false, message: `${value} is not one of the allowed values: ${options.validValues.join(', ')}` }; } return { valid: true, value: match }; }, reduceValues: (current, newValue, isCurrentlyDefaulted) => newValue, defaultValue: options.defaultValue }; } //# sourceMappingURL=enumArgument.js.map