UNPKG

@cloud-copilot/cli

Version:

A standardized library for CLI building TypeScript CLI applications

43 lines 1.78 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.enumArrayArgument = enumArrayArgument; function enumArrayArgument(options) { return { description: options.description + `. One or more values required, valid values are: ${options.validValues.join(', ')}`, validateValues: async (currentValue, values, isCurrentlyDefaulted) => { if (values.length == 0) { return { valid: false, message: 'At least one value is required' }; } const invalidValues = []; const validValues = []; for (const value of values) { const match = options.validValues.find((v) => v.toLowerCase() === value.toLowerCase()); if (!match) { invalidValues.push(value); } else { validValues.push(match); } } if (invalidValues.length > 0) { return { valid: false, message: `${invalidValues.map((v) => `${v}`).join(', ')} is not one of the allowed values: ${options.validValues.join(', ')}` }; } return { valid: true, value: validValues }; }, reduceValues: async (current, newValues, isCurrentlyDefaulted) => { if (isCurrentlyDefaulted || !current) { // If the current value is the default or undefined, replace it entirely return newValues; } current.push(...newValues); return current; }, defaultValue: options.defaultValue, acceptMultipleValues: () => true }; } //# sourceMappingURL=enumArrayArgument.js.map